-
Notifications
You must be signed in to change notification settings - Fork 474
refactor(ui): share one ProtectCheckCard between the sign-in and sign-up protect check cards #9966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
93 changes: 93 additions & 0 deletions
93
packages/ui/src/components/ProtectCheck/ProtectCheckCard.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { Card } from '@/ui/elements/Card'; | ||
| import { Header } from '@/ui/elements/Header'; | ||
|
|
||
| import { | ||
| Box, | ||
| Button, | ||
| Col, | ||
| descriptors, | ||
| Flex, | ||
| Flow, | ||
| localizationKeys, | ||
| Spinner, | ||
| useLocalizations, | ||
| } from '../../customizables'; | ||
| import { useSpinDelay } from '../../hooks'; | ||
| import type { ProtectCheckRunnerState } from '../../hooks/useProtectCheckRunner'; | ||
|
|
||
| const localizationKeysByFlow = { | ||
| signIn: { | ||
| title: localizationKeys('signIn.protectCheck.title'), | ||
| subtitle: localizationKeys('signIn.protectCheck.subtitle'), | ||
| loading: localizationKeys('signIn.protectCheck.loading'), | ||
| retryButton: localizationKeys('signIn.protectCheck.retryButton'), | ||
| }, | ||
| signUp: { | ||
| title: localizationKeys('signUp.protectCheck.title'), | ||
| subtitle: localizationKeys('signUp.protectCheck.subtitle'), | ||
| loading: localizationKeys('signUp.protectCheck.loading'), | ||
| retryButton: localizationKeys('signUp.protectCheck.retryButton'), | ||
| }, | ||
| }; | ||
|
|
||
| type ProtectCheckCardProps = { | ||
| flow: 'signIn' | 'signUp'; | ||
| runner: ProtectCheckRunnerState; | ||
| }; | ||
|
|
||
| export const ProtectCheckCard = ({ flow, runner }: ProtectCheckCardProps) => { | ||
| const { containerRef, isRunning, isWidgetVisible, error, retry } = runner; | ||
| const { t } = useLocalizations(); | ||
| const keys = localizationKeysByFlow[flow]; | ||
|
|
||
| // Debounce the spinner's entrance so a near-instant check (or a script that signals its | ||
| // widget immediately) never flashes it — the card header alone carries the first ~300ms. | ||
| // The error and widget-visibility gates stay OUTSIDE the delay hook below: its minimum | ||
| // visible duration must never outrank the handshake's "spinner is gone when the promise | ||
| // resolves" guarantee, nor keep a spinner next to the retry button. | ||
| const showSpinner = useSpinDelay(isRunning, { delay: 300 }); | ||
|
|
||
| return ( | ||
| <Flow.Part part='protectCheck'> | ||
| <Card.Root> | ||
| <Card.Content> | ||
| <Header.Root showLogo> | ||
| <Header.Title localizationKey={keys.title} /> | ||
| <Header.Subtitle localizationKey={keys.subtitle} /> | ||
| </Header.Root> | ||
| <Card.Alert>{error}</Card.Alert> | ||
| <Col | ||
| elementDescriptor={descriptors.main} | ||
| gap={6} | ||
| > | ||
| <Box | ||
| ref={containerRef} | ||
| id='clerk-protect-check' | ||
| aria-busy={isRunning} | ||
| // Out of flow while empty so the collapsed container adds no reserved height or flex-gap | ||
| // gutter above the spinner (same idiom as CaptchaElement's `gapless` mode). | ||
| style={{ display: 'block', alignSelf: 'center', position: isWidgetVisible ? 'static' : 'absolute' }} | ||
| /> | ||
| {showSpinner && !error && !isWidgetVisible ? ( | ||
| <Flex center> | ||
| <Spinner | ||
| size='lg' | ||
| colorScheme='primary' | ||
| elementDescriptor={descriptors.spinner} | ||
| aria-label={t(keys.loading)} | ||
| /> | ||
| </Flex> | ||
| ) : null} | ||
| {error ? ( | ||
| <Button | ||
| onClick={retry} | ||
| localizationKey={keys.retryButton} | ||
| /> | ||
| ) : null} | ||
| </Col> | ||
| </Card.Content> | ||
| <Card.Footer /> | ||
| </Card.Root> | ||
| </Flow.Part> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Declare the return type of
ProtectCheckCard.Add an explicit
JSX.Elementreturn type to this exported component. As per coding guidelines, “Always define explicit return types for functions, especially public APIs.”Proposed change
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines