Add one-click 'Fix alles' button to catalog page header (runs full furni maintenance)
This commit is contained in:
1 parent
cd418e0390
commit
5a73ba292e
2 files changed
+58
No files matched your search
@@ -15,6 +15,7 @@ import { Store } from "lucide-react";
|
|||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { AdminPageShell } from "@/components/admin/admin-page-shell";
|
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 { CatalogTree } from "@/components/admin/catalog-tree";
|
||||||
import { calcPagination, parseListParams } from "@/lib/admin-helpers";
|
import { calcPagination, parseListParams } from "@/lib/admin-helpers";
|
||||||
import {
|
import {
|
||||||
@@ -289,6 +290,7 @@ export default async function CatalogPagesPage({
|
|||||||
initialParentId={sp.get("newPageParent")}
|
initialParentId={sp.get("newPageParent")}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
<CatalogFixAllButton />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{viewMode === "tree" ? (
|
{viewMode === "tree" ? (
|
||||||
@@ -509,6 +511,7 @@ export default async function CatalogPagesPage({
|
|||||||
{canEdit && (
|
{canEdit && (
|
||||||
<CatalogActions initialParentId={sp.get("newPageParent")} />
|
<CatalogActions initialParentId={sp.get("newPageParent")} />
|
||||||
)}
|
)}
|
||||||
|
<CatalogFixAllButton />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -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 (
|
||||||
|
<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>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user