feat(catalog): SSR stats in Visual Manager, honest deletes, newPageParent

Pass DB totals into StatsBar, mirror Catalog Structure delete copy, and open New Page with ?newPageParent= for shop and BC.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-07-18 21:14:55 +02:00
1 parent b7fd19b6d9
commit 8d1cf86105
7 files changed
+118 -38

No files matched your search

+24 -1
View File
@@ -1,7 +1,8 @@
"use client";
import { Loader2, Plus } from "lucide-react";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { toast } from "sonner";
import { createCatalogPage } from "@/actions/catalog";
import { createBcPage } from "@/actions/catalog-bc";
@@ -26,18 +27,40 @@ import { CATALOG_LAYOUTS } from "@/lib/catalog-layouts";
interface CatalogActionsProps {
catalogType?: "normal" | "bc";
/** Prefill parent and auto-open create dialog (from ?newPageParent=). */
initialParentId?: string | null;
}
export function CatalogActions({
catalogType = "normal",
initialParentId = null,
}: CatalogActionsProps) {
const { run, isPending } = useServerAction();
const router = useRouter();
const [open, setOpen] = useState(false);
const [caption, setCaption] = useState("");
const [parentId, setParentId] = useState("-1");
const [pageLayout, setPageLayout] = useState("default_3x3");
const isBc = catalogType === "bc";
useEffect(() => {
if (initialParentId == null || initialParentId === "") return;
const n = Number.parseInt(initialParentId, 10);
if (!Number.isFinite(n)) return;
setParentId(String(n));
setOpen(true);
if (typeof window === "undefined") return;
const url = new URL(window.location.href);
if (url.searchParams.has("newPageParent")) {
url.searchParams.delete("newPageParent");
const qs = url.searchParams.toString();
router.replace(`${url.pathname}${qs ? `?${qs}` : ""}`, {
scroll: false,
});
}
}, [initialParentId, router]);
function handleCreate() {
if (!caption.trim()) {
toast.error("Caption is required");
+19 -2
View File
@@ -212,6 +212,11 @@ export default async function CatalogPagesPage({
<CatalogManagerDialog
catalogType="bc"
canEdit={canEdit}
totals={{
totalPages: totalBcPages,
enabledPages: enabledBcPages,
totalItems: totalBcItems,
}}
initialRoots={bcRootPages.map((p) => ({
id: p.id,
caption: p.caption,
@@ -221,7 +226,12 @@ export default async function CatalogPagesPage({
}))}
/>
)}
{canEdit && <CatalogActions catalogType="bc" />}
{canEdit && (
<CatalogActions
catalogType="bc"
initialParentId={sp.get("newPageParent")}
/>
)}
</div>
</div>
{viewMode === "tree" ? (
@@ -398,6 +408,11 @@ export default async function CatalogPagesPage({
<CatalogManagerDialog
catalogType="normal"
canEdit={canEdit}
totals={{
totalPages,
enabledPages,
totalItems,
}}
initialRoots={rootPages.map((p) => ({
id: p.id,
caption: p.caption,
@@ -407,7 +422,9 @@ export default async function CatalogPagesPage({
}))}
/>
)}
{canEdit && <CatalogActions />}
{canEdit && (
<CatalogActions initialParentId={sp.get("newPageParent")} />
)}
</div>
</div>