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]>
118 lines
4.0 KiB
TypeScript
118 lines
4.0 KiB
TypeScript
import { useState, type FormEvent } from "react";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "../ui/index.js";
|
|
import { Alert } from "../components/feedback.js";
|
|
import { ApiError, api } from "../lib/api.js";
|
|
import { useSession } from "../lib/session.js";
|
|
|
|
export const ChangePassword = () => {
|
|
const { user, refresh, logout } = useSession();
|
|
const navigate = useNavigate();
|
|
const [current, setCurrent] = useState("");
|
|
const [next, setNext] = useState("");
|
|
const [confirm, setConfirm] = useState("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
event.preventDefault();
|
|
if (next !== confirm) {
|
|
setError("Les deux mots de passe ne correspondent pas.");
|
|
return;
|
|
}
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
await api.changePassword(current, next);
|
|
await refresh();
|
|
navigate("/files", { replace: true });
|
|
} catch (caught) {
|
|
setError(caught instanceof ApiError ? caught.message : "Changement 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">
|
|
Nouveau mot de passe
|
|
</h1>
|
|
</div>
|
|
</div>
|
|
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
|
|
Bienvenue {user?.first_name ?? ""}. Ce mot de passe a été défini par un
|
|
administrateur : choisissez le vôtre.
|
|
</p>
|
|
</header>
|
|
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Changement requis</CardTitle>
|
|
<CardDescription>
|
|
Les autres sessions ouvertes sur ce compte seront fermées.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
|
<Input
|
|
label="Mot de passe actuel"
|
|
type="password"
|
|
autoComplete="current-password"
|
|
required
|
|
autoFocus
|
|
value={current}
|
|
onChange={(event) => setCurrent(event.target.value)}
|
|
/>
|
|
<Input
|
|
label="Nouveau mot de passe"
|
|
type="password"
|
|
autoComplete="new-password"
|
|
required
|
|
minLength={8}
|
|
hint="8 caractères minimum."
|
|
value={next}
|
|
onChange={(event) => setNext(event.target.value)}
|
|
/>
|
|
<Input
|
|
label="Confirmation"
|
|
type="password"
|
|
autoComplete="new-password"
|
|
required
|
|
minLength={8}
|
|
value={confirm}
|
|
onChange={(event) => setConfirm(event.target.value)}
|
|
/>
|
|
{error ? <Alert>{error}</Alert> : null}
|
|
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
|
Enregistrer
|
|
</Button>
|
|
<Button
|
|
type="button"
|
|
variant="ghost"
|
|
size="md"
|
|
fullWidth
|
|
onClick={() => void logout()}
|
|
>
|
|
Se déconnecter
|
|
</Button>
|
|
</form>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</main>
|
|
);
|
|
};
|