Files
CoHaiSe/frontend/crm/src/pages/ChangePassword.tsx
T
Esiah 09cf07d79b feat: migrate showcase to Next.js and overhaul CRM UI
- rebuild the public site on the Next.js App Router with static export,
  per-section SEO pages, metadata, sitemap, robots and a generated OG image
- add full-screen scroll-snap regions, staged scroll reveals, a hash-free
  tab navigation with a sliding indicator and region-by-region menu scrolling
- replace the theme text toggle with animated sun/moon icons
- restructure the CRM API into config, middleware, models, routes, services
  and utils layers
- redesign the CRM shell with a single surface, tab rail, full-width blurred
  DataTable, record dialogs and mask-based icons
- update Docker/Nginx publishing, Makefile targets, shared UI polish and docs
2026-11-16 00:52:29 +01:00

113 lines
3.7 KiB
TypeScript

import { useState, type FormEvent } from "react";
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "@cohaise/ui";
import { ApiError, api, type User } from "../lib/api.js";
import { FaultyTerminalBackdrop } from "../components/FaultyTerminalBackdrop.js";
interface Props {
user: User;
onCompleted: () => void;
onLogout: () => void;
}
export const ChangePassword = ({ user, onCompleted, onLogout }: Props) => {
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;
}
if (next.length < 8) {
setError("Le nouveau mot de passe doit contenir au moins 8 caractères.");
return;
}
setBusy(true);
setError(null);
try {
await api.changePassword(current, next);
onCompleted();
} catch (caught) {
setError(caught instanceof ApiError ? caught.message : "Modification impossible.");
} finally {
setBusy(false);
}
};
return (
<main className="relative flex min-h-dvh items-center justify-center bg-background px-4 py-10">
<FaultyTerminalBackdrop />
<div className="relative z-10 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 ? { error } : {})}
/>
<Button type="submit" size="lg" fullWidth isLoading={busy}>
Enregistrer
</Button>
<Button type="button" variant="ghost" size="md" fullWidth onClick={onLogout}>
Se déconnecter
</Button>
</form>
</CardContent>
</Card>
</div>
</main>
);
};