- Login copy describes the event CRM instead of orders and payouts.
- Role dialog has no parent field; the role routes require a trimmed name and forward only {name}.
- New-user banner says a temporary password was emailed; TEMP_PASSWORD_NOT_SENT shows a message and a link back to users.
- Username is read-only when editing.
- Password hint and an 8-character minimum match the backend admin password rules.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
122 lines
3.8 KiB
TypeScript
122 lines
3.8 KiB
TypeScript
"use client";
|
|
|
|
import { useState, type FormEvent } from "react";
|
|
import { Alert, AlertDescription } from "@/app/components/ui/alert";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/app/components/ui/dialog";
|
|
import { Input } from "@/app/components/ui/input";
|
|
import { Label } from "@/app/components/ui/label";
|
|
import { ErrorState } from "@/app/components/ui/states";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
import { changeAdminUserPassword } from "@/app/lib/services/adminUsers";
|
|
|
|
const MIN_LENGTH = 8; // services-system ADMIN_PWD_FORMAT minimum
|
|
|
|
export function ChangePasswordDialog({
|
|
userId,
|
|
onClose,
|
|
}: {
|
|
userId: number;
|
|
onClose: () => void;
|
|
}) {
|
|
const t = useT();
|
|
const [password, setPassword] = useState("");
|
|
const [confirm, setConfirm] = useState("");
|
|
const [fieldError, setFieldError] = useState<string | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [success, setSuccess] = useState(false);
|
|
const [saving, setSaving] = useState(false);
|
|
|
|
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
setError(null);
|
|
|
|
if (!password || !confirm) {
|
|
setFieldError(t("UsrPwEnterBoth"));
|
|
return;
|
|
}
|
|
if (password.length < MIN_LENGTH) {
|
|
setFieldError(t("UsrPwTooShort", { min: MIN_LENGTH }));
|
|
return;
|
|
}
|
|
if (password !== confirm) {
|
|
setFieldError(t("UsrPwMismatch"));
|
|
return;
|
|
}
|
|
setFieldError(null);
|
|
|
|
setSaving(true);
|
|
try {
|
|
await changeAdminUserPassword(userId, password);
|
|
setSuccess(true);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : "UsrPwChangeFailed");
|
|
} finally {
|
|
setSaving(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Dialog open onOpenChange={(open) => !open && onClose()}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{t("UsrChangePassword")}</DialogTitle>
|
|
</DialogHeader>
|
|
|
|
{success ? (
|
|
<>
|
|
<Alert>
|
|
<AlertDescription>{t("UsrPwChanged")}</AlertDescription>
|
|
</Alert>
|
|
<DialogFooter>
|
|
<Button onClick={onClose}>{t("Close")}</Button>
|
|
</DialogFooter>
|
|
</>
|
|
) : (
|
|
<form onSubmit={handleSubmit} className="space-y-4" noValidate>
|
|
{error && <ErrorState message={t(error)} />}
|
|
{fieldError && (
|
|
<p role="alert" className="text-sm text-destructive">
|
|
{fieldError}
|
|
</p>
|
|
)}
|
|
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="new-password">{t("ResetNewPassword")}</Label>
|
|
<Input
|
|
id="new-password"
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
disabled={saving}
|
|
aria-describedby="new-password-rules"
|
|
/>
|
|
<p id="new-password-rules" className="text-sm text-muted-foreground">{t("AdminPasswordHint")}</p>
|
|
</div>
|
|
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="confirm-password">{t("UsrConfirmPassword")}</Label>
|
|
<Input
|
|
id="confirm-password"
|
|
type="password"
|
|
value={confirm}
|
|
onChange={(e) => setConfirm(e.target.value)}
|
|
disabled={saving}
|
|
/>
|
|
</div>
|
|
|
|
<DialogFooter>
|
|
<Button type="button" variant="outline" onClick={onClose} disabled={saving}>
|
|
{t("Cancel")}
|
|
</Button>
|
|
<Button type="submit" disabled={saving}>
|
|
{t("UsrChangePassword")}
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
)}
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|