mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import { Fingerprint, Smartphone } from 'lucide-react';
|
|
import { useTranslation } from '../i18n';
|
|
import { useNativeHandoff } from './nativeHandoff/useNativeHandoff';
|
|
|
|
const PRIMARY = 'w-full rounded-lg bg-accent py-3 font-semibold text-accent-text disabled:opacity-60';
|
|
const SECONDARY = 'py-1 text-caption text-content-muted';
|
|
|
|
export default function NativeHandoffPage() {
|
|
const { t } = useTranslation();
|
|
const { valid, passkeyStep, continueWithPasskey, otherSignIn, ready, userName, status, openApp, switchAccount } =
|
|
useNativeHandoff();
|
|
|
|
const failed = status === 'failed' && (
|
|
<p role="alert" className="text-body text-danger">
|
|
{t(passkeyStep ? 'login.passkey.failed' : 'native.login.failed')}
|
|
</p>
|
|
);
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-surface-secondary p-6">
|
|
<div className="flex w-full max-w-sm flex-col gap-4 rounded-xl border border-edge bg-surface-card p-7 text-center">
|
|
{passkeyStep ? (
|
|
<Fingerprint className="mx-auto text-content-muted" size={32} aria-hidden />
|
|
) : (
|
|
<Smartphone className="mx-auto text-content-muted" size={32} aria-hidden />
|
|
)}
|
|
{!valid ? (
|
|
<p className="text-body text-content">{t('native.login.failed')}</p>
|
|
) : passkeyStep ? (
|
|
<>
|
|
<h1 className="text-title font-semibold text-content">{t('login.passkey.signIn')}</h1>
|
|
{failed}
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
void continueWithPasskey();
|
|
}}
|
|
disabled={status === 'sending'}
|
|
className={PRIMARY}
|
|
>
|
|
{t('login.passkey.signIn')}
|
|
</button>
|
|
<button type="button" onClick={otherSignIn} className={SECONDARY}>
|
|
{t('native.handoff.switchAccount')}
|
|
</button>
|
|
</>
|
|
) : !ready ? (
|
|
<div
|
|
className="mx-auto h-8 w-8 animate-spin rounded-full border-4 border-edge border-t-accent"
|
|
aria-label={t('common.loading')}
|
|
/>
|
|
) : (
|
|
<>
|
|
<h1 className="text-title font-semibold text-content">{t('native.handoff.title')}</h1>
|
|
<p className="text-body text-content-muted">{t('native.handoff.hint', { name: userName })}</p>
|
|
{failed}
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
void openApp();
|
|
}}
|
|
disabled={status === 'sending'}
|
|
className={PRIMARY}
|
|
>
|
|
{t('native.handoff.open')}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
void switchAccount();
|
|
}}
|
|
className={SECONDARY}
|
|
>
|
|
{t('native.handoff.switchAccount')}
|
|
</button>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|