create-nextblock 0.15.10 → 0.16.2

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 (266) hide show
  1. package/docker-template/.dockerignore +1 -1
  2. package/libs/db/tsconfig.lib.json +3 -3
  3. package/libs/editor/tsconfig.lib.json +3 -3
  4. package/libs/ui/tsconfig.lib.json +3 -3
  5. package/libs/utils/tsconfig.json +3 -3
  6. package/package.json +50 -50
  7. package/project.json +19 -19
  8. package/templates/nextblock-template/.dockerignore +1 -1
  9. package/templates/nextblock-template/.swcrc +30 -30
  10. package/templates/nextblock-template/AGENTS.md +9 -9
  11. package/templates/nextblock-template/CLAUDE.md +1 -1
  12. package/templates/nextblock-template/app/(auth-pages)/layout.tsx +9 -9
  13. package/templates/nextblock-template/app/(auth-pages)/post-sign-in/page.tsx +27 -27
  14. package/templates/nextblock-template/app/.well-known/ucp/route.ts +16 -16
  15. package/templates/nextblock-template/app/ToasterProvider.tsx +26 -26
  16. package/templates/nextblock-template/app/[slug]/pageClientActions.ts +7 -7
  17. package/templates/nextblock-template/app/actions/contactSellerActions.test.ts +280 -280
  18. package/templates/nextblock-template/app/actions/contactSellerActions.ts +222 -222
  19. package/templates/nextblock-template/app/actions/email-retry.test.ts +62 -62
  20. package/templates/nextblock-template/app/actions/email.ts +241 -241
  21. package/templates/nextblock-template/app/actions/formActions.ts +245 -245
  22. package/templates/nextblock-template/app/actions/interactions.ts +489 -489
  23. package/templates/nextblock-template/app/actions/threadActions.ts +166 -166
  24. package/templates/nextblock-template/app/actions/visibilityActions.ts +210 -210
  25. package/templates/nextblock-template/app/api/ai/seo/alt-text/route.ts +221 -0
  26. package/templates/nextblock-template/app/api/ai/seo/metadata/route.ts +186 -0
  27. package/templates/nextblock-template/app/api/checkout/freemius/sync/route.ts +29 -29
  28. package/templates/nextblock-template/app/api/checkout/route.ts +162 -162
  29. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +3092 -2900
  30. package/templates/nextblock-template/app/api/mcp/route.ts +415 -415
  31. package/templates/nextblock-template/app/api/media/record/route.ts +160 -160
  32. package/templates/nextblock-template/app/api/search/route.ts +43 -43
  33. package/templates/nextblock-template/app/api/view/route.ts +114 -114
  34. package/templates/nextblock-template/app/api/visual-editing/block-draft/route.ts +47 -47
  35. package/templates/nextblock-template/app/api/visual-editing/product-draft/route.ts +47 -47
  36. package/templates/nextblock-template/app/auth/callback/route.ts +31 -31
  37. package/templates/nextblock-template/app/cart/page.tsx +7 -7
  38. package/templates/nextblock-template/app/checkout/UcpCartHydrator.tsx +20 -20
  39. package/templates/nextblock-template/app/checkout/page.tsx +57 -57
  40. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +558 -552
  41. package/templates/nextblock-template/app/cms/blocks/components/BlockEditorArea.tsx +27 -0
  42. package/templates/nextblock-template/app/cms/blocks/components/BlockEditorModal.tsx +241 -241
  43. package/templates/nextblock-template/app/cms/blocks/components/MediaLibraryModal.tsx +149 -149
  44. package/templates/nextblock-template/app/cms/blocks/editors/FormBlockEditor.tsx +304 -304
  45. package/templates/nextblock-template/app/cms/blocks/editors/ImageBlockEditor.tsx +180 -3
  46. package/templates/nextblock-template/app/cms/blocks/editors/TextBlockEditor.tsx +171 -6
  47. package/templates/nextblock-template/app/cms/components/ContactReminderBanner.tsx +75 -75
  48. package/templates/nextblock-template/app/cms/components/CortexAiActiveContext.tsx +23 -23
  49. package/templates/nextblock-template/app/cms/components/CortexAiPageContext.tsx +58 -58
  50. package/templates/nextblock-template/app/cms/components/FeatureImageField.tsx +12 -3
  51. package/templates/nextblock-template/app/cms/components/FeedbackModal.tsx +36 -36
  52. package/templates/nextblock-template/app/cms/components/PaymentsReminderBanner.tsx +58 -58
  53. package/templates/nextblock-template/app/cms/components/VisibilityBadge.tsx +62 -62
  54. package/templates/nextblock-template/app/cms/components/VisibilityControl.tsx +542 -542
  55. package/templates/nextblock-template/app/cms/coupons/[id]/edit/page.tsx +16 -16
  56. package/templates/nextblock-template/app/cms/coupons/page.tsx +16 -16
  57. package/templates/nextblock-template/app/cms/dashboard/actions.ts +228 -228
  58. package/templates/nextblock-template/app/cms/dashboard/components/DashboardComponents.tsx +200 -200
  59. package/templates/nextblock-template/app/cms/inquiries/actions.ts +66 -66
  60. package/templates/nextblock-template/app/cms/inquiries/page.tsx +12 -12
  61. package/templates/nextblock-template/app/cms/interactions/page.tsx +12 -12
  62. package/templates/nextblock-template/app/cms/layout.tsx +101 -101
  63. package/templates/nextblock-template/app/cms/media/components/FolderNavigator.tsx +273 -273
  64. package/templates/nextblock-template/app/cms/media/components/FolderTree.tsx +122 -122
  65. package/templates/nextblock-template/app/cms/media/components/MediaEditForm.tsx +177 -2
  66. package/templates/nextblock-template/app/cms/media/components/MediaGridClient.tsx +69 -69
  67. package/templates/nextblock-template/app/cms/messages/MessagesClient.tsx +661 -661
  68. package/templates/nextblock-template/app/cms/messages/actions.ts +404 -404
  69. package/templates/nextblock-template/app/cms/messages/loadInbox.ts +333 -333
  70. package/templates/nextblock-template/app/cms/messages/page.tsx +87 -87
  71. package/templates/nextblock-template/app/cms/messages/require-admin.ts +37 -37
  72. package/templates/nextblock-template/app/cms/navigation/components/NavigationMenuDnd.tsx +3 -3
  73. package/templates/nextblock-template/app/cms/pages/[id]/edit/EditPageClient.tsx +28 -0
  74. package/templates/nextblock-template/app/cms/pages/components/PageForm.tsx +248 -5
  75. package/templates/nextblock-template/app/cms/posts/[id]/edit/page.tsx +33 -0
  76. package/templates/nextblock-template/app/cms/posts/components/PostForm.tsx +240 -5
  77. package/templates/nextblock-template/app/cms/products/[id]/edit/page.tsx +370 -370
  78. package/templates/nextblock-template/app/cms/products/attributes/page.tsx +12 -12
  79. package/templates/nextblock-template/app/cms/products/inventory/page.tsx +13 -13
  80. package/templates/nextblock-template/app/cms/products/productFormData.ts +133 -133
  81. package/templates/nextblock-template/app/cms/products/settings/page.tsx +5 -5
  82. package/templates/nextblock-template/app/cms/revisions/actions.ts +332 -332
  83. package/templates/nextblock-template/app/cms/revisions/service.test.ts +498 -498
  84. package/templates/nextblock-template/app/cms/revisions/service.ts +569 -569
  85. package/templates/nextblock-template/app/cms/revisions/utils.ts +304 -304
  86. package/templates/nextblock-template/app/cms/settings/cortex-ai/CortexAiSettingsClient.tsx +948 -948
  87. package/templates/nextblock-template/app/cms/settings/cortex-ai/McpServerSettingsCard.tsx +628 -628
  88. package/templates/nextblock-template/app/cms/settings/cortex-ai/mcp-actions.ts +230 -230
  89. package/templates/nextblock-template/app/cms/settings/cortex-ai/require-admin.ts +34 -34
  90. package/templates/nextblock-template/app/cms/settings/currencies/actions.ts +331 -331
  91. package/templates/nextblock-template/app/cms/settings/currencies/page.tsx +494 -494
  92. package/templates/nextblock-template/app/cms/settings/email/components/EmailForm.tsx +227 -227
  93. package/templates/nextblock-template/app/cms/settings/extra-translations/ExtraTranslationsWorkspace.tsx +767 -767
  94. package/templates/nextblock-template/app/cms/settings/extra-translations/actions.ts +276 -276
  95. package/templates/nextblock-template/app/cms/settings/extra-translations/page.tsx +93 -93
  96. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeEditor.tsx +382 -382
  97. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeManager.tsx +267 -267
  98. package/templates/nextblock-template/app/cms/settings/global-css/page.tsx +40 -40
  99. package/templates/nextblock-template/app/cms/settings/global-css/theme-actions.ts +259 -259
  100. package/templates/nextblock-template/app/cms/settings/logos/[id]/edit/page.tsx +7 -7
  101. package/templates/nextblock-template/app/cms/settings/logos/components/BrandingSettingsForm.tsx +339 -339
  102. package/templates/nextblock-template/app/cms/settings/logos/new/page.tsx +8 -8
  103. package/templates/nextblock-template/app/cms/settings/seo/RedirectsCard.tsx +514 -0
  104. package/templates/nextblock-template/app/cms/settings/seo/RobotsCard.tsx +529 -0
  105. package/templates/nextblock-template/app/cms/settings/seo/SeoSettingsClient.tsx +57 -0
  106. package/templates/nextblock-template/app/cms/settings/seo/actions.ts +448 -0
  107. package/templates/nextblock-template/app/cms/settings/seo/mappers.ts +93 -0
  108. package/templates/nextblock-template/app/cms/settings/seo/page.tsx +46 -0
  109. package/templates/nextblock-template/app/cms/settings/seo/require-admin.ts +47 -0
  110. package/templates/nextblock-template/app/cms/settings/site-scripts/page.tsx +51 -51
  111. package/templates/nextblock-template/app/cms/settings/taxes/page.tsx +21 -21
  112. package/templates/nextblock-template/app/cms/shipping/page.tsx +20 -20
  113. package/templates/nextblock-template/app/cms/users/components/DeleteUserButton.tsx +12 -12
  114. package/templates/nextblock-template/app/layout.tsx +671 -671
  115. package/templates/nextblock-template/app/lib/seo.ts +319 -319
  116. package/templates/nextblock-template/app/lib/ucp/protocol.ts +190 -190
  117. package/templates/nextblock-template/app/lib/ucp/server.test.ts +56 -56
  118. package/templates/nextblock-template/app/product/[slug]/page.tsx +502 -502
  119. package/templates/nextblock-template/app/profile/ProfilePageHeader.tsx +16 -16
  120. package/templates/nextblock-template/app/profile/ProfilePageMissingState.tsx +9 -9
  121. package/templates/nextblock-template/app/profile/account-links.ts +22 -22
  122. package/templates/nextblock-template/app/profile/orders/CustomerOrdersPageClient.tsx +124 -124
  123. package/templates/nextblock-template/app/profile/orders/page.tsx +19 -19
  124. package/templates/nextblock-template/app/profile/password/PasswordSettingsPageClient.tsx +128 -128
  125. package/templates/nextblock-template/app/profile/password/actions.ts +59 -59
  126. package/templates/nextblock-template/app/profile/password/page.tsx +27 -27
  127. package/templates/nextblock-template/app/providers.tsx +96 -96
  128. package/templates/nextblock-template/app/robots.ts +123 -0
  129. package/templates/nextblock-template/app/sitemap.ts +1 -1
  130. package/templates/nextblock-template/app/thread/ThreadView.tsx +164 -164
  131. package/templates/nextblock-template/app/thread/[token]/route.ts +57 -57
  132. package/templates/nextblock-template/app/thread/layout.tsx +15 -15
  133. package/templates/nextblock-template/app/thread/page.tsx +98 -98
  134. package/templates/nextblock-template/app/ucp/v1/carts/[id]/cancel/route.ts +38 -38
  135. package/templates/nextblock-template/app/ucp/v1/carts/[id]/route.ts +68 -68
  136. package/templates/nextblock-template/app/ucp/v1/carts/route.ts +35 -35
  137. package/templates/nextblock-template/app/ucp/v1/catalog/lookup/route.ts +35 -35
  138. package/templates/nextblock-template/app/ucp/v1/catalog/product/route.ts +35 -35
  139. package/templates/nextblock-template/app/ucp/v1/catalog/search/route.ts +34 -34
  140. package/templates/nextblock-template/components/BlockRenderer.tsx +312 -312
  141. package/templates/nextblock-template/components/CartDrawerLoader.tsx +7 -7
  142. package/templates/nextblock-template/components/CartTranslator.tsx +210 -210
  143. package/templates/nextblock-template/components/ContactSellerSection.tsx +188 -188
  144. package/templates/nextblock-template/components/DeferredCartDrawer.tsx +23 -23
  145. package/templates/nextblock-template/components/DeferredCartTranslator.tsx +51 -51
  146. package/templates/nextblock-template/components/DeferredGlobalSearch.tsx +68 -68
  147. package/templates/nextblock-template/components/DeferredGoogleTagManager.tsx +70 -70
  148. package/templates/nextblock-template/components/DeferredSpeedInsights.tsx +69 -69
  149. package/templates/nextblock-template/components/FooterNavigation.tsx +32 -32
  150. package/templates/nextblock-template/components/GlobalSearch.tsx +557 -557
  151. package/templates/nextblock-template/components/Header.tsx +38 -38
  152. package/templates/nextblock-template/components/HtmlScriptExecutor.tsx +47 -47
  153. package/templates/nextblock-template/components/LanguageSwitcher.tsx +2 -2
  154. package/templates/nextblock-template/components/PostCommentsSection.tsx +378 -378
  155. package/templates/nextblock-template/components/ProductReviewsSection.tsx +426 -426
  156. package/templates/nextblock-template/components/SiteScripts.tsx +56 -56
  157. package/templates/nextblock-template/components/StaffReplies.tsx +102 -102
  158. package/templates/nextblock-template/components/blocks/PostCardSkeleton.tsx +12 -12
  159. package/templates/nextblock-template/components/blocks/PostsGridBlock.tsx +12 -12
  160. package/templates/nextblock-template/components/blocks/PostsGridClient.tsx +48 -48
  161. package/templates/nextblock-template/components/blocks/TestimonialBlock.tsx +9 -9
  162. package/templates/nextblock-template/components/blocks/ecommerceRendererLoaders.ts +23 -23
  163. package/templates/nextblock-template/components/blocks/publicRendererLoaders.ts +25 -25
  164. package/templates/nextblock-template/components/blocks/renderers/ButtonBlockRenderer.tsx +92 -92
  165. package/templates/nextblock-template/components/blocks/renderers/CartBlockRenderer.tsx +18 -18
  166. package/templates/nextblock-template/components/blocks/renderers/CheckoutBlockRenderer.tsx +20 -20
  167. package/templates/nextblock-template/components/blocks/renderers/FeaturedProductBlockRenderer.tsx +25 -25
  168. package/templates/nextblock-template/components/blocks/renderers/FormBlockRenderer.tsx +385 -385
  169. package/templates/nextblock-template/components/blocks/renderers/PostsGridBlockRenderer.tsx +24 -24
  170. package/templates/nextblock-template/components/blocks/renderers/ProductDetailsBlockRenderer.tsx +157 -157
  171. package/templates/nextblock-template/components/blocks/renderers/ProductGridBlockRenderer.tsx +34 -34
  172. package/templates/nextblock-template/components/blocks/renderers/SectionBlockRenderer.tsx +612 -612
  173. package/templates/nextblock-template/components/blocks/renderers/TestimonialBlockRenderer.tsx +57 -57
  174. package/templates/nextblock-template/components/blocks/renderers/inline/AlertWidgetRenderer.tsx +2 -2
  175. package/templates/nextblock-template/components/blocks/renderers/inline/CtaWidgetRenderer.tsx +2 -2
  176. package/templates/nextblock-template/components/blocks/types.ts +7 -7
  177. package/templates/nextblock-template/components/commerce/PaymentReadinessBoundary.tsx +32 -32
  178. package/templates/nextblock-template/components/env-var-warning.tsx +3 -3
  179. package/templates/nextblock-template/components/form-message.tsx +32 -32
  180. package/templates/nextblock-template/components/seo/GenerateMetaButton.tsx +137 -0
  181. package/templates/nextblock-template/components/seo/PageSeoAuditSection.tsx +244 -0
  182. package/templates/nextblock-template/components/seo/SeoAuditPanel.tsx +749 -0
  183. package/templates/nextblock-template/components/seo/SeoIssueList.tsx +195 -0
  184. package/templates/nextblock-template/components/seo/SeoScoreDial.tsx +144 -0
  185. package/templates/nextblock-template/components/seo/SocialPreview.tsx +243 -0
  186. package/templates/nextblock-template/components/seo/SocialPreviewDialog.tsx +110 -0
  187. package/templates/nextblock-template/components/submit-button.tsx +23 -23
  188. package/templates/nextblock-template/components/theme-icon.tsx +78 -78
  189. package/templates/nextblock-template/components/theme-switcher.tsx +85 -85
  190. package/templates/nextblock-template/context/AuthContext.tsx +23 -23
  191. package/templates/nextblock-template/context/ThemeCatalogContext.tsx +44 -44
  192. package/templates/nextblock-template/docs/01-PROJECT-OVERVIEW.md +94 -94
  193. package/templates/nextblock-template/docs/03-CMS-AND-EDITOR.md +77 -77
  194. package/templates/nextblock-template/docs/13-STAYING-UP-TO-DATE.md +372 -372
  195. package/templates/nextblock-template/docs/14-MESSAGES-INBOX.md +309 -309
  196. package/templates/nextblock-template/docs/README.md +42 -42
  197. package/templates/nextblock-template/docs/TECHNICAL_SPECIFICATION.md +12506 -12506
  198. package/templates/nextblock-template/hooks/use-hotkeys.ts +21 -21
  199. package/templates/nextblock-template/hooks/useGlobalSearch.ts +101 -101
  200. package/templates/nextblock-template/index.d.ts +7 -7
  201. package/templates/nextblock-template/lib/auth-redirects.ts +46 -46
  202. package/templates/nextblock-template/lib/blocks/blockColors.test.ts +134 -134
  203. package/templates/nextblock-template/lib/blocks/blockColors.ts +175 -175
  204. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +761 -761
  205. package/templates/nextblock-template/lib/blocks/inlineScriptNonce.ts +20 -20
  206. package/templates/nextblock-template/lib/cms/contact-reminder.ts +64 -64
  207. package/templates/nextblock-template/lib/cms/payments-reminder.test.ts +135 -0
  208. package/templates/nextblock-template/lib/cms/payments-reminder.ts +30 -23
  209. package/templates/nextblock-template/lib/cms/unread-messages.ts +42 -42
  210. package/templates/nextblock-template/lib/commerce/seller-contact.ts +162 -162
  211. package/templates/nextblock-template/lib/config/email-settings.ts +323 -323
  212. package/templates/nextblock-template/lib/config/email-tls.test.ts +57 -57
  213. package/templates/nextblock-template/lib/cortex-ai/alt-text-request.ts +86 -0
  214. package/templates/nextblock-template/lib/cortex-ai/sandbox-headers.ts +60 -0
  215. package/templates/nextblock-template/lib/email/placeholder-address.test.ts +59 -59
  216. package/templates/nextblock-template/lib/email/placeholder-address.ts +39 -39
  217. package/templates/nextblock-template/lib/messages/thread-reference.test.ts +70 -70
  218. package/templates/nextblock-template/lib/messages/thread-token.test.ts +93 -93
  219. package/templates/nextblock-template/lib/messages/thread-token.ts +157 -157
  220. package/templates/nextblock-template/lib/messages/threads.ts +579 -579
  221. package/templates/nextblock-template/lib/posts/readTime.ts +60 -60
  222. package/templates/nextblock-template/lib/publishing/viewUrl.ts +26 -26
  223. package/templates/nextblock-template/lib/search/types.ts +27 -27
  224. package/templates/nextblock-template/lib/seo/alt-text-write-back.test.ts +154 -0
  225. package/templates/nextblock-template/lib/seo/alt-text-write-back.ts +109 -0
  226. package/templates/nextblock-template/lib/seo/block-content.ts +123 -0
  227. package/templates/nextblock-template/lib/seo/fix-prompts.test.ts +242 -0
  228. package/templates/nextblock-template/lib/seo/fix-prompts.ts +204 -0
  229. package/templates/nextblock-template/lib/seo/page-audit-context.tsx +140 -0
  230. package/templates/nextblock-template/lib/seo/page-document.test.ts +350 -0
  231. package/templates/nextblock-template/lib/seo/page-document.ts +412 -0
  232. package/templates/nextblock-template/lib/seo/redirect-store.test.ts +479 -0
  233. package/templates/nextblock-template/lib/seo/redirect-store.ts +466 -0
  234. package/templates/nextblock-template/lib/seo/robots-settings-signature.test.ts +102 -0
  235. package/templates/nextblock-template/lib/seo/robots-settings-signature.ts +41 -0
  236. package/templates/nextblock-template/lib/seo/robots-txt.test.ts +370 -0
  237. package/templates/nextblock-template/lib/seo/robots-txt.ts +510 -0
  238. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +177 -167
  239. package/templates/nextblock-template/lib/site-scripts/revisions.ts +71 -71
  240. package/templates/nextblock-template/lib/site-scripts/types.ts +46 -46
  241. package/templates/nextblock-template/lib/site-url.test.ts +89 -89
  242. package/templates/nextblock-template/lib/site-url.ts +102 -102
  243. package/templates/nextblock-template/lib/themes/buildThemeCss.ts +124 -124
  244. package/templates/nextblock-template/lib/themes/tokenColor.ts +31 -31
  245. package/templates/nextblock-template/lib/themes/tokens.ts +143 -143
  246. package/templates/nextblock-template/lib/visual-editing/draft-content.test.ts +105 -105
  247. package/templates/nextblock-template/lib/visual-editing/draft-route.test.ts +42 -42
  248. package/templates/nextblock-template/lib/visual-editing/edit-info.test.ts +143 -143
  249. package/templates/nextblock-template/lib/visual-editing/edit-info.ts +94 -94
  250. package/templates/nextblock-template/lib/visual-editing/product-drafts.test.ts +81 -81
  251. package/templates/nextblock-template/lib/zod-config.ts +5 -5
  252. package/templates/nextblock-template/next-env.d.ts +0 -1
  253. package/templates/nextblock-template/package.json +1 -1
  254. package/templates/nextblock-template/postcss.config.js +6 -6
  255. package/templates/nextblock-template/proxy.ts +240 -20
  256. package/templates/nextblock-template/scripts/backup.js +115 -115
  257. package/templates/nextblock-template/scripts/restore.js +385 -385
  258. package/templates/nextblock-template/scripts/validate-editor-block-schema.ts +112 -112
  259. package/templates/nextblock-template/tailwind.config.js +25 -25
  260. package/templates/nextblock-template/tools/build-migrate.mjs +102 -102
  261. package/templates/nextblock-template/tools/configure-supabase-auth.js +282 -282
  262. package/templates/nextblock-template/tools/deploy-supabase.js +159 -159
  263. package/templates/nextblock-template/tools/lib/migrate-core.mjs +569 -569
  264. package/templates/nextblock-template/tools/update.mjs +1303 -1303
  265. package/tsconfig.base.json +3 -3
  266. package/templates/nextblock-template/app/robots.txt/route.ts +0 -32
@@ -1,552 +1,558 @@
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
- }
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, Search,
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
+ // Must stay ABOVE the generic "/cms/settings" arm below: this chain is
253
+ // first-match-wins, so anything placed after that fallback is dead code.
254
+ else if (pathname.startsWith("/cms/settings/seo")) pageTitle = "SEO & Redirects";
255
+ else if (pathname.startsWith("/cms/settings/extra-translations")) pageTitle = "Extra Translations";
256
+ else if (pathname.startsWith("/cms/settings/backup-restore")) pageTitle = "Backup And Restore";
257
+ else if (pathname.startsWith("/cms/settings/currencies")) pageTitle = "Currency Settings";
258
+ else if (pathname.startsWith("/cms/settings/taxes")) pageTitle = "Tax Settings";
259
+ else if (pathname.startsWith("/cms/settings/cortex-ai")) pageTitle = "Cortex AI";
260
+ else if (pathname.startsWith("/cms/settings/bot-protection")) pageTitle = "Bot Protection";
261
+ else if (pathname.startsWith("/cms/settings/email")) pageTitle = "Email";
262
+ else if (pathname.startsWith("/cms/settings/registration")) pageTitle = "Sign-ups & Registration";
263
+ else if (pathname.startsWith("/cms/settings/google-analytics")) pageTitle = "Google Analytics";
264
+ else if (pathname.startsWith("/cms/settings/privacy")) pageTitle = "Privacy & Consent";
265
+ else if (pathname.startsWith("/cms/settings/security")) pageTitle = "Security & 2FA";
266
+ else if (pathname.startsWith("/cms/payments")) pageTitle = "Payment Settings";
267
+
268
+ else if (pathname.startsWith("/cms/settings/packages")) pageTitle = "Packages";
269
+ else if (pathname.startsWith("/cms/settings")) pageTitle = "Settings";
270
+ else if (pathname.startsWith("/cms/interactions")) pageTitle = "Interactions";
271
+ else if (pathname.startsWith("/cms/products/inventory")) pageTitle = "Inventory";
272
+ else if (pathname.startsWith("/cms/coupons/") && pathname.endsWith("/edit")) pageTitle = "Edit Coupon";
273
+ else if (pathname.startsWith("/cms/coupons")) pageTitle = "Coupons";
274
+ else if (pathname.startsWith("/cms/products/new")) pageTitle = "New Product";
275
+ else if (pathname.startsWith("/cms/products/") && pathname.endsWith("/edit")) pageTitle = "Edit Product";
276
+ else if (pathname.startsWith("/cms/products")) pageTitle = "Products";
277
+ else if (pathname.startsWith("/cms/orders/") && pathname.endsWith("/edit")) pageTitle = "Edit Order";
278
+ else if (pathname.startsWith("/cms/orders")) pageTitle = "Orders";
279
+ else if (pathname.startsWith("/cms/messages")) pageTitle = "Messages";
280
+
281
+
282
+ return (
283
+ <CortexAiPageContextProvider>
284
+ <CortexAiActiveProvider isActive={isCortexAiActive}>
285
+ <EcommerceActiveProvider isActive={isEcommerceActive}>
286
+ <div className="relative flex h-full min-h-0 w-full overflow-hidden bg-slate-50 dark:bg-slate-950 md:flex-row">
287
+ <div className="fixed bottom-4 right-4 z-[60] md:hidden">
288
+ <Button
289
+ variant="outline"
290
+ size="icon"
291
+ onClick={() => setCmsSidebarOpen(!cmsSidebarOpen)}
292
+ className="bg-white shadow-lg dark:bg-slate-800 rounded-full h-12 w-12"
293
+ >
294
+ {cmsSidebarOpen ? <X className="h-5 w-5" /> : <Menu className="h-5 w-5" />}
295
+ </Button>
296
+ </div>
297
+
298
+ <aside
299
+ className={cn(
300
+ "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",
301
+ "md:sticky md:top-0 md:bottom-auto md:h-full md:translate-x-0",
302
+ cmsSidebarOpen ? "translate-x-0" : "-translate-x-full",
303
+ "z-30"
304
+ )}
305
+ >
306
+ <div className="flex h-full min-h-0 flex-col">
307
+ <div className="p-4 border-b dark:border-slate-700/60 h-16 flex items-center shrink-0">
308
+ <Link href="/cms/dashboard" className="flex items-center gap-2 px-2">
309
+ <Image
310
+ src={cmsLogoSrc}
311
+ alt={cmsLogoAlt}
312
+ width={logo?.media?.width || 32}
313
+ height={logo?.media?.height || 32}
314
+ className="h-8 w-auto"
315
+ priority
316
+ />
317
+ <h2 className="text-xl font-bold text-foreground">
318
+ Nextblock CMS
319
+ </h2>
320
+ </Link>
321
+ </div>
322
+
323
+ <nav className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-4">
324
+ <ul className="space-y-1.5">
325
+ <NavItem href="/cms/dashboard" icon={LayoutDashboard} isActive={pathname === "/cms/dashboard"} isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
326
+ Dashboard
327
+ </NavItem>
328
+ {isCortexAiActive && (
329
+ <NavItem href="/cms/settings/cortex-ai" icon={Brain} isActive={pathname.startsWith("/cms/settings/cortex-ai")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
330
+ Cortex AI
331
+ </NavItem>
332
+ )}
333
+ <NavItem href="/cms/pages" icon={FileText} isActive={pathname.startsWith("/cms/pages")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
334
+ Pages
335
+ </NavItem>
336
+ <NavItem href="/cms/posts" icon={PenTool} isActive={pathname.startsWith("/cms/posts")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
337
+ Posts
338
+ </NavItem>
339
+ <NavItem href="/cms/media" icon={ImageIconLucide} isActive={pathname.startsWith("/cms/media")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
340
+ Media
341
+ </NavItem>
342
+ <NavItem href="/cms/custom-blocks" icon={Boxes} isActive={pathname.startsWith("/cms/custom-blocks")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
343
+ Blocks
344
+ </NavItem>
345
+ <NavItem href="/cms/messages" icon={MessageSquareText} isActive={pathname.startsWith("/cms/messages")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile} badgeCount={messagesUnread}>
346
+ Messages
347
+ </NavItem>
348
+ <NavItem href="/cms/navigation" icon={ListTree} isActive={pathname.startsWith("/cms/navigation")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
349
+ Navigation
350
+ </NavItem>
351
+ {!isSandbox && (
352
+ <NavItem href="/cms/settings/security" icon={ShieldCheck} isActive={pathname.startsWith("/cms/settings/security")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
353
+ Security
354
+ </NavItem>
355
+ )}
356
+
357
+ {isEcommerceActive && (
358
+ <>
359
+ <div className="mt-6 mb-2">
360
+ <p className="px-3 text-xs font-semibold text-slate-500 uppercase tracking-wider dark:text-slate-400">
361
+ Store
362
+ </p>
363
+ </div>
364
+ <CollapsibleNavItem
365
+ icon={ShoppingBag}
366
+ title="Products"
367
+ isActive={pathname.startsWith("/cms/products")}
368
+ >
369
+ <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}>
370
+ All Products
371
+ </NavItem>
372
+ <NavItem href="/cms/products/categories" icon={Folder} isActive={pathname.startsWith("/cms/products/categories")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
373
+ Categories
374
+ </NavItem>
375
+ <NavItem href="/cms/products/inventory" icon={Package} isActive={pathname.startsWith("/cms/products/inventory")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
376
+ Inventory
377
+ </NavItem>
378
+ <NavItem href="/cms/products/attributes" icon={ListTree} isActive={pathname.startsWith("/cms/products/attributes")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
379
+ Attributes
380
+ </NavItem>
381
+ </CollapsibleNavItem>
382
+ <NavItem href="/cms/orders" icon={ListOrdered} isActive={pathname.startsWith("/cms/orders")} writerOnly isAdmin={isAdmin} isWriter={isWriter} onClick={closeSidebarOnMobile}>
383
+ Orders
384
+ </NavItem>
385
+
386
+ <NavItem href="/cms/coupons" icon={TicketPercent} isActive={pathname.startsWith("/cms/coupons")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
387
+ Coupons
388
+ </NavItem>
389
+ <NavItem href="/cms/promotions" icon={Tag} isActive={pathname.startsWith("/cms/promotions")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
390
+ Bulk Price & Sales
391
+ </NavItem>
392
+ <CollapsibleNavItem
393
+ icon={SlidersHorizontal}
394
+ title="Configuration"
395
+ isActive={
396
+ pathname.startsWith("/cms/payments") ||
397
+ pathname.startsWith("/cms/shipping") ||
398
+ pathname.startsWith("/cms/settings/taxes") ||
399
+ pathname.startsWith("/cms/settings/currencies")
400
+ }
401
+ adminOnly
402
+ isAdmin={isAdmin}
403
+ >
404
+ <NavItem href="/cms/payments" icon={CreditCard} isActive={pathname.startsWith("/cms/payments")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
405
+ Payments
406
+ </NavItem>
407
+ <NavItem href="/cms/shipping" icon={Package} isActive={pathname.startsWith("/cms/shipping")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
408
+ Shipping
409
+ </NavItem>
410
+ <NavItem href="/cms/settings/taxes" icon={Settings} isActive={pathname.startsWith("/cms/settings/taxes")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
411
+ Taxes
412
+ </NavItem>
413
+ <NavItem href="/cms/settings/currencies" icon={Coins} isActive={pathname.startsWith("/cms/settings/currencies")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
414
+ Currencies
415
+ </NavItem>
416
+ </CollapsibleNavItem>
417
+ </>
418
+ )}
419
+
420
+ {isAdmin && (
421
+ <>
422
+ <div className="mt-6 mb-2">
423
+ <p className="px-3 text-xs font-semibold text-slate-500 uppercase tracking-wider dark:text-slate-400">
424
+ Administration
425
+ </p>
426
+ </div>
427
+ <NavItem href="/cms/users" icon={Users} isActive={pathname.startsWith("/cms/users")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
428
+ Manage Users
429
+ </NavItem>
430
+ <NavItem href="/cms/settings/packages" icon={Package} isActive={pathname.startsWith("/cms/settings/packages")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
431
+ Packages
432
+ </NavItem>
433
+ <CollapsibleNavItem
434
+ icon={Settings}
435
+ title="Settings"
436
+ 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")}
437
+ adminOnly
438
+ isAdmin={isAdmin}
439
+ >
440
+ <NavItem href="/cms/settings/languages" icon={LanguagesIconLucide} isActive={pathname.startsWith("/cms/settings/languages")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
441
+ Languages
442
+ </NavItem>
443
+ <NavItem href="/cms/settings/logos" icon={ImageIconLucide} isActive={pathname.startsWith("/cms/settings/logos")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
444
+ Branding
445
+ </NavItem>
446
+ <NavItem href="/cms/settings/copyright" icon={CopyrightIcon} isActive={pathname.startsWith("/cms/settings/copyright")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
447
+ Copyright
448
+ </NavItem>
449
+ <NavItem href="/cms/settings/global-css" icon={Paintbrush} isActive={pathname.startsWith("/cms/settings/global-css")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
450
+ Themes &amp; CSS
451
+ </NavItem>
452
+ <NavItem href="/cms/settings/site-scripts" icon={Code2} isActive={pathname.startsWith("/cms/settings/site-scripts")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
453
+ Site Scripts
454
+ </NavItem>
455
+ <NavItem href="/cms/settings/privacy" icon={Cookie} isActive={pathname.startsWith("/cms/settings/privacy")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
456
+ Privacy &amp; Consent
457
+ </NavItem>
458
+ <NavItem href="/cms/settings/google-analytics" icon={LineChart} isActive={pathname.startsWith("/cms/settings/google-analytics")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
459
+ Google Analytics
460
+ </NavItem>
461
+ <NavItem href="/cms/settings/seo" icon={Search} isActive={pathname.startsWith("/cms/settings/seo")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
462
+ SEO &amp; Redirects
463
+ </NavItem>
464
+ <NavItem href="/cms/settings/extra-translations" icon={MessageSquare} isActive={pathname.startsWith("/cms/settings/extra-translations")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
465
+ Extra Translations
466
+ </NavItem>
467
+ <NavItem href="/cms/settings/backup-restore" icon={DatabaseBackup} isActive={pathname.startsWith("/cms/settings/backup-restore")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
468
+ Backup / Restore
469
+ </NavItem>
470
+ </CollapsibleNavItem>
471
+ <CollapsibleNavItem
472
+ icon={SlidersHorizontal}
473
+ title="Configuration"
474
+ isActive={
475
+ pathname.startsWith("/cms/settings/email") ||
476
+ pathname.startsWith("/cms/settings/registration") ||
477
+ pathname.startsWith("/cms/settings/bot-protection")
478
+ }
479
+ adminOnly
480
+ isAdmin={isAdmin}
481
+ >
482
+ <NavItem href="/cms/settings/email" icon={Mail} isActive={pathname.startsWith("/cms/settings/email")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
483
+ Email
484
+ </NavItem>
485
+ <NavItem href="/cms/settings/bot-protection" icon={ShieldAlert} isActive={pathname.startsWith("/cms/settings/bot-protection")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
486
+ Bot Protection
487
+ </NavItem>
488
+ <NavItem href="/cms/settings/registration" icon={UserPlus} isActive={pathname.startsWith("/cms/settings/registration")} adminOnly isAdmin={isAdmin} onClick={closeSidebarOnMobile}>
489
+ Sign-ups
490
+ </NavItem>
491
+ </CollapsibleNavItem>
492
+ </>
493
+ )}
494
+ </ul>
495
+ </nav>
496
+
497
+
498
+ <div className="p-3 pb-0">
499
+ <FeedbackModal />
500
+ </div>
501
+
502
+ <div className="mt-auto p-3 border-t border-slate-200 dark:border-slate-700/60 shrink-0">
503
+ <div className="flex items-center gap-3">
504
+ <Avatar className="h-10 w-10 border">
505
+ <AvatarImage src={profile?.avatar_url || undefined} alt={profile?.full_name || user?.email} />
506
+ <AvatarFallback className="bg-primary/10 text-primary font-medium">{getInitials()}</AvatarFallback>
507
+ </Avatar>
508
+ <div className="flex-1 min-w-0">
509
+ <p className="text-sm font-medium truncate text-slate-700 dark:text-slate-200">{profile?.full_name || user?.email}</p>
510
+ <div className="flex items-center gap-1.5">
511
+ <div className={cn("h-2 w-2 rounded-full", getRoleColor())}></div>
512
+ <p className="text-xs text-slate-500 dark:text-slate-400 capitalize">{role}</p>
513
+ </div>
514
+ </div>
515
+ <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">
516
+ <LogOut className="h-4 w-4" />
517
+ </Button>
518
+ </div>
519
+ </div>
520
+ </div>
521
+ </aside>
522
+
523
+ <div className="flex min-w-0 flex-1 flex-col transition-all duration-300 ease-in-out w-full min-h-0">
524
+ <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">
525
+ <Button variant="ghost" size="icon" className="md:hidden mr-3 -ml-2" onClick={() => setCmsSidebarOpen(!cmsSidebarOpen)}>
526
+ <Menu className="h-5 w-5" />
527
+ </Button>
528
+ <h1 className="min-w-0 flex-1 truncate text-lg font-semibold text-foreground">
529
+ {pageTitle}
530
+ </h1>
531
+ <Button asChild variant="outline" size="sm" className="shrink-0">
532
+ <Link href="/" target="_blank">
533
+ <ExternalLink className="h-4 w-4" />
534
+ <span className="hidden sm:inline">View Site</span>
535
+ </Link>
536
+ </Button>
537
+ </header>
538
+ <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">
539
+ {showTwoFactorReminder && <TwoFactorReminderBanner />}
540
+ {paymentsReminder && <PaymentsReminderBanner reminder={paymentsReminder} />}
541
+ {contactReminder && <ContactReminderBanner reminder={contactReminder} />}
542
+ <SystemAlertsBanner alerts={systemAlerts} />
543
+ {children}
544
+ </main>
545
+ </div>
546
+ {cmsSidebarOpen && ! (typeof window !== 'undefined' && window.innerWidth >= 768) && (
547
+ <div
548
+ className="fixed inset-x-0 bottom-0 top-16 bg-black/30 z-20 md:hidden"
549
+ onClick={() => setCmsSidebarOpen(false)}
550
+ />
551
+ )}
552
+ {isAdmin && isCortexAiActive && <CortexGlobalAgentChat />}
553
+ </div>
554
+ </EcommerceActiveProvider>
555
+ </CortexAiActiveProvider>
556
+ </CortexAiPageContextProvider>
557
+ )
558
+ }