PR — Ouverture automatique / create-pr (push) Successful in 3s
Migrate remaining Tailwind utilities to v4 names and apply formatting; center auth form elements and unify the CoHaiSe Cloud branding header; use the activity icon for audio file placeholders.
118 lines
4.1 KiB
TypeScript
118 lines
4.1 KiB
TypeScript
import { useState, type FormEvent } from "react";
|
|
import { Link, useSearchParams } 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 { useI18n } from "../lib/i18n.js";
|
|
|
|
export const ResetPassword = () => {
|
|
const { t } = useI18n();
|
|
const [params] = useSearchParams();
|
|
const token = params.get("token") ?? "";
|
|
const [password, setPassword] = useState("");
|
|
const [confirm, setConfirm] = useState("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [done, setDone] = useState(false);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
event.preventDefault();
|
|
if (password !== confirm) {
|
|
setError(t("Les deux mots de passe ne correspondent pas."));
|
|
return;
|
|
}
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
await api.resetPassword(token, password);
|
|
setDone(true);
|
|
} catch (caught) {
|
|
setError(caught instanceof ApiError ? caught.message : t("Réinitialisation impossible."));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<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>
|
|
</header>
|
|
|
|
<Card>
|
|
<CardHeader className="text-center">
|
|
<CardTitle>{t("Réinitialisation")}</CardTitle>
|
|
<CardDescription>{t("Choisissez un mot de passe robuste.")}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{!token ? (
|
|
<div className="flex flex-col gap-4">
|
|
<Alert className="text-center">{t("Ce lien est incomplet ou invalide.")}</Alert>
|
|
<Link
|
|
to="/forgot-password"
|
|
className="text-center text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
|
|
>
|
|
{t("Demander un nouveau lien")}
|
|
</Link>
|
|
</div>
|
|
) : done ? (
|
|
<div className="flex flex-col gap-4">
|
|
<Alert tone="success" className="text-center">
|
|
{t("Votre mot de passe a été réinitialisé. Vous pouvez vous connecter.")}
|
|
</Alert>
|
|
<Link to="/login">
|
|
<Button size="lg" fullWidth>
|
|
{t("Se connecter")}
|
|
</Button>
|
|
</Link>
|
|
</div>
|
|
) : (
|
|
<form className="flex flex-col gap-4" onSubmit={(event) => void submit(event)}>
|
|
<Input
|
|
centered
|
|
label={t("Nouveau mot de passe")}
|
|
type="password"
|
|
autoComplete="new-password"
|
|
required
|
|
minLength={8}
|
|
autoFocus
|
|
hint={t("8 caractères minimum.")}
|
|
value={password}
|
|
onChange={(event) => setPassword(event.target.value)}
|
|
/>
|
|
<Input
|
|
centered
|
|
label={t("Confirmation")}
|
|
type="password"
|
|
autoComplete="new-password"
|
|
required
|
|
minLength={8}
|
|
value={confirm}
|
|
onChange={(event) => setConfirm(event.target.value)}
|
|
/>
|
|
{error ? <Alert className="text-center">{error}</Alert> : null}
|
|
<Button type="submit" size="lg" fullWidth isLoading={busy}>
|
|
{t("Réinitialiser")}
|
|
</Button>
|
|
</form>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
};
|