CD — Déploiement / deploy (push) Failing after 25s
- logo embarque dans les e-mails (CID) et gabarit repense en mode sombre - favicon multi-tailles + icone PNG, logo a gauche du titre (app et auth) - modale de confirmation animee a la place de window.confirm - bouton retour et fil d'ariane dans l'explorateur --------- Co-authored-by: xEsiah <[email protected]> Reviewed-on: #4 Reviewed-by: Esiah <[email protected]> Co-authored-by: Gitea Actions <-[email protected]>
101 lines
3.5 KiB
TypeScript
101 lines
3.5 KiB
TypeScript
import { useState, type FormEvent } from "react";
|
|
import { Link, Navigate, useNavigate } from "react-router-dom";
|
|
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
|
import { ApiError, api } from "../lib/api.js";
|
|
import { useSession } from "../lib/session.js";
|
|
|
|
export const Login = () => {
|
|
const { user, setUser } = useSession();
|
|
const navigate = useNavigate();
|
|
const [email, setEmail] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
if (user) return <Navigate to="/files" replace />;
|
|
|
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
event.preventDefault();
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
const { user: current } = await api.login(email, password);
|
|
setUser(current);
|
|
navigate(current.must_change_password ? "/change-password" : "/files", { replace: true });
|
|
} catch (caught) {
|
|
setError(caught instanceof ApiError ? caught.message : "Connexion impossible.");
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
|
<div className="w-full max-w-sm">
|
|
<header className="mb-6 text-center">
|
|
<div className="flex items-center justify-center gap-3">
|
|
<img
|
|
src="/icon.png"
|
|
alt=""
|
|
className="h-12 w-12 rounded-xl ring-1 ring-black/5"
|
|
/>
|
|
<div className="text-left">
|
|
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
|
CoHaiSe
|
|
</p>
|
|
<h1 className="font-display text-lg font-semibold uppercase tracking-label text-foreground">
|
|
Cloud
|
|
</h1>
|
|
</div>
|
|
</div>
|
|
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
|
Connectez-vous pour accéder à vos fichiers.
|
|
</p>
|
|
</header>
|
|
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Connexion</CardTitle>
|
|
<CardDescription>Votre session reste ouverte 14 jours.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
|
<Input
|
|
label="Adresse e-mail"
|
|
type="email"
|
|
autoComplete="username"
|
|
required
|
|
autoFocus
|
|
value={email}
|
|
onChange={(event) => setEmail(event.target.value)}
|
|
/>
|
|
<Input
|
|
label="Mot de passe"
|
|
type="password"
|
|
autoComplete="current-password"
|
|
required
|
|
value={password}
|
|
onChange={(event) => setPassword(event.target.value)}
|
|
{...(error ? { error } : {})}
|
|
/>
|
|
|
|
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
|
Se connecter
|
|
</Button>
|
|
</form>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<p className="mt-4 text-center text-xs text-muted-foreground">
|
|
<Link
|
|
to="/forgot-password"
|
|
className="underline-offset-2 hover:text-foreground hover:underline"
|
|
>
|
|
Mot de passe oublié ?
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</main>
|
|
);
|
|
};
|