Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
120 lines
3.6 KiB
TypeScript
120 lines
3.6 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 = 6;
|
|
|
|
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}
|
|
/>
|
|
</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>
|
|
);
|
|
}
|