All files / src/features/auth/components DemoEntry.tsx

57.14% Statements 4/7
50% Branches 1/2
25% Functions 1/4
57.14% Lines 4/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                      7x 7x 7x   7x                                                                          
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import { toast } from 'sonner'
 
import { ServerWakingNotice } from '@/shared/components/ServerWakingNotice'
import { PlayIcon } from '@/shared/icons/play-icon'
import { SpinnerIcon } from '@/shared/icons/spinner-icon'
 
import { demoStartErrorKey, useStartDemoSession } from '../api/auth.hooks'
 
/**
 * The way in without an account, above the sign-in form.
 *
 * Most people who reach this screen from the CV have no account and will not
 * make one to look around, so the demo comes first and the form second, with
 * a divider saying so. The account behind it is disposable — a sample family,
 * deleted in 24 hours (API: POST /auth/demo).
 */
export function DemoEntry() {
  const { t } = useTranslation()
  const navigate = useNavigate()
  const demo = useStartDemoSession()
 
  return (
    <div className="mb-5">
      <button
        type="button"
        disabled={demo.isPending}
        aria-busy={demo.isPending}
        onClick={() =>
          demo.mutate(undefined, {
            onSuccess: () => navigate('/dashboard', { replace: true }),
            onError: (error) => toast.error(t(demoStartErrorKey(error))),
          })
        }
        className="flex min-h-[52px] w-full items-center justify-center gap-2.5 rounded-[10px] border-[1.5px] border-auth-button bg-emerald-50/70 text-[15px] font-semibold text-auth-action transition-colors hover:bg-emerald-100/70 focus-visible:ring-3 focus-visible:ring-emerald-600/40 focus-visible:outline-none dark:border-emerald-400/60 dark:bg-emerald-500/10 dark:hover:bg-emerald-500/15"
      >
        {demo.isPending ? (
          <>
            <SpinnerIcon className="size-4 animate-spin" />
            {t('demo.opening')}
          </>
        ) : (
          <>
            <PlayIcon className="size-4" />
            {t('demo.start')}
            <span className="text-[12.5px] font-medium text-ink-muted">{t('demo.noSignUp')}</span>
          </>
        )}
      </button>
      <ServerWakingNotice active={demo.isPending} />
      <p className="mt-2 text-center text-xs text-ink-muted">{t('demo.note')}</p>
      <div className="mt-5 flex items-center gap-3" aria-hidden>
        <span className="h-px flex-1 bg-border" />
        <span className="text-xs text-ink-faint">{t('demo.orSignIn')}</span>
        <span className="h-px flex-1 bg-border" />
      </div>
    </div>
  )
}