160 lines
6.5 KiB
TypeScript
160 lines
6.5 KiB
TypeScript
import { participationIdentity } from '@/lib/participation-identity';
|
|
import { Form, Head, usePage } from '@inertiajs/react';
|
|
import InputError from '@/components/input-error';
|
|
import PasswordInput from '@/components/password-input';
|
|
import TextLink from '@/components/text-link';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Checkbox } from '@/components/ui/checkbox';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import { Spinner } from '@/components/ui/spinner';
|
|
/* @chisel-registration */
|
|
import { register } from '@/routes';
|
|
/* @end-chisel-registration */
|
|
import { store } from '@/routes/login';
|
|
import { request } from '@/routes/password';
|
|
/* @chisel-passkeys */
|
|
import PasskeyVerify from '@/components/passkey-verify';
|
|
/* @end-chisel-passkeys */
|
|
|
|
type Props = {
|
|
status?: string;
|
|
canResetPassword: boolean;
|
|
qaAccount?: { id: number; email: string };
|
|
};
|
|
|
|
export default function Login({ status, canResetPassword, qaAccount }: Props) {
|
|
// A redirect from another page (e.g. MFA) creates a new Form with empty local errors.
|
|
const pageErrors = usePage<{ errors: { email?: string } }>().props.errors;
|
|
return (
|
|
<>
|
|
<Head title="Entrar" />
|
|
|
|
{qaAccount && (
|
|
<aside
|
|
className="mb-4 rounded border border-amber-300 bg-amber-50 p-3 text-sm text-slate-900"
|
|
aria-label="Conta de ensaio QA"
|
|
>
|
|
<p className="font-semibold">
|
|
Ambiente QA — conta {qaAccount.id}
|
|
</p>
|
|
<p>
|
|
Para os cenários A/B: {qaAccount.email}. Use a
|
|
palavra-passe e o autenticador desta conta. Outros
|
|
perfis devem usar as respetivas contas sintéticas QA.
|
|
</p>
|
|
</aside>
|
|
)}
|
|
|
|
{/* @chisel-passkeys */}
|
|
<PasskeyVerify
|
|
label="Entrar com chave de acesso"
|
|
loadingLabel="A autenticar…"
|
|
separator="Ou continuar com email"
|
|
/>
|
|
{/* @end-chisel-passkeys */}
|
|
|
|
<Form
|
|
{...store.form()}
|
|
resetOnSuccess={['password']}
|
|
className="flex flex-col gap-6"
|
|
>
|
|
{({ processing, errors }) => (
|
|
<>
|
|
<div className="grid gap-6">
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="email">Email</Label>
|
|
<Input
|
|
id="email"
|
|
type="email"
|
|
name="email"
|
|
required
|
|
tabIndex={1}
|
|
autoComplete="email"
|
|
placeholder="email@example.com"
|
|
defaultValue={
|
|
qaAccount?.email ??
|
|
participationIdentity().email
|
|
}
|
|
/>
|
|
<InputError
|
|
message={errors.email ?? pageErrors.email}
|
|
/>
|
|
</div>
|
|
|
|
<div className="grid gap-2">
|
|
<div className="flex items-center">
|
|
<Label htmlFor="password">
|
|
Palavra-passe
|
|
</Label>
|
|
{canResetPassword && (
|
|
<TextLink
|
|
href={request()}
|
|
className="ml-auto text-sm"
|
|
tabIndex={5}
|
|
>
|
|
Esqueceu a palavra-passe?
|
|
</TextLink>
|
|
)}
|
|
</div>
|
|
<PasswordInput
|
|
id="password"
|
|
name="password"
|
|
required
|
|
tabIndex={2}
|
|
autoComplete="current-password"
|
|
placeholder="Palavra-passe"
|
|
/>
|
|
<InputError message={errors.password} />
|
|
</div>
|
|
|
|
<div className="flex items-center space-x-3">
|
|
<Checkbox
|
|
id="remember"
|
|
name="remember"
|
|
tabIndex={3}
|
|
/>
|
|
<Label htmlFor="remember">
|
|
Manter sessão iniciada
|
|
</Label>
|
|
</div>
|
|
|
|
<Button
|
|
type="submit"
|
|
className="mt-4 w-full"
|
|
tabIndex={4}
|
|
disabled={processing}
|
|
data-test="login-button"
|
|
>
|
|
{processing && <Spinner />}
|
|
Entrar
|
|
</Button>
|
|
</div>
|
|
|
|
{/* @chisel-registration */}
|
|
<div className="text-muted-foreground text-center text-sm">
|
|
Ainda não tem conta?{' '}
|
|
<TextLink href={register()} tabIndex={5}>
|
|
Criar conta
|
|
</TextLink>
|
|
</div>
|
|
{/* @end-chisel-registration */}
|
|
</>
|
|
)}
|
|
</Form>
|
|
|
|
{status && (
|
|
<div className="mb-4 text-center text-sm font-medium text-green-600">
|
|
{status}
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
Login.layout = {
|
|
title: 'Entrar na sua conta',
|
|
description:
|
|
'Entre para continuar a operação que escolheu. Os dados preenchidos permanecem guardados neste navegador.',
|
|
};
|