Skip to content

Commit

Permalink
fix(ui): Render EmailOrPhoneNumberField when both phone and email a…
Browse files Browse the repository at this point in the history
…re optional (#3799)
  • Loading branch information
alexcarpenter authored Jul 24, 2024
1 parent d61d31d commit 872f615
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .changeset/swift-spoons-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
31 changes: 19 additions & 12 deletions packages/ui/src/components/sign-up/sign-up.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as SignUp from '@clerk/elements/sign-up';

import { Connections } from '~/common/connections';
import { EmailField } from '~/common/email-field';
import { EmailOrPhoneNumberField } from '~/common/email-or-phone-number-field';
import { FirstNameField } from '~/common/first-name-field';
import { LastNameField } from '~/common/last-name-field';
import { OTPField } from '~/common/otp-field';
Expand Down Expand Up @@ -43,7 +44,7 @@ function SignUpComponentLoaded() {
const { enabled: lastNameEnabled, required: lastNameRequired } = useAttributes('last_name');
const { enabled: usernameEnabled, required: usernameRequired } = useAttributes('username');
const { enabled: phoneNumberEnabled, required: phoneNumberRequired } = useAttributes('phone_number');
const { enabled: emailAddressEnabled } = useAttributes('email_address');
const { enabled: emailAddressEnabled, required: emailAddressRequired } = useAttributes('email_address');
const { enabled: passwordEnabled, required: passwordRequired } = useAttributes('password');
const { applicationName, branded, homeUrl, logoImageUrl } = useDisplayConfig();

Expand Down Expand Up @@ -113,18 +114,24 @@ function SignUpComponentLoaded() {
/>
) : null}

<EmailField disabled={isGlobalLoading} />
{emailAddressEnabled && !emailAddressRequired && phoneNumberEnabled && !phoneNumberRequired ? (
<EmailOrPhoneNumberField locationBasedCountryIso={locationBasedCountryIso} />
) : (
<>
<EmailField disabled={isGlobalLoading} />

{phoneNumberEnabled ? (
<PhoneNumberField
label={t('formFieldLabel__phoneNumber')}
hintText={t('formFieldHintText__optional')}
required={phoneNumberRequired}
disabled={isGlobalLoading}
initPhoneWithCode={clerk.client.signUp.phoneNumber || ''}
locationBasedCountryIso={locationBasedCountryIso}
/>
) : null}
{phoneNumberEnabled ? (
<PhoneNumberField
label={t('formFieldLabel__phoneNumber')}
hintText={t('formFieldHintText__optional')}
required={phoneNumberRequired}
disabled={isGlobalLoading}
initPhoneWithCode={clerk.client.signUp.phoneNumber || ''}
locationBasedCountryIso={locationBasedCountryIso}
/>
) : null}
</>
)}

{passwordEnabled && passwordRequired ? (
<PasswordField
Expand Down

0 comments on commit 872f615

Please sign in to comment.