create-nextblock 0.15.8 → 0.15.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/package.json +1 -1
  2. package/templates/nextblock-template/app/ToasterProvider.tsx +26 -17
  3. package/templates/nextblock-template/app/actions/contactSellerActions.test.ts +280 -0
  4. package/templates/nextblock-template/app/actions/contactSellerActions.ts +222 -0
  5. package/templates/nextblock-template/app/actions/email-retry.test.ts +62 -0
  6. package/templates/nextblock-template/app/actions/email.ts +241 -110
  7. package/templates/nextblock-template/app/actions/formActions.ts +245 -116
  8. package/templates/nextblock-template/app/actions/interactions.ts +489 -396
  9. package/templates/nextblock-template/app/actions/threadActions.ts +166 -0
  10. package/templates/nextblock-template/app/api/checkout/route.ts +162 -146
  11. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +664 -1
  12. package/templates/nextblock-template/app/checkout/page.tsx +57 -52
  13. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +552 -529
  14. package/templates/nextblock-template/app/cms/blocks/editors/FormBlockEditor.tsx +304 -181
  15. package/templates/nextblock-template/app/cms/components/ContactReminderBanner.tsx +75 -0
  16. package/templates/nextblock-template/app/cms/components/PaymentsReminderBanner.tsx +58 -0
  17. package/templates/nextblock-template/app/cms/components/VisibilityControl.tsx +542 -528
  18. package/templates/nextblock-template/app/cms/inquiries/actions.ts +66 -0
  19. package/templates/nextblock-template/app/cms/inquiries/page.tsx +12 -0
  20. package/templates/nextblock-template/app/cms/interactions/page.tsx +12 -51
  21. package/templates/nextblock-template/app/cms/layout.tsx +101 -73
  22. package/templates/nextblock-template/app/cms/messages/MessagesClient.tsx +661 -0
  23. package/templates/nextblock-template/app/cms/messages/actions.ts +404 -0
  24. package/templates/nextblock-template/app/cms/messages/loadInbox.ts +333 -0
  25. package/templates/nextblock-template/app/cms/messages/page.tsx +87 -0
  26. package/templates/nextblock-template/app/cms/messages/require-admin.ts +37 -0
  27. package/templates/nextblock-template/app/cms/products/[id]/edit/page.tsx +370 -362
  28. package/templates/nextblock-template/app/cms/revisions/service.ts +20 -0
  29. package/templates/nextblock-template/app/cms/settings/email/components/EmailForm.tsx +227 -185
  30. package/templates/nextblock-template/app/layout.tsx +671 -671
  31. package/templates/nextblock-template/app/product/[slug]/page.tsx +502 -482
  32. package/templates/nextblock-template/app/providers.tsx +96 -96
  33. package/templates/nextblock-template/app/thread/ThreadView.tsx +164 -0
  34. package/templates/nextblock-template/app/thread/[token]/route.ts +57 -0
  35. package/templates/nextblock-template/app/thread/layout.tsx +15 -0
  36. package/templates/nextblock-template/app/thread/page.tsx +98 -0
  37. package/templates/nextblock-template/components/BlockRenderer.tsx +312 -296
  38. package/templates/nextblock-template/components/ContactSellerSection.tsx +188 -0
  39. package/templates/nextblock-template/components/PostCommentsSection.tsx +378 -369
  40. package/templates/nextblock-template/components/ProductReviewsSection.tsx +426 -419
  41. package/templates/nextblock-template/components/StaffReplies.tsx +102 -0
  42. package/templates/nextblock-template/components/blocks/renderers/CartBlockRenderer.tsx +18 -17
  43. package/templates/nextblock-template/components/blocks/renderers/CheckoutBlockRenderer.tsx +20 -19
  44. package/templates/nextblock-template/components/blocks/renderers/FeaturedProductBlockRenderer.tsx +25 -22
  45. package/templates/nextblock-template/components/blocks/renderers/FormBlockRenderer.tsx +385 -381
  46. package/templates/nextblock-template/components/blocks/renderers/ProductDetailsBlockRenderer.tsx +157 -92
  47. package/templates/nextblock-template/components/blocks/renderers/ProductGridBlockRenderer.tsx +34 -31
  48. package/templates/nextblock-template/components/blocks/renderers/SectionBlockRenderer.tsx +612 -600
  49. package/templates/nextblock-template/components/commerce/PaymentReadinessBoundary.tsx +32 -0
  50. package/templates/nextblock-template/docs/14-MESSAGES-INBOX.md +309 -0
  51. package/templates/nextblock-template/docs/README.md +42 -41
  52. package/templates/nextblock-template/docs/assets/lighthouse-scores.png +0 -0
  53. package/templates/nextblock-template/lib/blocks/blockColors.test.ts +22 -2
  54. package/templates/nextblock-template/lib/blocks/blockColors.ts +44 -1
  55. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +761 -753
  56. package/templates/nextblock-template/lib/cms/contact-reminder.ts +64 -0
  57. package/templates/nextblock-template/lib/cms/payments-reminder.ts +98 -0
  58. package/templates/nextblock-template/lib/cms/unread-messages.ts +42 -0
  59. package/templates/nextblock-template/lib/commerce/seller-contact.ts +162 -0
  60. package/templates/nextblock-template/lib/config/email-settings.ts +323 -254
  61. package/templates/nextblock-template/lib/config/email-tls.test.ts +57 -0
  62. package/templates/nextblock-template/lib/email/placeholder-address.test.ts +59 -0
  63. package/templates/nextblock-template/lib/email/placeholder-address.ts +39 -0
  64. package/templates/nextblock-template/lib/messages/thread-reference.test.ts +70 -0
  65. package/templates/nextblock-template/lib/messages/thread-token.test.ts +93 -0
  66. package/templates/nextblock-template/lib/messages/thread-token.ts +157 -0
  67. package/templates/nextblock-template/lib/messages/threads.ts +579 -0
  68. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +20 -0
  69. package/templates/nextblock-template/lib/site-url.test.ts +89 -0
  70. package/templates/nextblock-template/lib/site-url.ts +102 -48
  71. package/templates/nextblock-template/package.json +1 -1
@@ -1,529 +1,552 @@
1
- // app/cms/CmsClientLayout.tsx
2
- "use client"
3
-
4
- import React, { type ReactNode, useEffect } from "react"
5
- import { useAuth } from "../../context/AuthContext"
6
- import { useRouter, usePathname } from "next/navigation" // Import usePathname
7
- import Link from "next/link"
8
- import {
9
- LayoutDashboard, FileText, PenTool, Users, Settings, ChevronRight, LogOut, Menu, ListTree, Image as ImageIconLucide, X, Languages as LanguagesIconLucide, MessageSquare,
10
- Copyright as CopyrightIcon, ShoppingBag, ListOrdered, CreditCard, Package, Coins,
11
- ExternalLink, Paintbrush, Brain, TicketPercent, ShieldAlert, Folder, DatabaseBackup, Boxes, Tag,
12
- ShieldCheck, Code2, Cookie, LineChart, Mail, UserPlus, SlidersHorizontal,
13
- } from "lucide-react"
14
- import TwoFactorReminderBanner from "./components/TwoFactorReminderBanner"
15
- import SystemAlertsBanner, { type SystemAlertItem } from "./components/SystemAlertsBanner"
16
- import { Button } from "@nextblock-cms/ui"
17
- import { Avatar, AvatarFallback, AvatarImage } from "@nextblock-cms/ui"
18
- import { cn } from "@nextblock-cms/utils"
19
- import { signOutAction } from "../actions"
20
- import Image from "next/image";
21
- import { FeedbackModal } from "./components/FeedbackModal";
22
- import { CortexGlobalAgentChat } from "./components/CortexGlobalAgentChat";
23
- import { CortexAiPageContextProvider } from "./components/CortexAiPageContext";
24
- import { CortexAiActiveProvider } from "./components/CortexAiActiveContext";
25
- import { EcommerceActiveProvider } from "./components/EcommerceActiveContext";
26
- import { useAppBranding } from "../../components/AppShell";
27
- import { resolveMediaUrl } from "../../lib/media/resolveMediaUrl";
28
-
29
- const FALLBACK_LOGO_PATH = "/images/nextblock-logo-small.webp";
30
-
31
- const LoadingSpinner = () => (
32
- <div className="flex justify-center items-center h-full w-full py-20">
33
- <div className="relative">
34
- <div className="h-16 w-16 rounded-full border-t-4 border-b-4 border-primary animate-spin"></div>
35
- <div className="absolute inset-0 flex items-center justify-center">
36
- <div className="h-10 w-10 rounded-full bg-background"></div>
37
- </div>
38
- </div>
39
- </div>
40
- );
41
-
42
- type NavItemProps = {
43
- href: string
44
- icon: React.ElementType
45
- children: React.ReactNode
46
- isActive?: boolean
47
- adminOnly?: boolean
48
- writerOnly?: boolean
49
- isAdmin?: boolean
50
- isWriter?: boolean
51
- onClick?: () => void
52
- }
53
-
54
- const NavItem = ({ href, icon: Icon, children, isActive, adminOnly, writerOnly, isAdmin, isWriter, onClick }: NavItemProps) => {
55
- if (adminOnly && !isAdmin) return null
56
- if (writerOnly && !isWriter && !isAdmin) return null
57
-
58
- return (
59
- <li>
60
- <Link
61
- href={href}
62
- onClick={onClick}
63
- className={cn(
64
- "flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium transition-all",
65
- isActive
66
- ? "bg-primary/10 text-primary dark:bg-primary/20"
67
- : "text-slate-600 hover:text-primary hover:bg-primary/5 dark:text-slate-300 dark:hover:bg-primary/10",
68
- )}
69
- >
70
- <Icon className="h-5 w-5" />
71
- <span>{children}</span>
72
- {isActive && <ChevronRight className="h-4 w-4 ml-auto" />}
73
- </Link>
74
- </li>
75
- )
76
- };
77
-
78
- type CollapsibleNavItemProps = {
79
- icon: React.ElementType
80
- title: string
81
- children: React.ReactNode
82
- isActive?: boolean
83
- adminOnly?: boolean
84
- isAdmin?: boolean
85
- }
86
-
87
- const CollapsibleNavItem = ({ icon: Icon, title, children, isActive, adminOnly, isAdmin }: CollapsibleNavItemProps) => {
88
- const [isOpen, setIsOpen] = React.useState(isActive);
89
-
90
- if (adminOnly && !isAdmin) return null
91
-
92
- return (
93
- <li>
94
- <button
95
- onClick={() => setIsOpen(!isOpen)}
96
- className={cn(
97
- "flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium transition-all w-full",
98
- isActive
99
- ? "bg-primary/10 text-primary dark:bg-primary/20"
100
- : "text-slate-600 hover:text-primary hover:bg-primary/5 dark:text-slate-300 dark:hover:bg-primary/10",
101
- )}
102
- >
103
- <Icon className="h-5 w-5" />
104
- <span>{title}</span>
105
- <ChevronRight className={cn("h-4 w-4 ml-auto transition-transform", isOpen && "rotate-90")} />
106
- </button>
107
- {isOpen && (
108
- <ul className="pl-6 space-y-1.5 mt-1.5">
109
- {children}
110
- </ul>
111
- )}
112
- </li>
113
- )
114
- };
115
-
116
-
117
- export default function CmsClientLayout({
118
- children,
119
- isCortexAiActive = false,
120
- isEcommerceActive = false,
121
- showTwoFactorReminder = false,
122
- systemAlerts = [],
123
- }: {
124
- children: ReactNode,
125
- isCortexAiActive?: boolean,
126
- isEcommerceActive?: boolean,
127
- showTwoFactorReminder?: boolean,
128
- systemAlerts?: SystemAlertItem[],
129
- }) {
130
- const isSandbox = process.env.NEXT_PUBLIC_IS_SANDBOX === 'true';
131
- const { user, profile, role, isLoading, isAdmin, isWriter } = useAuth();
132
- const { logo, siteTitle } = useAppBranding();
133
- const router = useRouter();
134
- const pathname = usePathname(); // Use the usePathname hook
135
- const [cmsSidebarOpen, setCmsSidebarOpen] = React.useState(false);
136
-
137
- useEffect(() => {
138
- if (!isLoading) {
139
- if (!user) {
140
- router.push(`/sign-in?redirect=${encodeURIComponent(pathname || "/cms/dashboard")}`);
141
- } else if (!isWriter && !isAdmin) {
142
- router.push("/unauthorized?reason=insufficient_role_in_layout");
143
- }
144
- }
145
- }, [user, role, isLoading, router, isAdmin, isWriter, pathname]);
146
-
147
- useEffect(() => {
148
- const mainLayoutElement = document.querySelector('body > div > main > div.flex-1.w-full.flex.flex-col.items-center');
149
- if (mainLayoutElement) {
150
- mainLayoutElement.classList.remove('max-w-7xl');
151
- (mainLayoutElement as HTMLElement).style.padding = '0';
152
- }
153
- const mainScreenChild = document.querySelector('main.min-h-screen > div.flex-1.w-full');
154
- if (mainScreenChild) {
155
- mainScreenChild.classList.remove("max-w-7xl");
156
- }
157
-
158
- const handleResize = () => {
159
- if (window.innerWidth >= 768) {
160
- setCmsSidebarOpen(true);
161
- } else {
162
- // setCmsSidebarOpen(false); // Removed to allow manual toggle on mobile
163
- }
164
- };
165
- handleResize();
166
- window.addEventListener('resize', handleResize);
167
- return () => window.removeEventListener('resize', handleResize);
168
- }, []);
169
-
170
- const closeSidebarOnMobile = () => {
171
- if (window.innerWidth < 768) {
172
- setCmsSidebarOpen(false);
173
- }
174
- };
175
-
176
- const handleSignOut = async () => {
177
- await signOutAction();
178
- };
179
-
180
-
181
- // With server-side auth data, isLoading is initially false.
182
- // We show a spinner only if something client-side sets it to true (e.g., during logout).
183
- if (isLoading) {
184
- return <LoadingSpinner />;
185
- }
186
-
187
- // The useEffect handles redirection if the server-provided user/role is insufficient.
188
- // Returning null here prevents rendering the layout for unauthorized users.
189
- if (!user || (!isWriter && !isAdmin)) {
190
- return null;
191
- }
192
-
193
- const getInitials = () => {
194
- if (profile && profile.full_name) return profile.full_name.split(' ').map((n: string) => n[0]).join('').substring(0,2).toUpperCase();
195
- if (user && user.email) return user.email.charAt(0).toUpperCase();
196
- return "U"; // Default fallback
197
- }
198
- const getRoleColor = () => {
199
- if (isAdmin) return "bg-amber-500";
200
- if (isWriter) return "bg-emerald-500";
201
- return "bg-sky-500"; // Default color
202
- }
203
- const cmsLogoSrc = resolveMediaUrl(logo?.media?.object_key) || FALLBACK_LOGO_PATH;
204
- const cmsLogoAlt = logo?.media?.alt_text || siteTitle || "Nextblock";
205
-
206
- // pageTitle logic should now work reliably with usePathname
207
- let pageTitle = "CMS"; // Default title
208
- if (pathname === "/cms/dashboard") pageTitle = "Dashboard";
209
- else if (pathname.startsWith("/cms/custom-blocks/new")) pageTitle = "Create Custom Block";
210
- else if (pathname.startsWith("/cms/custom-blocks/") && pathname.endsWith("/edit")) pageTitle = "Edit Custom Block";
211
- else if (pathname.startsWith("/cms/custom-blocks")) pageTitle = "Block Management";
212
- else if (pathname.startsWith("/cms/pages/new")) pageTitle = "New Page";
213
- else if (pathname.startsWith("/cms/pages/") && pathname.endsWith("/edit")) pageTitle = "Edit Page";
214
- else if (pathname.startsWith("/cms/pages")) pageTitle = "Pages";
215
- else if (pathname.startsWith("/cms/posts/new")) pageTitle = "New Post";
216
- else if (pathname.startsWith("/cms/posts/") && pathname.endsWith("/edit")) pageTitle = "Edit Post";
217
- else if (pathname.startsWith("/cms/posts")) pageTitle = "Posts";
218
- else if (pathname.startsWith("/cms/navigation/new")) pageTitle = "New Navigation Item";
219
- else if (pathname.startsWith("/cms/navigation/") && pathname.includes("/edit")) pageTitle = "Edit Navigation Item";
220
- else if (pathname.startsWith("/cms/navigation")) pageTitle = "Navigation";
221
- else if (pathname.startsWith("/cms/media/") && pathname.endsWith("/edit")) pageTitle = "Edit Media Item";
222
- else if (pathname.startsWith("/cms/media")) pageTitle = "Media Library";
223
- else if (pathname.startsWith("/cms/users/") && pathname.endsWith("/edit")) pageTitle = "Edit User Profile";
224
- else if (pathname.startsWith("/cms/users")) pageTitle = "User Management";
225
- else if (pathname.startsWith("/cms/settings/languages/new")) pageTitle = "New Language";
226
- else if (pathname.startsWith("/cms/settings/languages") && pathname.includes("/edit")) pageTitle = "Edit Language";
227
- else if (pathname.startsWith("/cms/settings/languages")) pageTitle = "Language Settings";
228
- // Fallback for general /cms/settings if no more specific language path matches
229
- else if (pathname.startsWith("/cms/settings/logos")) pageTitle = "Branding";
230
- else if (pathname.startsWith("/cms/settings/copyright")) pageTitle = "Copyright Settings";
231
- else if (pathname.startsWith("/cms/settings/global-css")) pageTitle = "Themes & CSS";
232
- else if (pathname.startsWith("/cms/settings/site-scripts")) pageTitle = "Site Scripts";
233
- else if (pathname.startsWith("/cms/settings/extra-translations")) pageTitle = "Extra Translations";
234
- else if (pathname.startsWith("/cms/settings/backup-restore")) pageTitle = "Backup And Restore";
235
- else if (pathname.startsWith("/cms/settings/currencies")) pageTitle = "Currency Settings";
236
- else if (pathname.startsWith("/cms/settings/taxes")) pageTitle = "Tax Settings";
237
- else if (pathname.startsWith("/cms/settings/cortex-ai")) pageTitle = "Cortex AI";
238
- else if (pathname.startsWith("/cms/settings/bot-protection")) pageTitle = "Bot Protection";
239
- else if (pathname.startsWith("/cms/settings/email")) pageTitle = "Email";
240
- else if (pathname.startsWith("/cms/settings/registration")) pageTitle = "Sign-ups & Registration";
241
- else if (pathname.startsWith("/cms/settings/google-analytics")) pageTitle = "Google Analytics";
242
- else if (pathname.startsWith("/cms/settings/privacy")) pageTitle = "Privacy & Consent";
243
- else if (pathname.startsWith("/cms/settings/security")) pageTitle = "Security & 2FA";
244
- else if (pathname.startsWith("/cms/payments")) pageTitle = "Payment Settings";
245
-
246
- else if (pathname.startsWith("/cms/settings/packages")) pageTitle = "Packages";
247
- else if (pathname.startsWith("/cms/settings")) pageTitle = "Settings";
248
- else if (pathname.startsWith("/cms/interactions")) pageTitle = "Interactions";
249
- else if (pathname.startsWith("/cms/products/inventory")) pageTitle = "Inventory";
250
- else if (pathname.startsWith("/cms/coupons/") && pathname.endsWith("/edit")) pageTitle = "Edit Coupon";
251
- else if (pathname.startsWith("/cms/coupons")) pageTitle = "Coupons";
252
- else if (pathname.startsWith("/cms/products/new")) pageTitle = "New Product";
253
- else if (pathname.startsWith("/cms/products/") && pathname.endsWith("/edit")) pageTitle = "Edit Product";
254
- else if (pathname.startsWith("/cms/products")) pageTitle = "Products";
255
- else if (pathname.startsWith("/cms/orders/") && pathname.endsWith("/edit")) pageTitle = "Edit Order";
256
- else if (pathname.startsWith("/cms/orders")) pageTitle = "Orders";
257
-
258
-
259
- return (
260
- <CortexAiPageContextProvider>
261
- <CortexAiActiveProvider isActive={isCortexAiActive}>
262
- <EcommerceActiveProvider isActive={isEcommerceActive}>
263
- <div className="relative flex h-full min-h-0 w-full overflow-hidden bg-slate-50 dark:bg-slate-950 md:flex-row">
264
- <div className="fixed bottom-4 right-4 z-[60] md:hidden">
265
- <Button
266
- variant="outline"
267
- size="icon"
268
- onClick={() => setCmsSidebarOpen(!cmsSidebarOpen)}
269
- className="bg-white shadow-lg dark:bg-slate-800 rounded-full h-12 w-12"
270
- >
271
- {cmsSidebarOpen ? <X className="h-5 w-5" /> : <Menu className="h-5 w-5" />}
272
- </Button>
273
- </div>
274
-
275
- <aside
276
- className={cn(
277
- "fixed left-0 top-16 bottom-0 w-64 bg-white shadow-lg transition-transform duration-300 ease-in-out dark:bg-slate-900 dark:border-r dark:border-slate-700/60",
278
- "md:sticky md:top-0 md:bottom-auto md:h-full md:translate-x-0",
279
- cmsSidebarOpen ? "translate-x-0" : "-translate-x-full",
280
- "z-30"
281
- )}
282
- >
283
- <div className="flex h-full min-h-0 flex-col">
284
- <div className="p-4 border-b dark:border-slate-700/60 h-16 flex items-center shrink-0">
285
- <Link href="/cms/dashboard" className="flex items-center gap-2 px-2">
286
- <Image
287
- src={cmsLogoSrc}
288
- alt={cmsLogoAlt}
289
- width={logo?.media?.width || 32}
290
- height={logo?.media?.height || 32}
291
- className="h-8 w-auto"
292
- priority
293
- />
294
- <h2 className="text-xl font-bold text-foreground">
295
- Nextblock CMS
296
- </h2>
297
- </Link>
298
- </div>
299
-
300
- <nav className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-4">
301
- <ul className="space-y-1.5">
302
- <NavItem href="/cms/dashboard" icon={LayoutDashboard} isActive={pathname === "/cms/dashboard"} isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
303
- Dashboard
304
- </NavItem>
305
- {isCortexAiActive && (
306
- <NavItem href="/cms/settings/cortex-ai" icon={Brain} isActive={pathname.startsWith("/cms/settings/cortex-ai")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
307
- Cortex AI
308
- </NavItem>
309
- )}
310
- <NavItem href="/cms/pages" icon={FileText} isActive={pathname.startsWith("/cms/pages")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
311
- Pages
312
- </NavItem>
313
- <NavItem href="/cms/posts" icon={PenTool} isActive={pathname.startsWith("/cms/posts")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
314
- Posts
315
- </NavItem>
316
- <NavItem href="/cms/media" icon={ImageIconLucide} isActive={pathname.startsWith("/cms/media")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
317
- Media
318
- </NavItem>
319
- <NavItem href="/cms/custom-blocks" icon={Boxes} isActive={pathname.startsWith("/cms/custom-blocks")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
320
- Blocks
321
- </NavItem>
322
- <NavItem href="/cms/interactions" icon={MessageSquare} isActive={pathname.startsWith("/cms/interactions")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
323
- Interactions
324
- </NavItem>
325
- <NavItem href="/cms/navigation" icon={ListTree} isActive={pathname.startsWith("/cms/navigation")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
326
- Navigation
327
- </NavItem>
328
- {!isSandbox && (
329
- <NavItem href="/cms/settings/security" icon={ShieldCheck} isActive={pathname.startsWith("/cms/settings/security")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
330
- Security
331
- </NavItem>
332
- )}
333
-
334
- {isEcommerceActive && (
335
- <>
336
- <div className="mt-6 mb-2">
337
- <p className="px-3 text-xs font-semibold text-slate-500 uppercase tracking-wider dark:text-slate-400">
338
- Store
339
- </p>
340
- </div>
341
- <CollapsibleNavItem
342
- icon={ShoppingBag}
343
- title="Products"
344
- isActive={pathname.startsWith("/cms/products")}
345
- >
346
- <NavItem href="/cms/products" icon={ShoppingBag} isActive={pathname === "/cms/products" || (pathname.startsWith("/cms/products/") && !pathname.startsWith("/cms/products/categories") && !pathname.startsWith("/cms/products/attributes") && !pathname.startsWith("/cms/products/inventory"))} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
347
- All Products
348
- </NavItem>
349
- <NavItem href="/cms/products/categories" icon={Folder} isActive={pathname.startsWith("/cms/products/categories")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
350
- Categories
351
- </NavItem>
352
- <NavItem href="/cms/products/inventory" icon={Package} isActive={pathname.startsWith("/cms/products/inventory")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
353
- Inventory
354
- </NavItem>
355
- <NavItem href="/cms/products/attributes" icon={ListTree} isActive={pathname.startsWith("/cms/products/attributes")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
356
- Attributes
357
- </NavItem>
358
- </CollapsibleNavItem>
359
- <NavItem href="/cms/orders" icon={ListOrdered} isActive={pathname.startsWith("/cms/orders")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
360
- Orders
361
- </NavItem>
362
- <NavItem href="/cms/coupons" icon={TicketPercent} isActive={pathname.startsWith("/cms/coupons")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
363
- Coupons
364
- </NavItem>
365
- <NavItem href="/cms/promotions" icon={Tag} isActive={pathname.startsWith("/cms/promotions")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
366
- Bulk Price & Sales
367
- </NavItem>
368
- <CollapsibleNavItem
369
- icon={SlidersHorizontal}
370
- title="Configuration"
371
- isActive={
372
- pathname.startsWith("/cms/payments") ||
373
- pathname.startsWith("/cms/shipping") ||
374
- pathname.startsWith("/cms/settings/taxes") ||
375
- pathname.startsWith("/cms/settings/currencies")
376
- }
377
- adminOnly
378
- isAdmin={isAdmin}
379
- >
380
- <NavItem href="/cms/payments" icon={CreditCard} isActive={pathname.startsWith("/cms/payments")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
381
- Payments
382
- </NavItem>
383
- <NavItem href="/cms/shipping" icon={Package} isActive={pathname.startsWith("/cms/shipping")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
384
- Shipping
385
- </NavItem>
386
- <NavItem href="/cms/settings/taxes" icon={Settings} isActive={pathname.startsWith("/cms/settings/taxes")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
387
- Taxes
388
- </NavItem>
389
- <NavItem href="/cms/settings/currencies" icon={Coins} isActive={pathname.startsWith("/cms/settings/currencies")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
390
- Currencies
391
- </NavItem>
392
- </CollapsibleNavItem>
393
- </>
394
- )}
395
-
396
- {isAdmin && (
397
- <>
398
- <div className="mt-6 mb-2">
399
- <p className="px-3 text-xs font-semibold text-slate-500 uppercase tracking-wider dark:text-slate-400">
400
- Administration
401
- </p>
402
- </div>
403
- <NavItem href="/cms/users" icon={Users} isActive={pathname.startsWith("/cms/users")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
404
- Manage Users
405
- </NavItem>
406
- <NavItem href="/cms/settings/packages" icon={Package} isActive={pathname.startsWith("/cms/settings/packages")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
407
- Packages
408
- </NavItem>
409
- <CollapsibleNavItem
410
- icon={Settings}
411
- title="Settings"
412
- isActive={pathname.startsWith("/cms/settings") && !pathname.startsWith("/cms/settings/taxes") && !pathname.startsWith("/cms/settings/currencies") && !pathname.startsWith("/cms/settings/email") && !pathname.startsWith("/cms/settings/registration") && !pathname.startsWith("/cms/settings/bot-protection")}
413
- adminOnly
414
- isAdmin={isAdmin}
415
- >
416
- <NavItem href="/cms/settings/languages" icon={LanguagesIconLucide} isActive={pathname.startsWith("/cms/settings/languages")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
417
- Languages
418
- </NavItem>
419
- <NavItem href="/cms/settings/logos" icon={ImageIconLucide} isActive={pathname.startsWith("/cms/settings/logos")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
420
- Branding
421
- </NavItem>
422
- <NavItem href="/cms/settings/copyright" icon={CopyrightIcon} isActive={pathname.startsWith("/cms/settings/copyright")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
423
- Copyright
424
- </NavItem>
425
- <NavItem href="/cms/settings/global-css" icon={Paintbrush} isActive={pathname.startsWith("/cms/settings/global-css")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
426
- Themes &amp; CSS
427
- </NavItem>
428
- <NavItem href="/cms/settings/site-scripts" icon={Code2} isActive={pathname.startsWith("/cms/settings/site-scripts")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
429
- Site Scripts
430
- </NavItem>
431
- <NavItem href="/cms/settings/privacy" icon={Cookie} isActive={pathname.startsWith("/cms/settings/privacy")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
432
- Privacy &amp; Consent
433
- </NavItem>
434
- <NavItem href="/cms/settings/google-analytics" icon={LineChart} isActive={pathname.startsWith("/cms/settings/google-analytics")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
435
- Google Analytics
436
- </NavItem>
437
- <NavItem href="/cms/settings/extra-translations" icon={MessageSquare} isActive={pathname.startsWith("/cms/settings/extra-translations")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
438
- Extra Translations
439
- </NavItem>
440
- <NavItem href="/cms/settings/backup-restore" icon={DatabaseBackup} isActive={pathname.startsWith("/cms/settings/backup-restore")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
441
- Backup / Restore
442
- </NavItem>
443
- </CollapsibleNavItem>
444
- <CollapsibleNavItem
445
- icon={SlidersHorizontal}
446
- title="Configuration"
447
- isActive={
448
- pathname.startsWith("/cms/settings/email") ||
449
- pathname.startsWith("/cms/settings/registration") ||
450
- pathname.startsWith("/cms/settings/bot-protection")
451
- }
452
- adminOnly
453
- isAdmin={isAdmin}
454
- >
455
- <NavItem href="/cms/settings/email" icon={Mail} isActive={pathname.startsWith("/cms/settings/email")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
456
- Email
457
- </NavItem>
458
- <NavItem href="/cms/settings/bot-protection" icon={ShieldAlert} isActive={pathname.startsWith("/cms/settings/bot-protection")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
459
- Bot Protection
460
- </NavItem>
461
- <NavItem href="/cms/settings/registration" icon={UserPlus} isActive={pathname.startsWith("/cms/settings/registration")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
462
- Sign-ups
463
- </NavItem>
464
- </CollapsibleNavItem>
465
- </>
466
- )}
467
- </ul>
468
- </nav>
469
-
470
-
471
- <div className="p-3 pb-0">
472
- <FeedbackModal />
473
- </div>
474
-
475
- <div className="mt-auto p-3 border-t border-slate-200 dark:border-slate-700/60 shrink-0">
476
- <div className="flex items-center gap-3">
477
- <Avatar className="h-10 w-10 border">
478
- <AvatarImage src={profile?.avatar_url || undefined} alt={profile?.full_name || user?.email} />
479
- <AvatarFallback className="bg-primary/10 text-primary font-medium">{getInitials()}</AvatarFallback>
480
- </Avatar>
481
- <div className="flex-1 min-w-0">
482
- <p className="text-sm font-medium truncate text-slate-700 dark:text-slate-200">{profile?.full_name || user?.email}</p>
483
- <div className="flex items-center gap-1.5">
484
- <div className={cn("h-2 w-2 rounded-full", getRoleColor())}></div>
485
- <p className="text-xs text-slate-500 dark:text-slate-400 capitalize">{role}</p>
486
- </div>
487
- </div>
488
- <Button onClick={handleSignOut} variant="ghost" size="icon" className="text-slate-500 hover:text-slate-700 dark:text-slate-400 dark:hover:text-slate-300" title="Sign Out">
489
- <LogOut className="h-4 w-4" />
490
- </Button>
491
- </div>
492
- </div>
493
- </div>
494
- </aside>
495
-
496
- <div className="flex min-w-0 flex-1 flex-col transition-all duration-300 ease-in-out w-full min-h-0">
497
- <header className="bg-background dark:bg-slate-800/30 border-b border-border h-16 flex items-center gap-3 px-6 sticky top-0 z-20 w-full shrink-0">
498
- <Button variant="ghost" size="icon" className="md:hidden mr-3 -ml-2" onClick={() => setCmsSidebarOpen(!cmsSidebarOpen)}>
499
- <Menu className="h-5 w-5" />
500
- </Button>
501
- <h1 className="min-w-0 flex-1 truncate text-lg font-semibold text-foreground">
502
- {pageTitle}
503
- </h1>
504
- <Button asChild variant="outline" size="sm" className="shrink-0">
505
- <Link href="/" target="_blank">
506
- <ExternalLink className="h-4 w-4" />
507
- <span className="hidden sm:inline">View Site</span>
508
- </Link>
509
- </Button>
510
- </header>
511
- <main className="flex-1 min-h-0 w-full overflow-y-auto overscroll-contain px-6 pt-6 pb-20 scroll-pb-24 md:pb-24">
512
- {showTwoFactorReminder && <TwoFactorReminderBanner />}
513
- <SystemAlertsBanner alerts={systemAlerts} />
514
- {children}
515
- </main>
516
- </div>
517
- {cmsSidebarOpen && ! (typeof window !== 'undefined' && window.innerWidth >= 768) && (
518
- <div
519
- className="fixed inset-x-0 bottom-0 top-16 bg-black/30 z-20 md:hidden"
520
- onClick={() => setCmsSidebarOpen(false)}
521
- />
522
- )}
523
- {isAdmin && isCortexAiActive && <CortexGlobalAgentChat />}
524
- </div>
525
- </EcommerceActiveProvider>
526
- </CortexAiActiveProvider>
527
- </CortexAiPageContextProvider>
528
- )
529
- }
1
+ // app/cms/CmsClientLayout.tsx
2
+ "use client"
3
+
4
+ import React, { type ReactNode, useEffect } from "react"
5
+ import { useAuth } from "../../context/AuthContext"
6
+ import { useRouter, usePathname } from "next/navigation" // Import usePathname
7
+ import Link from "next/link"
8
+ import {
9
+ LayoutDashboard, FileText, PenTool, Users, Settings, ChevronRight, LogOut, Menu, ListTree, Image as ImageIconLucide, X, Languages as LanguagesIconLucide, MessageSquare,
10
+ Copyright as CopyrightIcon, ShoppingBag, ListOrdered, CreditCard, Package, Coins, MessageSquareText,
11
+ ExternalLink, Paintbrush, Brain, TicketPercent, ShieldAlert, Folder, DatabaseBackup, Boxes, Tag,
12
+ ShieldCheck, Code2, Cookie, LineChart, Mail, UserPlus, SlidersHorizontal,
13
+ } from "lucide-react"
14
+ import TwoFactorReminderBanner from "./components/TwoFactorReminderBanner"
15
+ import SystemAlertsBanner, { type SystemAlertItem } from "./components/SystemAlertsBanner"
16
+ import PaymentsReminderBanner from "./components/PaymentsReminderBanner"
17
+ import ContactReminderBanner from "./components/ContactReminderBanner"
18
+ import type { PaymentsReminder } from "../../lib/cms/payments-reminder"
19
+ import type { ContactReminder } from "../../lib/cms/contact-reminder"
20
+ import { Button } from "@nextblock-cms/ui"
21
+ import { Avatar, AvatarFallback, AvatarImage } from "@nextblock-cms/ui"
22
+ import { cn } from "@nextblock-cms/utils"
23
+ import { signOutAction } from "../actions"
24
+ import Image from "next/image";
25
+ import { FeedbackModal } from "./components/FeedbackModal";
26
+ import { CortexGlobalAgentChat } from "./components/CortexGlobalAgentChat";
27
+ import { CortexAiPageContextProvider } from "./components/CortexAiPageContext";
28
+ import { CortexAiActiveProvider } from "./components/CortexAiActiveContext";
29
+ import { EcommerceActiveProvider } from "./components/EcommerceActiveContext";
30
+ import { useAppBranding } from "../../components/AppShell";
31
+ import { resolveMediaUrl } from "../../lib/media/resolveMediaUrl";
32
+
33
+ const FALLBACK_LOGO_PATH = "/images/nextblock-logo-small.webp";
34
+
35
+ const LoadingSpinner = () => (
36
+ <div className="flex justify-center items-center h-full w-full py-20">
37
+ <div className="relative">
38
+ <div className="h-16 w-16 rounded-full border-t-4 border-b-4 border-primary animate-spin"></div>
39
+ <div className="absolute inset-0 flex items-center justify-center">
40
+ <div className="h-10 w-10 rounded-full bg-background"></div>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ );
45
+
46
+ type NavItemProps = {
47
+ href: string
48
+ icon: React.ElementType
49
+ children: React.ReactNode
50
+ isActive?: boolean
51
+ adminOnly?: boolean
52
+ writerOnly?: boolean
53
+ /** Unread/needs-attention count rendered as a pill. */
54
+ badgeCount?: number
55
+ isAdmin?: boolean
56
+ isWriter?: boolean
57
+ onClick?: () => void
58
+ }
59
+
60
+ const NavItem = ({ href, icon: Icon, children, isActive, adminOnly, writerOnly, isAdmin, isWriter, onClick, badgeCount = 0 }: NavItemProps) => {
61
+ if (adminOnly && !isAdmin) return null
62
+ if (writerOnly && !isWriter && !isAdmin) return null
63
+
64
+ return (
65
+ <li>
66
+ <Link
67
+ href={href}
68
+ onClick={onClick}
69
+ className={cn(
70
+ "flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium transition-all",
71
+ isActive
72
+ ? "bg-primary/10 text-primary dark:bg-primary/20"
73
+ : "text-slate-600 hover:text-primary hover:bg-primary/5 dark:text-slate-300 dark:hover:bg-primary/10",
74
+ )}
75
+ >
76
+ <Icon className="h-5 w-5" />
77
+ <span>{children}</span>
78
+ {/* The badge and the chevron share ml-auto, so the count wins when there is one. */}
79
+ {badgeCount > 0 ? (
80
+ <span className="ml-auto rounded-full bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-bold leading-none text-amber-700 dark:text-amber-400">
81
+ {badgeCount > 99 ? '99+' : badgeCount}
82
+ </span>
83
+ ) : (
84
+ isActive && <ChevronRight className="h-4 w-4 ml-auto" />
85
+ )}
86
+ </Link>
87
+ </li>
88
+ )
89
+ };
90
+
91
+ type CollapsibleNavItemProps = {
92
+ icon: React.ElementType
93
+ title: string
94
+ children: React.ReactNode
95
+ isActive?: boolean
96
+ adminOnly?: boolean
97
+ isAdmin?: boolean
98
+ }
99
+
100
+ const CollapsibleNavItem = ({ icon: Icon, title, children, isActive, adminOnly, isAdmin }: CollapsibleNavItemProps) => {
101
+ const [isOpen, setIsOpen] = React.useState(isActive);
102
+
103
+ if (adminOnly && !isAdmin) return null
104
+
105
+ return (
106
+ <li>
107
+ <button
108
+ onClick={() => setIsOpen(!isOpen)}
109
+ className={cn(
110
+ "flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium transition-all w-full",
111
+ isActive
112
+ ? "bg-primary/10 text-primary dark:bg-primary/20"
113
+ : "text-slate-600 hover:text-primary hover:bg-primary/5 dark:text-slate-300 dark:hover:bg-primary/10",
114
+ )}
115
+ >
116
+ <Icon className="h-5 w-5" />
117
+ <span>{title}</span>
118
+ <ChevronRight className={cn("h-4 w-4 ml-auto transition-transform", isOpen && "rotate-90")} />
119
+ </button>
120
+ {isOpen && (
121
+ <ul className="pl-6 space-y-1.5 mt-1.5">
122
+ {children}
123
+ </ul>
124
+ )}
125
+ </li>
126
+ )
127
+ };
128
+
129
+
130
+ export default function CmsClientLayout({
131
+ children,
132
+ isCortexAiActive = false,
133
+ isEcommerceActive = false,
134
+ showTwoFactorReminder = false,
135
+ systemAlerts = [],
136
+ paymentsReminder = null,
137
+ messagesUnread = 0,
138
+ contactReminder = null,
139
+ }: {
140
+ children: ReactNode,
141
+ isCortexAiActive?: boolean,
142
+ isEcommerceActive?: boolean,
143
+ showTwoFactorReminder?: boolean,
144
+ systemAlerts?: SystemAlertItem[],
145
+ paymentsReminder?: PaymentsReminder | null,
146
+ messagesUnread?: number,
147
+ contactReminder?: ContactReminder | null,
148
+ }) {
149
+ const isSandbox = process.env.NEXT_PUBLIC_IS_SANDBOX === 'true';
150
+ const { user, profile, role, isLoading, isAdmin, isWriter } = useAuth();
151
+ const { logo, siteTitle } = useAppBranding();
152
+ const router = useRouter();
153
+ const pathname = usePathname(); // Use the usePathname hook
154
+ const [cmsSidebarOpen, setCmsSidebarOpen] = React.useState(false);
155
+
156
+ useEffect(() => {
157
+ if (!isLoading) {
158
+ if (!user) {
159
+ router.push(`/sign-in?redirect=${encodeURIComponent(pathname || "/cms/dashboard")}`);
160
+ } else if (!isWriter && !isAdmin) {
161
+ router.push("/unauthorized?reason=insufficient_role_in_layout");
162
+ }
163
+ }
164
+ }, [user, role, isLoading, router, isAdmin, isWriter, pathname]);
165
+
166
+ useEffect(() => {
167
+ const mainLayoutElement = document.querySelector('body > div > main > div.flex-1.w-full.flex.flex-col.items-center');
168
+ if (mainLayoutElement) {
169
+ mainLayoutElement.classList.remove('max-w-7xl');
170
+ (mainLayoutElement as HTMLElement).style.padding = '0';
171
+ }
172
+ const mainScreenChild = document.querySelector('main.min-h-screen > div.flex-1.w-full');
173
+ if (mainScreenChild) {
174
+ mainScreenChild.classList.remove("max-w-7xl");
175
+ }
176
+
177
+ const handleResize = () => {
178
+ if (window.innerWidth >= 768) {
179
+ setCmsSidebarOpen(true);
180
+ } else {
181
+ // setCmsSidebarOpen(false); // Removed to allow manual toggle on mobile
182
+ }
183
+ };
184
+ handleResize();
185
+ window.addEventListener('resize', handleResize);
186
+ return () => window.removeEventListener('resize', handleResize);
187
+ }, []);
188
+
189
+ const closeSidebarOnMobile = () => {
190
+ if (window.innerWidth < 768) {
191
+ setCmsSidebarOpen(false);
192
+ }
193
+ };
194
+
195
+ const handleSignOut = async () => {
196
+ await signOutAction();
197
+ };
198
+
199
+
200
+ // With server-side auth data, isLoading is initially false.
201
+ // We show a spinner only if something client-side sets it to true (e.g., during logout).
202
+ if (isLoading) {
203
+ return <LoadingSpinner />;
204
+ }
205
+
206
+ // The useEffect handles redirection if the server-provided user/role is insufficient.
207
+ // Returning null here prevents rendering the layout for unauthorized users.
208
+ if (!user || (!isWriter && !isAdmin)) {
209
+ return null;
210
+ }
211
+
212
+ const getInitials = () => {
213
+ if (profile && profile.full_name) return profile.full_name.split(' ').map((n: string) => n[0]).join('').substring(0,2).toUpperCase();
214
+ if (user && user.email) return user.email.charAt(0).toUpperCase();
215
+ return "U"; // Default fallback
216
+ }
217
+ const getRoleColor = () => {
218
+ if (isAdmin) return "bg-amber-500";
219
+ if (isWriter) return "bg-emerald-500";
220
+ return "bg-sky-500"; // Default color
221
+ }
222
+ const cmsLogoSrc = resolveMediaUrl(logo?.media?.object_key) || FALLBACK_LOGO_PATH;
223
+ const cmsLogoAlt = logo?.media?.alt_text || siteTitle || "Nextblock";
224
+
225
+ // pageTitle logic should now work reliably with usePathname
226
+ let pageTitle = "CMS"; // Default title
227
+ if (pathname === "/cms/dashboard") pageTitle = "Dashboard";
228
+ else if (pathname.startsWith("/cms/custom-blocks/new")) pageTitle = "Create Custom Block";
229
+ else if (pathname.startsWith("/cms/custom-blocks/") && pathname.endsWith("/edit")) pageTitle = "Edit Custom Block";
230
+ else if (pathname.startsWith("/cms/custom-blocks")) pageTitle = "Block Management";
231
+ else if (pathname.startsWith("/cms/pages/new")) pageTitle = "New Page";
232
+ else if (pathname.startsWith("/cms/pages/") && pathname.endsWith("/edit")) pageTitle = "Edit Page";
233
+ else if (pathname.startsWith("/cms/pages")) pageTitle = "Pages";
234
+ else if (pathname.startsWith("/cms/posts/new")) pageTitle = "New Post";
235
+ else if (pathname.startsWith("/cms/posts/") && pathname.endsWith("/edit")) pageTitle = "Edit Post";
236
+ else if (pathname.startsWith("/cms/posts")) pageTitle = "Posts";
237
+ else if (pathname.startsWith("/cms/navigation/new")) pageTitle = "New Navigation Item";
238
+ else if (pathname.startsWith("/cms/navigation/") && pathname.includes("/edit")) pageTitle = "Edit Navigation Item";
239
+ else if (pathname.startsWith("/cms/navigation")) pageTitle = "Navigation";
240
+ else if (pathname.startsWith("/cms/media/") && pathname.endsWith("/edit")) pageTitle = "Edit Media Item";
241
+ else if (pathname.startsWith("/cms/media")) pageTitle = "Media Library";
242
+ else if (pathname.startsWith("/cms/users/") && pathname.endsWith("/edit")) pageTitle = "Edit User Profile";
243
+ else if (pathname.startsWith("/cms/users")) pageTitle = "User Management";
244
+ else if (pathname.startsWith("/cms/settings/languages/new")) pageTitle = "New Language";
245
+ else if (pathname.startsWith("/cms/settings/languages") && pathname.includes("/edit")) pageTitle = "Edit Language";
246
+ else if (pathname.startsWith("/cms/settings/languages")) pageTitle = "Language Settings";
247
+ // Fallback for general /cms/settings if no more specific language path matches
248
+ else if (pathname.startsWith("/cms/settings/logos")) pageTitle = "Branding";
249
+ else if (pathname.startsWith("/cms/settings/copyright")) pageTitle = "Copyright Settings";
250
+ else if (pathname.startsWith("/cms/settings/global-css")) pageTitle = "Themes & CSS";
251
+ else if (pathname.startsWith("/cms/settings/site-scripts")) pageTitle = "Site Scripts";
252
+ else if (pathname.startsWith("/cms/settings/extra-translations")) pageTitle = "Extra Translations";
253
+ else if (pathname.startsWith("/cms/settings/backup-restore")) pageTitle = "Backup And Restore";
254
+ else if (pathname.startsWith("/cms/settings/currencies")) pageTitle = "Currency Settings";
255
+ else if (pathname.startsWith("/cms/settings/taxes")) pageTitle = "Tax Settings";
256
+ else if (pathname.startsWith("/cms/settings/cortex-ai")) pageTitle = "Cortex AI";
257
+ else if (pathname.startsWith("/cms/settings/bot-protection")) pageTitle = "Bot Protection";
258
+ else if (pathname.startsWith("/cms/settings/email")) pageTitle = "Email";
259
+ else if (pathname.startsWith("/cms/settings/registration")) pageTitle = "Sign-ups & Registration";
260
+ else if (pathname.startsWith("/cms/settings/google-analytics")) pageTitle = "Google Analytics";
261
+ else if (pathname.startsWith("/cms/settings/privacy")) pageTitle = "Privacy & Consent";
262
+ else if (pathname.startsWith("/cms/settings/security")) pageTitle = "Security & 2FA";
263
+ else if (pathname.startsWith("/cms/payments")) pageTitle = "Payment Settings";
264
+
265
+ else if (pathname.startsWith("/cms/settings/packages")) pageTitle = "Packages";
266
+ else if (pathname.startsWith("/cms/settings")) pageTitle = "Settings";
267
+ else if (pathname.startsWith("/cms/interactions")) pageTitle = "Interactions";
268
+ else if (pathname.startsWith("/cms/products/inventory")) pageTitle = "Inventory";
269
+ else if (pathname.startsWith("/cms/coupons/") && pathname.endsWith("/edit")) pageTitle = "Edit Coupon";
270
+ else if (pathname.startsWith("/cms/coupons")) pageTitle = "Coupons";
271
+ else if (pathname.startsWith("/cms/products/new")) pageTitle = "New Product";
272
+ else if (pathname.startsWith("/cms/products/") && pathname.endsWith("/edit")) pageTitle = "Edit Product";
273
+ else if (pathname.startsWith("/cms/products")) pageTitle = "Products";
274
+ else if (pathname.startsWith("/cms/orders/") && pathname.endsWith("/edit")) pageTitle = "Edit Order";
275
+ else if (pathname.startsWith("/cms/orders")) pageTitle = "Orders";
276
+ else if (pathname.startsWith("/cms/messages")) pageTitle = "Messages";
277
+
278
+
279
+ return (
280
+ <CortexAiPageContextProvider>
281
+ <CortexAiActiveProvider isActive={isCortexAiActive}>
282
+ <EcommerceActiveProvider isActive={isEcommerceActive}>
283
+ <div className="relative flex h-full min-h-0 w-full overflow-hidden bg-slate-50 dark:bg-slate-950 md:flex-row">
284
+ <div className="fixed bottom-4 right-4 z-[60] md:hidden">
285
+ <Button
286
+ variant="outline"
287
+ size="icon"
288
+ onClick={() => setCmsSidebarOpen(!cmsSidebarOpen)}
289
+ className="bg-white shadow-lg dark:bg-slate-800 rounded-full h-12 w-12"
290
+ >
291
+ {cmsSidebarOpen ? <X className="h-5 w-5" /> : <Menu className="h-5 w-5" />}
292
+ </Button>
293
+ </div>
294
+
295
+ <aside
296
+ className={cn(
297
+ "fixed left-0 top-16 bottom-0 w-64 bg-white shadow-lg transition-transform duration-300 ease-in-out dark:bg-slate-900 dark:border-r dark:border-slate-700/60",
298
+ "md:sticky md:top-0 md:bottom-auto md:h-full md:translate-x-0",
299
+ cmsSidebarOpen ? "translate-x-0" : "-translate-x-full",
300
+ "z-30"
301
+ )}
302
+ >
303
+ <div className="flex h-full min-h-0 flex-col">
304
+ <div className="p-4 border-b dark:border-slate-700/60 h-16 flex items-center shrink-0">
305
+ <Link href="/cms/dashboard" className="flex items-center gap-2 px-2">
306
+ <Image
307
+ src={cmsLogoSrc}
308
+ alt={cmsLogoAlt}
309
+ width={logo?.media?.width || 32}
310
+ height={logo?.media?.height || 32}
311
+ className="h-8 w-auto"
312
+ priority
313
+ />
314
+ <h2 className="text-xl font-bold text-foreground">
315
+ Nextblock CMS
316
+ </h2>
317
+ </Link>
318
+ </div>
319
+
320
+ <nav className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-4">
321
+ <ul className="space-y-1.5">
322
+ <NavItem href="/cms/dashboard" icon={LayoutDashboard} isActive={pathname === "/cms/dashboard"} isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
323
+ Dashboard
324
+ </NavItem>
325
+ {isCortexAiActive && (
326
+ <NavItem href="/cms/settings/cortex-ai" icon={Brain} isActive={pathname.startsWith("/cms/settings/cortex-ai")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
327
+ Cortex AI
328
+ </NavItem>
329
+ )}
330
+ <NavItem href="/cms/pages" icon={FileText} isActive={pathname.startsWith("/cms/pages")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
331
+ Pages
332
+ </NavItem>
333
+ <NavItem href="/cms/posts" icon={PenTool} isActive={pathname.startsWith("/cms/posts")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
334
+ Posts
335
+ </NavItem>
336
+ <NavItem href="/cms/media" icon={ImageIconLucide} isActive={pathname.startsWith("/cms/media")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
337
+ Media
338
+ </NavItem>
339
+ <NavItem href="/cms/custom-blocks" icon={Boxes} isActive={pathname.startsWith("/cms/custom-blocks")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
340
+ Blocks
341
+ </NavItem>
342
+ <NavItem href="/cms/messages" icon={MessageSquareText} isActive={pathname.startsWith("/cms/messages")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile} badgeCount={messagesUnread}>
343
+ Messages
344
+ </NavItem>
345
+ <NavItem href="/cms/navigation" icon={ListTree} isActive={pathname.startsWith("/cms/navigation")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
346
+ Navigation
347
+ </NavItem>
348
+ {!isSandbox && (
349
+ <NavItem href="/cms/settings/security" icon={ShieldCheck} isActive={pathname.startsWith("/cms/settings/security")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
350
+ Security
351
+ </NavItem>
352
+ )}
353
+
354
+ {isEcommerceActive && (
355
+ <>
356
+ <div className="mt-6 mb-2">
357
+ <p className="px-3 text-xs font-semibold text-slate-500 uppercase tracking-wider dark:text-slate-400">
358
+ Store
359
+ </p>
360
+ </div>
361
+ <CollapsibleNavItem
362
+ icon={ShoppingBag}
363
+ title="Products"
364
+ isActive={pathname.startsWith("/cms/products")}
365
+ >
366
+ <NavItem href="/cms/products" icon={ShoppingBag} isActive={pathname === "/cms/products" || (pathname.startsWith("/cms/products/") && !pathname.startsWith("/cms/products/categories") && !pathname.startsWith("/cms/products/attributes") && !pathname.startsWith("/cms/products/inventory"))} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
367
+ All Products
368
+ </NavItem>
369
+ <NavItem href="/cms/products/categories" icon={Folder} isActive={pathname.startsWith("/cms/products/categories")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
370
+ Categories
371
+ </NavItem>
372
+ <NavItem href="/cms/products/inventory" icon={Package} isActive={pathname.startsWith("/cms/products/inventory")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
373
+ Inventory
374
+ </NavItem>
375
+ <NavItem href="/cms/products/attributes" icon={ListTree} isActive={pathname.startsWith("/cms/products/attributes")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
376
+ Attributes
377
+ </NavItem>
378
+ </CollapsibleNavItem>
379
+ <NavItem href="/cms/orders" icon={ListOrdered} isActive={pathname.startsWith("/cms/orders")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
380
+ Orders
381
+ </NavItem>
382
+
383
+ <NavItem href="/cms/coupons" icon={TicketPercent} isActive={pathname.startsWith("/cms/coupons")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
384
+ Coupons
385
+ </NavItem>
386
+ <NavItem href="/cms/promotions" icon={Tag} isActive={pathname.startsWith("/cms/promotions")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
387
+ Bulk Price & Sales
388
+ </NavItem>
389
+ <CollapsibleNavItem
390
+ icon={SlidersHorizontal}
391
+ title="Configuration"
392
+ isActive={
393
+ pathname.startsWith("/cms/payments") ||
394
+ pathname.startsWith("/cms/shipping") ||
395
+ pathname.startsWith("/cms/settings/taxes") ||
396
+ pathname.startsWith("/cms/settings/currencies")
397
+ }
398
+ adminOnly
399
+ isAdmin={isAdmin}
400
+ >
401
+ <NavItem href="/cms/payments" icon={CreditCard} isActive={pathname.startsWith("/cms/payments")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
402
+ Payments
403
+ </NavItem>
404
+ <NavItem href="/cms/shipping" icon={Package} isActive={pathname.startsWith("/cms/shipping")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
405
+ Shipping
406
+ </NavItem>
407
+ <NavItem href="/cms/settings/taxes" icon={Settings} isActive={pathname.startsWith("/cms/settings/taxes")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
408
+ Taxes
409
+ </NavItem>
410
+ <NavItem href="/cms/settings/currencies" icon={Coins} isActive={pathname.startsWith("/cms/settings/currencies")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
411
+ Currencies
412
+ </NavItem>
413
+ </CollapsibleNavItem>
414
+ </>
415
+ )}
416
+
417
+ {isAdmin && (
418
+ <>
419
+ <div className="mt-6 mb-2">
420
+ <p className="px-3 text-xs font-semibold text-slate-500 uppercase tracking-wider dark:text-slate-400">
421
+ Administration
422
+ </p>
423
+ </div>
424
+ <NavItem href="/cms/users" icon={Users} isActive={pathname.startsWith("/cms/users")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
425
+ Manage Users
426
+ </NavItem>
427
+ <NavItem href="/cms/settings/packages" icon={Package} isActive={pathname.startsWith("/cms/settings/packages")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
428
+ Packages
429
+ </NavItem>
430
+ <CollapsibleNavItem
431
+ icon={Settings}
432
+ title="Settings"
433
+ isActive={pathname.startsWith("/cms/settings") && !pathname.startsWith("/cms/settings/taxes") && !pathname.startsWith("/cms/settings/currencies") && !pathname.startsWith("/cms/settings/email") && !pathname.startsWith("/cms/settings/registration") && !pathname.startsWith("/cms/settings/bot-protection")}
434
+ adminOnly
435
+ isAdmin={isAdmin}
436
+ >
437
+ <NavItem href="/cms/settings/languages" icon={LanguagesIconLucide} isActive={pathname.startsWith("/cms/settings/languages")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
438
+ Languages
439
+ </NavItem>
440
+ <NavItem href="/cms/settings/logos" icon={ImageIconLucide} isActive={pathname.startsWith("/cms/settings/logos")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
441
+ Branding
442
+ </NavItem>
443
+ <NavItem href="/cms/settings/copyright" icon={CopyrightIcon} isActive={pathname.startsWith("/cms/settings/copyright")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
444
+ Copyright
445
+ </NavItem>
446
+ <NavItem href="/cms/settings/global-css" icon={Paintbrush} isActive={pathname.startsWith("/cms/settings/global-css")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
447
+ Themes &amp; CSS
448
+ </NavItem>
449
+ <NavItem href="/cms/settings/site-scripts" icon={Code2} isActive={pathname.startsWith("/cms/settings/site-scripts")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
450
+ Site Scripts
451
+ </NavItem>
452
+ <NavItem href="/cms/settings/privacy" icon={Cookie} isActive={pathname.startsWith("/cms/settings/privacy")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
453
+ Privacy &amp; Consent
454
+ </NavItem>
455
+ <NavItem href="/cms/settings/google-analytics" icon={LineChart} isActive={pathname.startsWith("/cms/settings/google-analytics")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
456
+ Google Analytics
457
+ </NavItem>
458
+ <NavItem href="/cms/settings/extra-translations" icon={MessageSquare} isActive={pathname.startsWith("/cms/settings/extra-translations")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
459
+ Extra Translations
460
+ </NavItem>
461
+ <NavItem href="/cms/settings/backup-restore" icon={DatabaseBackup} isActive={pathname.startsWith("/cms/settings/backup-restore")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
462
+ Backup / Restore
463
+ </NavItem>
464
+ </CollapsibleNavItem>
465
+ <CollapsibleNavItem
466
+ icon={SlidersHorizontal}
467
+ title="Configuration"
468
+ isActive={
469
+ pathname.startsWith("/cms/settings/email") ||
470
+ pathname.startsWith("/cms/settings/registration") ||
471
+ pathname.startsWith("/cms/settings/bot-protection")
472
+ }
473
+ adminOnly
474
+ isAdmin={isAdmin}
475
+ >
476
+ <NavItem href="/cms/settings/email" icon={Mail} isActive={pathname.startsWith("/cms/settings/email")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
477
+ Email
478
+ </NavItem>
479
+ <NavItem href="/cms/settings/bot-protection" icon={ShieldAlert} isActive={pathname.startsWith("/cms/settings/bot-protection")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
480
+ Bot Protection
481
+ </NavItem>
482
+ <NavItem href="/cms/settings/registration" icon={UserPlus} isActive={pathname.startsWith("/cms/settings/registration")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
483
+ Sign-ups
484
+ </NavItem>
485
+ </CollapsibleNavItem>
486
+ </>
487
+ )}
488
+ </ul>
489
+ </nav>
490
+
491
+
492
+ <div className="p-3 pb-0">
493
+ <FeedbackModal />
494
+ </div>
495
+
496
+ <div className="mt-auto p-3 border-t border-slate-200 dark:border-slate-700/60 shrink-0">
497
+ <div className="flex items-center gap-3">
498
+ <Avatar className="h-10 w-10 border">
499
+ <AvatarImage src={profile?.avatar_url || undefined} alt={profile?.full_name || user?.email} />
500
+ <AvatarFallback className="bg-primary/10 text-primary font-medium">{getInitials()}</AvatarFallback>
501
+ </Avatar>
502
+ <div className="flex-1 min-w-0">
503
+ <p className="text-sm font-medium truncate text-slate-700 dark:text-slate-200">{profile?.full_name || user?.email}</p>
504
+ <div className="flex items-center gap-1.5">
505
+ <div className={cn("h-2 w-2 rounded-full", getRoleColor())}></div>
506
+ <p className="text-xs text-slate-500 dark:text-slate-400 capitalize">{role}</p>
507
+ </div>
508
+ </div>
509
+ <Button onClick={handleSignOut} variant="ghost" size="icon" className="text-slate-500 hover:text-slate-700 dark:text-slate-400 dark:hover:text-slate-300" title="Sign Out">
510
+ <LogOut className="h-4 w-4" />
511
+ </Button>
512
+ </div>
513
+ </div>
514
+ </div>
515
+ </aside>
516
+
517
+ <div className="flex min-w-0 flex-1 flex-col transition-all duration-300 ease-in-out w-full min-h-0">
518
+ <header className="bg-background dark:bg-slate-800/30 border-b border-border h-16 flex items-center gap-3 px-6 sticky top-0 z-20 w-full shrink-0">
519
+ <Button variant="ghost" size="icon" className="md:hidden mr-3 -ml-2" onClick={() => setCmsSidebarOpen(!cmsSidebarOpen)}>
520
+ <Menu className="h-5 w-5" />
521
+ </Button>
522
+ <h1 className="min-w-0 flex-1 truncate text-lg font-semibold text-foreground">
523
+ {pageTitle}
524
+ </h1>
525
+ <Button asChild variant="outline" size="sm" className="shrink-0">
526
+ <Link href="/" target="_blank">
527
+ <ExternalLink className="h-4 w-4" />
528
+ <span className="hidden sm:inline">View Site</span>
529
+ </Link>
530
+ </Button>
531
+ </header>
532
+ <main className="flex-1 min-h-0 w-full overflow-y-auto overscroll-contain px-6 pt-6 pb-20 scroll-pb-24 md:pb-24">
533
+ {showTwoFactorReminder && <TwoFactorReminderBanner />}
534
+ {paymentsReminder && <PaymentsReminderBanner reminder={paymentsReminder} />}
535
+ {contactReminder && <ContactReminderBanner reminder={contactReminder} />}
536
+ <SystemAlertsBanner alerts={systemAlerts} />
537
+ {children}
538
+ </main>
539
+ </div>
540
+ {cmsSidebarOpen && ! (typeof window !== 'undefined' && window.innerWidth >= 768) && (
541
+ <div
542
+ className="fixed inset-x-0 bottom-0 top-16 bg-black/30 z-20 md:hidden"
543
+ onClick={() => setCmsSidebarOpen(false)}
544
+ />
545
+ )}
546
+ {isAdmin && isCortexAiActive && <CortexGlobalAgentChat />}
547
+ </div>
548
+ </EcommerceActiveProvider>
549
+ </CortexAiActiveProvider>
550
+ </CortexAiPageContextProvider>
551
+ )
552
+ }