Harden catalog admin: fix translate/quick-add, RCON sync, and confirm UX.
Local Build and Deploy / deploy (push) Successful in 1m18s
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:
1 parent
de9f837da1
commit
b52e25578d
20 files changed
+557
-216
No files matched your search
@@ -47,6 +47,7 @@ import {
|
||||
import { BulkImportItems } from "@/components/admin/catalog/bulk-import-items";
|
||||
import { ItemsShopPreview } from "@/components/admin/catalog/items-shop-preview";
|
||||
import { QuickAddFurni } from "@/components/admin/catalog/quick-add-furni";
|
||||
import { useConfirmDialog } from "@/components/admin/confirm-dialog";
|
||||
import {
|
||||
CurrencyIcon,
|
||||
currencyKindFromPointsType,
|
||||
@@ -60,7 +61,6 @@ import {
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
@@ -158,6 +158,7 @@ export function CatalogItemsTable({
|
||||
}: CatalogItemsTableProps) {
|
||||
const router = useRouter();
|
||||
const { run, isPending } = useServerAction();
|
||||
const { confirm, dialog: confirmDialog } = useConfirmDialog();
|
||||
const [addOpen, setAddOpen] = useState(false);
|
||||
const [editingItem, setEditingItem] = useState<CatalogItemData | null>(null);
|
||||
const [editingBase, setEditingBase] = useState<BaseItemData | null>(null);
|
||||
@@ -378,6 +379,7 @@ export function CatalogItemsTable({
|
||||
setSavingItemId(null);
|
||||
router.refresh();
|
||||
},
|
||||
onError: () => setSavingItemId(null),
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -436,7 +438,12 @@ export function CatalogItemsTable({
|
||||
// ── Bulk delete selected ─────────────────────────────────────────
|
||||
async function handleBulkDelete() {
|
||||
if (selected.size === 0) return;
|
||||
if (!confirm(`Delete ${selected.size} selected item(s)?`)) return;
|
||||
const ok = await confirm({
|
||||
title: "Delete items",
|
||||
description: `Delete ${selected.size} selected item(s)?`,
|
||||
confirmLabel: "Delete",
|
||||
});
|
||||
if (!ok) return;
|
||||
|
||||
run(() => deleteCatalogItems({ ids: [...selected] }), {
|
||||
successMessage: `Deleted ${selected.size} item(s).`,
|
||||
@@ -584,7 +591,12 @@ export function CatalogItemsTable({
|
||||
}
|
||||
|
||||
async function handleDeleteItem(id: number) {
|
||||
if (!confirm("Delete this catalog item?")) return;
|
||||
const ok = await confirm({
|
||||
title: "Delete item",
|
||||
description: "Delete this catalog item?",
|
||||
confirmLabel: "Delete",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(() => deleteCatalogItems({ ids: [id] }), {
|
||||
successMessage: "Item deleted.",
|
||||
errorMessage: "Failed to delete item.",
|
||||
@@ -867,6 +879,8 @@ export function CatalogItemsTable({
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{confirmDialog}
|
||||
<Card>
|
||||
<CardHeader className="space-y-3">
|
||||
<div className="flex flex-row items-center justify-between gap-4">
|
||||
@@ -1009,12 +1023,10 @@ export function CatalogItemsTable({
|
||||
onImported={() => router.refresh()}
|
||||
/>
|
||||
<Dialog open={addOpen} onOpenChange={setAddOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button size="sm">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Add Item
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<Button size="sm" onClick={() => setAddOpen(true)}>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Add Item
|
||||
</Button>
|
||||
<DialogContent className="max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Add Catalog Item</DialogTitle>
|
||||
@@ -2302,5 +2314,6 @@ export function CatalogItemsTable({
|
||||
</Dialog>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import { deleteCatalogPage, updateCatalogPage } from "@/actions/catalog";
|
||||
import { CatalogImagePicker } from "@/components/admin/catalog/catalog-image-picker";
|
||||
import { IconPicker } from "@/components/admin/catalog/icon-picker";
|
||||
import { ImagePreview } from "@/components/admin/catalog-manager/image-preview";
|
||||
import { useConfirmDialog } from "@/components/admin/confirm-dialog";
|
||||
import { CatalogIcon, LAYOUT_COLORS } from "@/components/admin/catalog-tree";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -90,6 +91,7 @@ export function CatalogPageForm({
|
||||
allPages,
|
||||
}: CatalogPageFormProps) {
|
||||
const { isPending, run } = useServerAction();
|
||||
const { confirm, dialog: confirmDialog } = useConfirmDialog();
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
|
||||
const [form, setForm] = useState({
|
||||
@@ -140,13 +142,18 @@ export function CatalogPageForm({
|
||||
});
|
||||
}
|
||||
|
||||
function handleDelete() {
|
||||
async function handleDelete() {
|
||||
const childCount = childPages.length;
|
||||
const msg =
|
||||
const description =
|
||||
childCount > 0
|
||||
? `Delete this catalog page? Its ${childCount} child page(s) will be moved to root. All items in this page will be deleted.`
|
||||
? `Delete this catalog page? Its ${childCount} child page(s) will be moved to the parent. All items on this page will be deleted.`
|
||||
: "Delete this catalog page and all its items?";
|
||||
if (!confirm(msg)) return;
|
||||
const ok = await confirm({
|
||||
title: "Delete catalog page",
|
||||
description,
|
||||
confirmLabel: "Delete",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(() => deleteCatalogPage({ id: catalogPage.id }), {
|
||||
successMessage: "Page deleted.",
|
||||
redirectTo: "/admin/catalog",
|
||||
@@ -157,7 +164,9 @@ export function CatalogPageForm({
|
||||
LAYOUT_COLORS[form.pageLayout] || "bg-muted text-muted-foreground";
|
||||
|
||||
return (
|
||||
<form ref={formRef} onSubmit={handleSubmit}>
|
||||
<>
|
||||
{confirmDialog}
|
||||
<form ref={formRef} onSubmit={handleSubmit}>
|
||||
<div className="grid gap-4 lg:grid-cols-3">
|
||||
{/* ── Left column (2/3): tabs ─────────────────────────── */}
|
||||
<div className="lg:col-span-2 space-y-4">
|
||||
@@ -495,6 +504,7 @@ export function CatalogPageForm({
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
} from "@/components/ui/table";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
import { useConfirmDialog } from "@/components/admin/confirm-dialog";
|
||||
|
||||
// ── Types ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -82,6 +83,7 @@ interface BcPageDetailProps {
|
||||
|
||||
export function BcPageDetail({ page, items, canEdit }: BcPageDetailProps) {
|
||||
const { isPending, run } = useServerAction();
|
||||
const { confirm, dialog: confirmDialog } = useConfirmDialog();
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
const [editingItem, setEditingItem] = useState<BcItemData | null>(null);
|
||||
const [addingItem, setAddingItem] = useState(false);
|
||||
@@ -130,6 +132,7 @@ export function BcPageDetail({ page, items, canEdit }: BcPageDetailProps) {
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{confirmDialog}
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-3">
|
||||
<Link
|
||||
@@ -338,13 +341,13 @@ export function BcPageDetail({ page, items, canEdit }: BcPageDetailProps) {
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 w-6 p-0 text-[var(--admin-error)] hover:text-[var(--admin-error)]"
|
||||
onClick={() => {
|
||||
if (
|
||||
!confirm(
|
||||
`Delete item "${item.catalogName}"?`,
|
||||
)
|
||||
)
|
||||
return;
|
||||
onClick={async () => {
|
||||
const ok = await confirm({
|
||||
title: "Delete BC item",
|
||||
description: `Delete item "${item.catalogName}"?`,
|
||||
confirmLabel: "Delete",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(() => deleteBcItem({ id: item.id }), {
|
||||
successMessage: "Item deleted.",
|
||||
});
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
@@ -72,12 +71,10 @@ export function CatalogActions({
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
New Page
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<Button type="button" onClick={() => setOpen(true)}>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
New Page
|
||||
</Button>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
|
||||
Reference in new issue
Block a user