56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { AlertTriangle } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
import { toast } from "sonner";
|
|
import { fixEverythingAction } from "@/actions/furni-maintenance";
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
/**
|
|
* One-click "fix everything" for the furniture tables. Runs sprite fix, catalog
|
|
* offer fix, FurnitureData reconciliation, dedup and ID alignment in order, all
|
|
* inside a single DB transaction on the server. Heavy — guarded by a confirm.
|
|
*/
|
|
export function CatalogFixAllButton() {
|
|
const router = useRouter();
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
async function run() {
|
|
if (
|
|
!window.confirm(
|
|
"Alle meubel-tabellen repareren (sprite-id, offer_id, dubbelen, IDs naar FurnitureData)?\nDit is een zware, niet-omkeerbare actie. Zorg dat er een backup is.",
|
|
)
|
|
) {
|
|
return;
|
|
}
|
|
setBusy(true);
|
|
try {
|
|
const res = await fixEverythingAction();
|
|
if (res.ok) {
|
|
toast.success("Alle reparaties uitgevoerd");
|
|
router.refresh();
|
|
} else {
|
|
toast.error(res.error ?? "Mislukt");
|
|
}
|
|
} catch (e) {
|
|
toast.error(String(e));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Button
|
|
variant="destructive"
|
|
size="sm"
|
|
disabled={busy}
|
|
onClick={() => void run()}
|
|
title="Alle meubel-tabellen repareren"
|
|
>
|
|
<AlertTriangle className="mr-2 h-4 w-4" />
|
|
{busy ? "Bezig…" : "Fix alles"}
|
|
</Button>
|
|
);
|
|
}
|