Skip to content

Commit

Permalink
fix(ui): If SafeIdentifier is a phone number format it
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcarpenter committed Jul 17, 2024
1 parent e884aad commit db9d2d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/ui/src/components/sign-in/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EmailOrUsernameOrPhoneNumberField } from '~/common/email-or-username-or
import { OTPField } from '~/common/otp-field';
import { PasswordField } from '~/common/password-field';
import { PhoneNumberField } from '~/common/phone-number-field';
import { parsePhoneString } from '~/common/phone-number-field/utils';
import { PhoneNumberOrUsernameField } from '~/common/phone-number-or-username-field';
import { UsernameField } from '~/common/username-field';
import { useAttributes } from '~/hooks/use-attributes';
Expand All @@ -24,6 +25,7 @@ import * as Icon from '~/primitives/icon';
import { LinkButton } from '~/primitives/link-button';
import { SecondaryButton } from '~/primitives/secondary-button';
import { Seperator } from '~/primitives/seperator';
import { isPhoneNumber } from '~/utils/is-phone-number';

export function SignInComponent() {
return (
Expand Down Expand Up @@ -204,7 +206,14 @@ export function SignInComponentLoaded() {
<Card.Description>{t('signIn.password.subtitle')}</Card.Description>
<Card.Description>
<span className='flex items-center justify-center gap-2'>
<SignIn.SafeIdentifier />
<SignIn.SafeIdentifier
transform={val => {
if (!isPhoneNumber(val)) {
return parsePhoneString(val).formattedNumberWithCode;
}
return val;
}}
/>
<SignIn.Action
navigate='start'
asChild
Expand Down
5 changes: 5 additions & 0 deletions packages/ui/src/utils/is-phone-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const phoneRegex = /^(\+\d{1,3}[-\s]?)?\(?[0-9]{3}\)?[-\s]?[0-9]{3}[-\s]?[0-9]{4}$/;

export function isPhoneNumber(str: string) {
return phoneRegex.test(str);
}

0 comments on commit db9d2d6

Please sign in to comment.