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
118 lines
3.9 KiB
TypeScript
118 lines
3.9 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { Label } from "@/app/components/ui/label";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
DialogFooter,
|
|
} from "@/app/components/ui/dialog";
|
|
import { Input } from "@/app/components/ui/input";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select";
|
|
import { LOCATION_TYPE_LABELS } from "@/app/components/locations/tabs/GeneralTab";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
// The backend's save does not validate parent/child types (HierarchyType.next() exists but is unused), so every type except the single Global root
|
|
// is offered. ponytail: hard-code a parent->child map here if the hierarchy ever gets one.
|
|
const CHILD_TYPES = Object.entries(LOCATION_TYPE_LABELS).filter(([code]) => code !== "G");
|
|
|
|
export function AddLocationDialog({
|
|
parentName,
|
|
onConfirm,
|
|
}: {
|
|
parentName: string;
|
|
onConfirm: (fields: { code: string; name: string; type: string }) => Promise<void>;
|
|
}) {
|
|
const t = useT();
|
|
const [open, setOpen] = useState(false);
|
|
const [code, setCode] = useState("");
|
|
const [name, setName] = useState("");
|
|
const [type, setType] = useState("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function handleConfirm() {
|
|
if (!code.trim() || !name.trim() || !type.trim()) {
|
|
setError("CatCodeNameTypeRequired");
|
|
return;
|
|
}
|
|
setError(null);
|
|
setPending(true);
|
|
try {
|
|
await onConfirm({ code, name, type });
|
|
setOpen(false);
|
|
setCode("");
|
|
setName("");
|
|
setType("");
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : "LocAddFailed");
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<DialogTrigger asChild>
|
|
<Button type="button">{t("LocAddTrigger")}</Button>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{t("LocAddTitle", { parentName })}</DialogTitle>
|
|
</DialogHeader>
|
|
<p className="text-sm text-muted-foreground">
|
|
{t("LocAddDescription", { parentName })}
|
|
</p>
|
|
<div className="space-y-3">
|
|
<div className="space-y-1">
|
|
<Label htmlFor="new-loc-code">
|
|
{t("Code")}
|
|
</Label>
|
|
<Input id="new-loc-code" value={code} onChange={(e) => setCode(e.target.value)} />
|
|
</div>
|
|
<div className="space-y-1">
|
|
<Label htmlFor="new-loc-name">
|
|
{t("CatName")}
|
|
</Label>
|
|
<Input id="new-loc-name" value={name} onChange={(e) => setName(e.target.value)} />
|
|
</div>
|
|
<div className="space-y-1">
|
|
<Label htmlFor="new-loc-type">
|
|
{t("Type")}
|
|
</Label>
|
|
<Select value={type} onValueChange={setType}>
|
|
<SelectTrigger id="new-loc-type" className="w-full">
|
|
<SelectValue placeholder={t("CatSelectType")} />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{CHILD_TYPES.map(([code, label]) => (
|
|
<SelectItem key={code} value={code}>
|
|
{t(label)}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
{error && (
|
|
<p role="alert" className="text-sm text-destructive">
|
|
{t(error)}
|
|
</p>
|
|
)}
|
|
</div>
|
|
<DialogFooter>
|
|
<Button type="button" variant="outline" onClick={() => setOpen(false)} disabled={pending}>
|
|
{t("Cancel")}
|
|
</Button>
|
|
<Button type="button" onClick={handleConfirm} disabled={pending}>
|
|
{t("Confirm")}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|