From 5a73ba292eeda6abb67d814c38901204c83ea7dd Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 23 Aug 2026 15:21:26 +0200 Subject: [PATCH] Add one-click 'Fix alles' button to catalog page header (runs full furni maintenance) --- src/app/admin/catalog/page.tsx | 3 + .../admin/catalog/catalog-fix-all-button.tsx | 55 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/components/admin/catalog/catalog-fix-all-button.tsx diff --git a/src/app/admin/catalog/page.tsx b/src/app/admin/catalog/page.tsx index bff919667e..4bded1a98e 100644 --- a/src/app/admin/catalog/page.tsx +++ b/src/app/admin/catalog/page.tsx @@ -15,6 +15,7 @@ import { Store } from "lucide-react"; import { redirect } from "next/navigation"; import { getTranslations } from "next-intl/server"; import { AdminPageShell } from "@/components/admin/admin-page-shell"; +import { CatalogFixAllButton } from "@/components/admin/catalog/catalog-fix-all-button"; import { CatalogTree } from "@/components/admin/catalog-tree"; import { calcPagination, parseListParams } from "@/lib/admin-helpers"; import { @@ -289,6 +290,7 @@ export default async function CatalogPagesPage({ initialParentId={sp.get("newPageParent")} /> )} + {viewMode === "tree" ? ( @@ -509,6 +511,7 @@ export default async function CatalogPagesPage({ {canEdit && ( )} + diff --git a/src/components/admin/catalog/catalog-fix-all-button.tsx b/src/components/admin/catalog/catalog-fix-all-button.tsx new file mode 100644 index 0000000000..7783b2b588 --- /dev/null +++ b/src/components/admin/catalog/catalog-fix-all-button.tsx @@ -0,0 +1,55 @@ +"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 ( + + ); +}