PR — Ouverture automatique / create-pr (push) Failing after 1s
Standalone files & media application: React/Vite frontend with the @cohaise/ui design system, Hono + MariaDB backend, nginx reverse proxy, Docker Compose stack, migrations 000-006, and project docs. Adds Gitea Actions workflows for deployment, automatic pull requests, and Renovate dependency updates.
109 lines
3.7 KiB
TypeScript
109 lines
3.7 KiB
TypeScript
import { useState, type FormEvent } from "react";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "@cohaise/ui";
|
|
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">
|
|
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
|
CoHaiSe
|
|
</p>
|
|
<h1 className="font-display mt-2 text-lg font-semibold uppercase tracking-label text-foreground">
|
|
Nouveau mot de passe
|
|
</h1>
|
|
<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>
|
|
);
|
|
};
|