"use client"; import { useState } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, DialogFooter, } from "@/app/components/ui/dialog"; import { Button } from "@/app/components/ui/button"; import type { AdminLocationNode } from "@/app/lib/types"; import { useT } from "@/app/lib/i18n/MessagesProvider"; /** * Confirmation dialog for the structural status toggle on a location node. * PUTs { status } through the page's read-merge-write update path (the backend * has no dedicated status endpoint — see AdminLocationService.update). */ export function StatusToggleDialog({ node, onConfirm, }: { node: AdminLocationNode; onConfirm: (status: "Y" | "N") => Promise; }) { const t = useT(); const [open, setOpen] = useState(false); const [error, setError] = useState(null); const [pending, setPending] = useState(false); const active = node.status === "Y"; const next = active ? "N" : "Y"; async function handleConfirm() { setError(null); setPending(true); try { await onConfirm(next); setOpen(false); } catch (err) { setError(err instanceof Error ? err.message : "LocStatusUpdateFailed"); } finally { setPending(false); } } return ( {active ? t("LocStatusDeactivateTitle", { name: node.name }) : t("LocStatusActivateTitle", { name: node.name })}

{active ? t("LocStatusDeactivateDescription", { name: node.name, code: node.code }) : t("LocStatusActivateDescription", { name: node.name, code: node.code })}

{error && (

{t(error)}

)}
); }