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
113 lines
3.2 KiB
TypeScript
113 lines
3.2 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 {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/app/components/ui/select";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import type { AdminLocationNode } from "@/app/lib/types";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
/**
|
|
* "Move to…" reparent dialog. The page computes `candidates` (every node except
|
|
* the selected node and its descendants, so a move can never create a cycle) and
|
|
* this dialog PUTs { parentId } through the page's read-merge-write update path.
|
|
*/
|
|
export function MoveLocationDialog({
|
|
node,
|
|
candidates,
|
|
onConfirm,
|
|
}: {
|
|
node: AdminLocationNode;
|
|
candidates: AdminLocationNode[];
|
|
onConfirm: (parentId: number) => Promise<void>;
|
|
}) {
|
|
const t = useT();
|
|
const [open, setOpen] = useState(false);
|
|
const [targetId, setTargetId] = useState<string>("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function handleConfirm() {
|
|
if (!targetId) {
|
|
setError("LocMoveSelectTarget");
|
|
return;
|
|
}
|
|
setError(null);
|
|
setPending(true);
|
|
try {
|
|
await onConfirm(Number(targetId));
|
|
setOpen(false);
|
|
setTargetId("");
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : "LocMoveFailed");
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<DialogTrigger asChild>
|
|
<Button type="button" variant="outline">
|
|
{t("LocMoveTrigger")}
|
|
</Button>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{t("LocMoveTitle", { name: node.name })}</DialogTitle>
|
|
</DialogHeader>
|
|
<p className="text-sm text-muted-foreground">
|
|
{t("LocMoveDescription", { name: node.name, code: node.code })}
|
|
</p>
|
|
<div className="space-y-1">
|
|
<Label htmlFor="move-target">
|
|
{t("LocMoveNewParent")}
|
|
</Label>
|
|
{candidates.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">
|
|
{t("LocMoveNoCandidates")}
|
|
</p>
|
|
) : (
|
|
<Select value={targetId || undefined} onValueChange={setTargetId}>
|
|
<SelectTrigger id="move-target" className="w-full">
|
|
<SelectValue placeholder={t("LocMoveSelectPlaceholder")} />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{candidates.map((c) => (
|
|
<SelectItem key={c.id} value={String(c.id)}>
|
|
{c.name} ({c.code})
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
)}
|
|
</div>
|
|
{error && (
|
|
<p role="alert" className="text-sm text-destructive">
|
|
{t(error)}
|
|
</p>
|
|
)}
|
|
<DialogFooter>
|
|
<Button type="button" onClick={handleConfirm} disabled={pending}>
|
|
{t("Confirm")}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|