226 lines
11 KiB
TypeScript
226 lines
11 KiB
TypeScript
import { participationIdentity } from '@/lib/participation-identity';
|
|
import { useTempoUi } from '@/components/tempo-brand';
|
|
import { Form, Head, usePage } from '@inertiajs/react';
|
|
import { Check, LogIn } from 'lucide-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 };
|
|
};
|
|
|
|
const controlClass =
|
|
'h-auto rounded-xl border-slate-300 bg-white px-3.5 py-3 text-sm text-slate-900 shadow-sm placeholder:text-slate-400 hover:border-slate-400 focus-visible:border-[#ed1c24] focus-visible:ring-4 focus-visible:ring-[#ed1c24]/10';
|
|
const labelClass =
|
|
'mb-1.5 block text-xs leading-normal font-bold text-slate-800';
|
|
const inlineLabelClass =
|
|
'block text-xs leading-normal font-bold text-slate-800';
|
|
|
|
export default function Login({ status, canResetPassword, qaAccount }: Props) {
|
|
const { t } = useTempoUi();
|
|
// 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={t('Entrar')} />
|
|
|
|
<div className="w-full overflow-hidden rounded-3xl bg-slate-50 shadow-2xl ring-1 ring-black/5">
|
|
<div className="p-5 sm:p-8 lg:p-10">
|
|
<img
|
|
src="/images/logo/logo-vermelho.png"
|
|
alt="Tempo"
|
|
width="1787"
|
|
height="564"
|
|
className="mx-auto mb-4 h-14 w-auto"
|
|
/>
|
|
|
|
<div className="mx-auto mb-8 max-w-2xl text-center">
|
|
<span className="mb-3 inline-flex rounded-full bg-red-100 px-3 py-1 text-xs font-bold tracking-wide text-[#b51219] uppercase">
|
|
{t('Área reservada')}
|
|
</span>
|
|
<h2 className="text-2xl font-bold text-slate-950 sm:text-3xl">
|
|
{t('Entrar na sua conta')}
|
|
</h2>
|
|
<p className="mt-3 text-sm leading-6 text-slate-600">
|
|
{t('Aceda à sua conta Tempo.')}
|
|
</p>
|
|
</div>
|
|
|
|
{qaAccount && (
|
|
<aside
|
|
className="mb-5 rounded-xl border border-amber-300 bg-amber-50 p-4 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>
|
|
)}
|
|
|
|
{status && (
|
|
<div
|
|
role="status"
|
|
className="mb-5 flex gap-2 rounded-xl border border-emerald-200 bg-emerald-50 p-4 text-sm font-medium text-emerald-800"
|
|
>
|
|
<Check className="shrink-0" size={18} />
|
|
{status}
|
|
</div>
|
|
)}
|
|
|
|
{/* @chisel-passkeys */}
|
|
<PasskeyVerify
|
|
label={t('Entrar com chave de acesso')}
|
|
loadingLabel={t('A autenticar…')}
|
|
separator={t('Ou continuar com email')}
|
|
separatorClassName="bg-slate-50"
|
|
/>
|
|
{/* @end-chisel-passkeys */}
|
|
|
|
<Form
|
|
{...store.form()}
|
|
resetOnSuccess={['password']}
|
|
className="flex flex-col gap-5"
|
|
>
|
|
{({ processing, errors }) => (
|
|
<>
|
|
<div className="grid gap-5">
|
|
<div className="grid gap-1.5">
|
|
<Label
|
|
htmlFor="email"
|
|
className={labelClass}
|
|
>
|
|
Email
|
|
</Label>
|
|
<Input
|
|
id="email"
|
|
type="email"
|
|
name="email"
|
|
required
|
|
tabIndex={1}
|
|
autoComplete="email"
|
|
placeholder="email@example.com"
|
|
className={controlClass}
|
|
defaultValue={
|
|
qaAccount?.email ??
|
|
participationIdentity().email
|
|
}
|
|
/>
|
|
<InputError
|
|
message={
|
|
errors.email ?? pageErrors.email
|
|
}
|
|
/>
|
|
</div>
|
|
|
|
<div className="grid gap-1.5">
|
|
<div className="flex items-center">
|
|
<Label
|
|
htmlFor="password"
|
|
className={inlineLabelClass}
|
|
>
|
|
{t('Palavra-passe')}
|
|
</Label>
|
|
{canResetPassword && (
|
|
<TextLink
|
|
href={request()}
|
|
className="ml-auto text-xs font-bold text-[#ed1c24] no-underline hover:underline"
|
|
tabIndex={5}
|
|
>
|
|
{t(
|
|
'Esqueceu a palavra-passe?',
|
|
)}
|
|
</TextLink>
|
|
)}
|
|
</div>
|
|
<PasswordInput
|
|
id="password"
|
|
name="password"
|
|
required
|
|
tabIndex={2}
|
|
autoComplete="current-password"
|
|
placeholder={t('Palavra-passe')}
|
|
className={`${controlClass} pr-10`}
|
|
/>
|
|
<InputError message={errors.password} />
|
|
</div>
|
|
|
|
<div className="flex items-center space-x-3">
|
|
<Checkbox
|
|
id="remember"
|
|
name="remember"
|
|
tabIndex={3}
|
|
className="size-4 border-slate-300 data-[state=checked]:border-[#ed1c24] data-[state=checked]:bg-[#ed1c24] data-[state=checked]:text-white"
|
|
/>
|
|
<Label
|
|
htmlFor="remember"
|
|
className="text-sm font-medium text-slate-700"
|
|
>
|
|
{t('Manter sessão iniciada')}
|
|
</Label>
|
|
</div>
|
|
|
|
<Button
|
|
type="submit"
|
|
className="mt-1 flex w-full items-center justify-center gap-2 rounded-xl bg-[#ed1c24] px-6 py-4 font-bold text-white shadow-lg shadow-red-900/15 transition hover:-translate-y-0.5 hover:bg-[#c6161d] hover:shadow-xl disabled:translate-y-0 disabled:cursor-not-allowed disabled:opacity-60"
|
|
tabIndex={4}
|
|
disabled={processing}
|
|
data-test="login-button"
|
|
>
|
|
{processing ? (
|
|
<Spinner />
|
|
) : (
|
|
<LogIn size={18} />
|
|
)}
|
|
{t('Entrar')}
|
|
</Button>
|
|
</div>
|
|
</>
|
|
)}
|
|
</Form>
|
|
</div>
|
|
|
|
{/* @chisel-registration */}
|
|
<div className="border-t border-slate-200 bg-white p-5 text-center text-sm text-slate-600">
|
|
{t('Ainda não tem conta?')}{' '}
|
|
<TextLink
|
|
href={register()}
|
|
tabIndex={5}
|
|
className="font-bold text-[#ed1c24] no-underline hover:underline"
|
|
>
|
|
{t('Criar conta')}
|
|
</TextLink>
|
|
</div>
|
|
{/* @end-chisel-registration */}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
Login.layout = {
|
|
variant: 'tempo-card',
|
|
title: 'Entrar na sua conta',
|
|
description: 'Aceda à sua conta Tempo.',
|
|
};
|