Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 100 additions & 117 deletions packages/ui/src/components/sign-in/steps/choose-strategy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Connections } from '~/common/connections';
import { GlobalError } from '~/common/global-error';
import { useGetHelp } from '~/components/sign-in/hooks/use-get-help';
import { LOCALIZATION_NEEDED } from '~/constants/localizations';
import { useAppearance } from '~/contexts';
import { useCard } from '~/hooks/use-card';
import { useDevModeWarning } from '~/hooks/use-dev-mode-warning';
import { useEnabledConnections } from '~/hooks/use-enabled-connections';
Expand All @@ -14,29 +15,16 @@ import { Button } from '~/primitives/button';
import * as Card from '~/primitives/card';
import * as Icon from '~/primitives/icon';
import { LinkButton } from '~/primitives/link';
import { Separator } from '~/primitives/separator';

/* Internal
============================================ */

function FirstFactorConnections({
isGlobalLoading,
hasConnection,
}: {
isGlobalLoading: boolean;
hasConnection: boolean;
}) {
const { t } = useLocalizations();
function FirstFactorConnections({ isGlobalLoading }: { isGlobalLoading: boolean }) {
const { signIn } = useSignIn();
const isFirstFactor = signIn?.status === 'needs_first_factor';

if (isFirstFactor) {
return (
<>
<Connections disabled={isGlobalLoading} />
{hasConnection ? <Separator>{t('dividerText')}</Separator> : null}
</>
);
return <Connections disabled={isGlobalLoading} />;
}
return null;
}
Expand Down Expand Up @@ -69,118 +57,113 @@ export function SignInChooseStrategy() {
<GlobalError />

<Card.Body>
<div className='flex flex-col gap-6'>
<FirstFactorConnections
isGlobalLoading={isGlobalLoading}
hasConnection={hasConnection}
/>
<div className='flex flex-col gap-3'>
<div className='flex flex-col gap-2'>
<SignIn.SupportedStrategy
name='email_link'
asChild
>
<Button
intent='secondary'
iconStart={<Icon.LinkSm />}
>
<SignIn.SafeIdentifier
transform={(identifier: string) =>
t('signIn.alternativeMethods.blockButton__emailLink', {
identifier,
})
}
/>
</Button>
</SignIn.SupportedStrategy>

<SignIn.SupportedStrategy
name='email_code'
asChild
>
<Button
intent='secondary'
iconStart={<Icon.EnvelopeSm />}
>
<SignIn.SafeIdentifier
transform={(identifier: string) =>
t('signIn.alternativeMethods.blockButton__emailCode', {
identifier,
})
}
/>
</Button>
</SignIn.SupportedStrategy>

<SignIn.SupportedStrategy
name='phone_code'
asChild
<div className='flex flex-col gap-3'>
<div className='flex flex-col gap-2'>
<FirstFactorConnections isGlobalLoading={isGlobalLoading} />
<SignIn.SupportedStrategy
name='email_link'
asChild
>
<Button
intent='secondary'
iconStart={<Icon.LinkSm />}
>
<Button
intent='secondary'
iconStart={<Icon.SMSSm />}
>
<SignIn.SafeIdentifier
transform={(identifier: string) =>
t('signIn.alternativeMethods.blockButton__phoneCode', {
identifier,
})
}
/>
</Button>
</SignIn.SupportedStrategy>

<SignIn.SupportedStrategy
name='passkey'
asChild
<SignIn.SafeIdentifier
transform={(identifier: string) =>
t('signIn.alternativeMethods.blockButton__emailLink', {
identifier,
})
}
/>
</Button>
</SignIn.SupportedStrategy>

<SignIn.SupportedStrategy
name='email_code'
asChild
>
<Button
intent='secondary'
iconStart={<Icon.EnvelopeSm />}
>
<Button
intent='secondary'
iconStart={<Icon.FingerprintSm />}
>
{t('signIn.alternativeMethods.blockButton__passkey')}
</Button>
</SignIn.SupportedStrategy>

<SignIn.SupportedStrategy
name='password'
asChild
<SignIn.SafeIdentifier
transform={(identifier: string) =>
t('signIn.alternativeMethods.blockButton__emailCode', {
identifier,
})
}
/>
</Button>
</SignIn.SupportedStrategy>

<SignIn.SupportedStrategy
name='phone_code'
asChild
>
<Button
intent='secondary'
iconStart={<Icon.SMSSm />}
>
<Button
intent='secondary'
iconStart={<Icon.LockSm />}
>
{t('signIn.alternativeMethods.blockButton__password')}
</Button>
</SignIn.SupportedStrategy>

{
// `SupportedStrategy`s that are only intended for use
// within `choose-strategy`, not the `forgot-password`
// `Step
}
<SignIn.SupportedStrategy
name='totp'
asChild
<SignIn.SafeIdentifier
transform={(identifier: string) =>
t('signIn.alternativeMethods.blockButton__phoneCode', {
identifier,
})
}
/>
</Button>
</SignIn.SupportedStrategy>

<SignIn.SupportedStrategy
name='passkey'
asChild
>
<Button
intent='secondary'
iconStart={<Icon.FingerprintSm />}
>
<Button intent='secondary'>{t('signIn.alternativeMethods.blockButton__totp')}</Button>
</SignIn.SupportedStrategy>
{t('signIn.alternativeMethods.blockButton__passkey')}
</Button>
</SignIn.SupportedStrategy>

<SignIn.SupportedStrategy
name='backup_code'
asChild
<SignIn.SupportedStrategy
name='password'
asChild
>
<Button
intent='secondary'
iconStart={<Icon.LockSm />}
>
<Button intent='secondary'>{t('signIn.alternativeMethods.blockButton__backupCode')}</Button>
</SignIn.SupportedStrategy>
</div>
{t('signIn.alternativeMethods.blockButton__password')}
</Button>
</SignIn.SupportedStrategy>

{
// `SupportedStrategy`s that are only intended for use
// within `choose-strategy`, not the `forgot-password`
// `Step
}
<SignIn.SupportedStrategy
name='totp'
asChild
>
<Button intent='secondary'>{t('signIn.alternativeMethods.blockButton__totp')}</Button>
</SignIn.SupportedStrategy>

<SignIn.Action
navigate='previous'
<SignIn.SupportedStrategy
name='backup_code'
asChild
>
<LinkButton>{t('backButton')}</LinkButton>
</SignIn.Action>
<Button intent='secondary'>{t('signIn.alternativeMethods.blockButton__backupCode')}</Button>
</SignIn.SupportedStrategy>
</div>

<SignIn.Action
navigate='previous'
asChild
>
<LinkButton>{t('backButton')}</LinkButton>
</SignIn.Action>
</div>
</Card.Body>
</Card.Content>
Expand Down
11 changes: 8 additions & 3 deletions packages/ui/src/components/sign-in/steps/start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PhoneNumberField } from '~/common/phone-number-field';
import { PhoneNumberOrUsernameField } from '~/common/phone-number-or-username-field';
import { UsernameField } from '~/common/username-field';
import { LOCALIZATION_NEEDED } from '~/constants/localizations';
import { useAppearance } from '~/contexts';
import { useAttributes } from '~/hooks/use-attributes';
import { useCard } from '~/hooks/use-card';
import { useDevModeWarning } from '~/hooks/use-dev-mode-warning';
Expand All @@ -35,11 +36,16 @@ export function SignInStart() {
const hasConnection = enabledConnections.length > 0;
const hasIdentifier = emailAddressEnabled || usernameEnabled || phoneNumberEnabled;
const isDev = useDevModeWarning();
const { layout } = useAppearance().parsedAppearance;
const { logoProps, footerProps } = useCard();

return (
<Common.Loading scope='global'>
{isGlobalLoading => {
const connectionsWithSeperator = [
<Connections disabled={isGlobalLoading} />,
hasConnection && hasIdentifier ? <Separator>{t('dividerText')}</Separator> : null,
];
return (
<SignIn.Step name='start'>
<Card.Root banner={isDev ? LOCALIZATION_NEEDED.developmentMode : null}>
Expand All @@ -53,9 +59,7 @@ export function SignInStart() {
<GlobalError />

<Card.Body>
<Connections disabled={isGlobalLoading} />

{hasConnection && hasIdentifier ? <Separator>{t('dividerText')}</Separator> : null}
{layout.socialButtonsPlacement === 'top' ? connectionsWithSeperator : null}

{hasIdentifier ? (
<div className='flex flex-col gap-4'>
Expand Down Expand Up @@ -122,6 +126,7 @@ export function SignInStart() {
) : null}
</div>
) : null}
{layout.socialButtonsPlacement === 'bottom' ? connectionsWithSeperator.reverse() : null}
</Card.Body>
<Card.Actions>
<Common.Loading scope='submit'>
Expand Down
12 changes: 9 additions & 3 deletions packages/ui/src/components/sign-up/steps/start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PasswordField } from '~/common/password-field';
import { PhoneNumberField } from '~/common/phone-number-field';
import { UsernameField } from '~/common/username-field';
import { LOCALIZATION_NEEDED } from '~/constants/localizations';
import { useAppearance } from '~/contexts';
import { useAttributes } from '~/hooks/use-attributes';
import { useCard } from '~/hooks/use-card';
import { useDevModeWarning } from '~/hooks/use-dev-mode-warning';
Expand Down Expand Up @@ -40,11 +41,16 @@ export function SignUpStart() {
const hasConnection = enabledConnections.length > 0;
const hasIdentifier = emailAddressEnabled || usernameEnabled || phoneNumberEnabled;
const isDev = useDevModeWarning();
const { layout } = useAppearance().parsedAppearance;
const { logoProps, footerProps } = useCard();

return (
<Common.Loading scope='global'>
{isGlobalLoading => {
const connectionsWithSeperator = [
<Connections disabled={isGlobalLoading} />,
hasConnection && hasIdentifier ? <Separator>{t('dividerText')}</Separator> : null,
];
return (
<SignUp.Step name='start'>
<Card.Root banner={isDev ? LOCALIZATION_NEEDED.developmentMode : null}>
Expand All @@ -62,9 +68,7 @@ export function SignUpStart() {
<GlobalError />

<Card.Body>
<Connections disabled={isGlobalLoading} />

{hasConnection && hasIdentifier ? <Separator>{t('dividerText')}</Separator> : null}
{layout.socialButtonsPlacement === 'top' ? connectionsWithSeperator : null}

{hasIdentifier ? (
<div className='flex flex-col gap-4'>
Expand Down Expand Up @@ -118,6 +122,8 @@ export function SignUpStart() {
</div>
) : null}

{layout.socialButtonsPlacement === 'bottom' ? connectionsWithSeperator.reverse() : null}

{userSettings.signUp.captcha_enabled ? <SignUp.Captcha className='empty:hidden' /> : null}
</Card.Body>
{hasConnection || hasIdentifier ? (
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/theme-builder/app/components/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SVGAttributes } from 'react';
import type { SVGAttributes } from 'react';

export const Logo = (props: SVGAttributes<SVGElement>) => (
<svg
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/theme-builder/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { SignedIn, SignedOut, SignInButton, SignUpButton, UserButton } from '@cl

function Button({ children }: { children: React.ReactNode }) {
return (
<button className='relative isolate rounded border bg-white bg-gradient-to-b from-white to-neutral-50 px-2.5 py-1 text-sm font-medium'>
<button
className='relative isolate rounded border bg-white bg-gradient-to-b from-white to-neutral-50 px-2.5 py-1 text-sm font-medium'
type='button'
>
{children}
</button>
);
Expand Down
Loading