Harden catalog admin: fix translate/quick-add, RCON sync, and confirm UX.
Local Build and Deploy / deploy (push) Successful in 1m18s

Restore broken Quick Add search, correct Translate saves to items_base and FurnitureData, reparent page deletes, sync RCON on create/toggle/BC mutations, and replace native confirms/prompts with dialogs.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-07-17 21:12:58 +02:00
1 parent de9f837da1
commit b52e25578d
20 files changed
+557 -216

No files matched your search

@@ -1,16 +1,20 @@
"use client";
import { LayoutGrid } from "lucide-react";
import { LayoutGrid, Plus } from "lucide-react";
import { useCallback, useEffect, useState } from "react";
import { toast } from "sonner";
import { createCatalogPage } from "@/actions/catalog";
import { useConfirmDialog } from "@/components/admin/confirm-dialog";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { TooltipProvider } from "@/components/ui/tooltip";
import type { RootTab } from "@/types/catalog";
import { BreadcrumbBar } from "./breadcrumb-bar";
@@ -47,15 +51,16 @@ export function CatalogManagerDialog() {
function CatalogManagerInner({
open,
// biome-ignore lint/correctness/noUnusedFunctionParameters: part of the dialog public API
onOpenChange,
}: {
open: boolean;
onOpenChange: (v: boolean) => void;
}) {
const { state, dispatch } = useCatalogManager();
const { confirm, dialog: confirmDialog } = useConfirmDialog();
const [createOpen, setCreateOpen] = useState(false);
const [newRootName, setNewRootName] = useState("");
const [creating, setCreating] = useState(false);
// Load root pages when dialog opens
const loadRootPages = useCallback(async () => {
dispatch({ type: "SET_LOADING_ROOT", loading: true });
try {
@@ -73,7 +78,6 @@ function CatalogManagerInner({
);
dispatch({ type: "SET_ROOT_PAGES", pages });
// Auto-select first tab if none or missing
if (
pages.length > 0 &&
(!state.activeTabId || !pages.find((p) => p.id === state.activeTabId))
@@ -86,53 +90,65 @@ function CatalogManagerInner({
}
}, [dispatch, state.activeTabId]);
// biome-ignore lint/correctness/useExhaustiveDependencies: explicitly chosen here, see surrounding code
// biome-ignore lint/correctness/useExhaustiveDependencies: load once when dialog opens
useEffect(() => {
if (open) loadRootPages();
}, [open]); // eslint-disable-line react-hooks/exhaustive-deps
}, [open]);
// Handle dialog close: preserve tree state, clear selection
useEffect(() => {
if (!open) dispatch({ type: "ON_DIALOG_CLOSE" });
}, [open, dispatch]);
const handleTabClick = (id: number) => {
if (state.editorDirty && !confirm("You have unsaved changes. Discard?"))
return;
async function confirmDiscardIfDirty(): Promise<boolean> {
if (!state.editorDirty) return true;
return confirm({
title: "Unsaved changes",
description: "You have unsaved changes. Discard them?",
confirmLabel: "Discard",
cancelLabel: "Keep editing",
});
}
const handleTabClick = async (id: number) => {
if (!(await confirmDiscardIfDirty())) return;
dispatch({ type: "SET_ACTIVE_TAB", id });
dispatch({ type: "CLEAR_TREE" });
};
const handleCreateRoot = async () => {
const caption = prompt("Root page name:");
if (!caption?.trim()) return;
const caption = newRootName.trim();
if (!caption) return;
setCreating(true);
try {
const result = await createCatalogPage({
parentId: -1,
caption: caption.trim(),
caption,
});
if (!result.ok) throw new Error(result.error);
setCreateOpen(false);
setNewRootName("");
await loadRootPages();
toast.success("Root page created");
} catch {
toast.error("Failed to create root page");
} finally {
setCreating(false);
}
};
const handleSelectPage = (id: number) => {
if (state.editorDirty && !confirm("You have unsaved changes. Discard?"))
return;
const handleSelectPage = async (id: number) => {
if (!(await confirmDiscardIfDirty())) return;
dispatch({ type: "SELECT_PAGE", id: id > 0 ? id : null });
};
const handleEditTab = (id: number) => {
// First ensure this tab is active, then select it in the editor
const handleEditTab = async (id: number) => {
if (state.activeTabId !== id) {
if (!(await confirmDiscardIfDirty())) return;
dispatch({ type: "SET_ACTIVE_TAB", id });
dispatch({ type: "CLEAR_TREE" });
}
if (state.editorDirty && !confirm("You have unsaved changes. Discard?"))
} else if (!(await confirmDiscardIfDirty())) {
return;
}
dispatch({ type: "SELECT_PAGE", id });
};
@@ -140,7 +156,6 @@ function CatalogManagerInner({
dispatch({ type: "UPDATE_NODE", update: { ...updated } });
dispatch({ type: "SET_DIRTY", dirty: false });
// Update root tabs if root page
const rootIdx = state.rootPages.findIndex((p) => p.id === updated.id);
if (rootIdx !== -1) {
const pages = [...state.rootPages];
@@ -155,7 +170,7 @@ function CatalogManagerInner({
return (
<TooltipProvider delayDuration={300}>
{/* Header */}
{confirmDialog}
<DialogHeader className="px-4 py-2.5 border-b shrink-0">
<DialogTitle className="text-base flex items-center gap-2">
<LayoutGrid className="h-4 w-4" />
@@ -163,20 +178,17 @@ function CatalogManagerInner({
</DialogTitle>
</DialogHeader>
{/* Breadcrumb */}
<BreadcrumbBar />
{/* Root tabs */}
<RootTabs
tabs={state.rootPages}
activeTabId={state.activeTabId}
onTabClick={handleTabClick}
onEditTab={handleEditTab}
onCreateRoot={handleCreateRoot}
onCreateRoot={() => setCreateOpen(true)}
loading={state.loadingRoot}
/>
{/* Main content: tree + editor */}
<div className="flex flex-1 min-h-0">
<SortableTree
activeTabId={state.activeTabId}
@@ -191,8 +203,45 @@ function CatalogManagerInner({
/>
</div>
{/* Stats bar */}
<StatsBar />
<Dialog open={createOpen} onOpenChange={setCreateOpen}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>New root page</DialogTitle>
</DialogHeader>
<div className="space-y-2">
<Label htmlFor="root-caption">Name</Label>
<Input
id="root-caption"
value={newRootName}
onChange={(e) => setNewRootName(e.target.value)}
placeholder="e.g. Furniture"
autoFocus
onKeyDown={(e) => {
if (e.key === "Enter") void handleCreateRoot();
}}
/>
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => setCreateOpen(false)}
>
Cancel
</Button>
<Button
type="button"
disabled={creating || !newRootName.trim()}
onClick={handleCreateRoot}
>
<Plus className="mr-1 h-4 w-4" />
Create
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</TooltipProvider>
);
}