create-nextblock 0.16.1 → 0.16.3

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 (264) 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 -221
  26. package/templates/nextblock-template/app/api/ai/seo/metadata/route.ts +186 -186
  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/route.ts +4 -4
  30. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +4542 -2904
  31. package/templates/nextblock-template/app/api/mcp/route.ts +415 -415
  32. package/templates/nextblock-template/app/api/media/record/route.ts +160 -160
  33. package/templates/nextblock-template/app/api/search/route.ts +43 -43
  34. package/templates/nextblock-template/app/api/view/route.ts +114 -114
  35. package/templates/nextblock-template/app/api/visual-editing/block-draft/route.ts +47 -47
  36. package/templates/nextblock-template/app/api/visual-editing/product-draft/route.ts +47 -47
  37. package/templates/nextblock-template/app/auth/callback/route.ts +31 -31
  38. package/templates/nextblock-template/app/cart/page.tsx +7 -7
  39. package/templates/nextblock-template/app/checkout/UcpCartHydrator.tsx +20 -20
  40. package/templates/nextblock-template/app/checkout/page.tsx +57 -57
  41. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +558 -558
  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 +406 -406
  46. package/templates/nextblock-template/app/cms/components/ContactReminderBanner.tsx +75 -75
  47. package/templates/nextblock-template/app/cms/components/CortexAiActiveContext.tsx +23 -23
  48. package/templates/nextblock-template/app/cms/components/CortexAiPageContext.tsx +58 -58
  49. package/templates/nextblock-template/app/cms/components/FeatureImageField.tsx +254 -254
  50. package/templates/nextblock-template/app/cms/components/FeedbackModal.tsx +36 -36
  51. package/templates/nextblock-template/app/cms/components/PaymentsReminderBanner.tsx +58 -58
  52. package/templates/nextblock-template/app/cms/components/SeoScoreBadge.tsx +40 -0
  53. package/templates/nextblock-template/app/cms/components/TablePagination.tsx +136 -0
  54. package/templates/nextblock-template/app/cms/components/VisibilityBadge.tsx +62 -62
  55. package/templates/nextblock-template/app/cms/components/VisibilityControl.tsx +542 -542
  56. package/templates/nextblock-template/app/cms/coupons/[id]/edit/page.tsx +16 -16
  57. package/templates/nextblock-template/app/cms/coupons/page.tsx +16 -16
  58. package/templates/nextblock-template/app/cms/dashboard/actions.ts +228 -228
  59. package/templates/nextblock-template/app/cms/dashboard/components/DashboardComponents.tsx +200 -200
  60. package/templates/nextblock-template/app/cms/inquiries/actions.ts +66 -66
  61. package/templates/nextblock-template/app/cms/inquiries/page.tsx +12 -12
  62. package/templates/nextblock-template/app/cms/interactions/page.tsx +12 -12
  63. package/templates/nextblock-template/app/cms/layout.tsx +101 -101
  64. package/templates/nextblock-template/app/cms/media/components/FolderNavigator.tsx +273 -273
  65. package/templates/nextblock-template/app/cms/media/components/FolderTree.tsx +122 -122
  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/components/PageForm.tsx +649 -649
  74. package/templates/nextblock-template/app/cms/pages/page.tsx +273 -227
  75. package/templates/nextblock-template/app/cms/posts/[id]/edit/page.tsx +2 -0
  76. package/templates/nextblock-template/app/cms/posts/components/PostForm.tsx +624 -618
  77. package/templates/nextblock-template/app/cms/posts/page.tsx +251 -194
  78. package/templates/nextblock-template/app/cms/products/[id]/edit/page.tsx +370 -370
  79. package/templates/nextblock-template/app/cms/products/attributes/page.tsx +12 -12
  80. package/templates/nextblock-template/app/cms/products/inventory/page.tsx +13 -13
  81. package/templates/nextblock-template/app/cms/products/productFormData.ts +133 -133
  82. package/templates/nextblock-template/app/cms/products/settings/page.tsx +5 -5
  83. package/templates/nextblock-template/app/cms/revisions/actions.ts +332 -332
  84. package/templates/nextblock-template/app/cms/revisions/service.test.ts +498 -498
  85. package/templates/nextblock-template/app/cms/revisions/service.ts +569 -569
  86. package/templates/nextblock-template/app/cms/revisions/utils.ts +304 -304
  87. package/templates/nextblock-template/app/cms/settings/cortex-ai/CortexAiSettingsClient.tsx +948 -948
  88. package/templates/nextblock-template/app/cms/settings/cortex-ai/McpServerSettingsCard.tsx +628 -628
  89. package/templates/nextblock-template/app/cms/settings/cortex-ai/mcp-actions.ts +230 -230
  90. package/templates/nextblock-template/app/cms/settings/cortex-ai/require-admin.ts +34 -34
  91. package/templates/nextblock-template/app/cms/settings/currencies/actions.ts +331 -331
  92. package/templates/nextblock-template/app/cms/settings/currencies/page.tsx +494 -494
  93. package/templates/nextblock-template/app/cms/settings/email/components/EmailForm.tsx +227 -227
  94. package/templates/nextblock-template/app/cms/settings/extra-translations/ExtraTranslationsWorkspace.tsx +767 -767
  95. package/templates/nextblock-template/app/cms/settings/extra-translations/actions.ts +276 -276
  96. package/templates/nextblock-template/app/cms/settings/extra-translations/page.tsx +93 -93
  97. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeEditor.tsx +382 -382
  98. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeManager.tsx +267 -267
  99. package/templates/nextblock-template/app/cms/settings/global-css/page.tsx +40 -40
  100. package/templates/nextblock-template/app/cms/settings/global-css/theme-actions.ts +259 -259
  101. package/templates/nextblock-template/app/cms/settings/logos/[id]/edit/page.tsx +7 -7
  102. package/templates/nextblock-template/app/cms/settings/logos/components/BrandingSettingsForm.tsx +339 -339
  103. package/templates/nextblock-template/app/cms/settings/logos/new/page.tsx +8 -8
  104. package/templates/nextblock-template/app/cms/settings/seo/RedirectsCard.tsx +514 -514
  105. package/templates/nextblock-template/app/cms/settings/seo/RobotsCard.tsx +529 -529
  106. package/templates/nextblock-template/app/cms/settings/seo/SeoSettingsClient.tsx +57 -57
  107. package/templates/nextblock-template/app/cms/settings/seo/actions.ts +448 -448
  108. package/templates/nextblock-template/app/cms/settings/seo/mappers.ts +93 -93
  109. package/templates/nextblock-template/app/cms/settings/seo/page.tsx +46 -46
  110. package/templates/nextblock-template/app/cms/settings/seo/require-admin.ts +47 -47
  111. package/templates/nextblock-template/app/cms/settings/site-scripts/page.tsx +51 -51
  112. package/templates/nextblock-template/app/cms/settings/taxes/page.tsx +21 -21
  113. package/templates/nextblock-template/app/cms/shipping/page.tsx +20 -20
  114. package/templates/nextblock-template/app/cms/users/components/DeleteUserButton.tsx +12 -12
  115. package/templates/nextblock-template/app/layout.tsx +671 -671
  116. package/templates/nextblock-template/app/lib/seo.ts +319 -319
  117. package/templates/nextblock-template/app/lib/ucp/protocol.ts +190 -190
  118. package/templates/nextblock-template/app/lib/ucp/server.test.ts +56 -56
  119. package/templates/nextblock-template/app/product/[slug]/page.tsx +502 -502
  120. package/templates/nextblock-template/app/profile/ProfilePageHeader.tsx +16 -16
  121. package/templates/nextblock-template/app/profile/ProfilePageMissingState.tsx +9 -9
  122. package/templates/nextblock-template/app/profile/account-links.ts +22 -22
  123. package/templates/nextblock-template/app/profile/orders/CustomerOrdersPageClient.tsx +124 -124
  124. package/templates/nextblock-template/app/profile/orders/page.tsx +19 -19
  125. package/templates/nextblock-template/app/profile/password/PasswordSettingsPageClient.tsx +128 -128
  126. package/templates/nextblock-template/app/profile/password/actions.ts +59 -59
  127. package/templates/nextblock-template/app/profile/password/page.tsx +27 -27
  128. package/templates/nextblock-template/app/providers.tsx +96 -96
  129. package/templates/nextblock-template/app/robots.ts +123 -123
  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 -137
  181. package/templates/nextblock-template/components/seo/PageSeoAuditSection.tsx +251 -244
  182. package/templates/nextblock-template/components/seo/SeoAuditPanel.tsx +749 -749
  183. package/templates/nextblock-template/components/seo/SeoIssueList.tsx +195 -195
  184. package/templates/nextblock-template/components/seo/SeoScoreDial.tsx +144 -144
  185. package/templates/nextblock-template/components/seo/SocialPreview.tsx +243 -243
  186. package/templates/nextblock-template/components/seo/SocialPreviewDialog.tsx +110 -110
  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 -86
  214. package/templates/nextblock-template/lib/cortex-ai/sandbox-headers.ts +60 -60
  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 -154
  225. package/templates/nextblock-template/lib/seo/alt-text-write-back.ts +109 -109
  226. package/templates/nextblock-template/lib/seo/block-content.ts +123 -123
  227. package/templates/nextblock-template/lib/seo/fix-prompts.test.ts +242 -242
  228. package/templates/nextblock-template/lib/seo/fix-prompts.ts +204 -204
  229. package/templates/nextblock-template/lib/seo/page-audit-context.tsx +157 -140
  230. package/templates/nextblock-template/lib/seo/page-document.test.ts +384 -350
  231. package/templates/nextblock-template/lib/seo/page-document.ts +463 -412
  232. package/templates/nextblock-template/lib/seo/redirect-store.test.ts +479 -479
  233. package/templates/nextblock-template/lib/seo/redirect-store.ts +466 -466
  234. package/templates/nextblock-template/lib/seo/robots-settings-signature.test.ts +102 -102
  235. package/templates/nextblock-template/lib/seo/robots-settings-signature.ts +41 -41
  236. package/templates/nextblock-template/lib/seo/robots-txt.test.ts +370 -370
  237. package/templates/nextblock-template/lib/seo/robots-txt.ts +510 -510
  238. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +37 -22
  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 +1 -2
  253. package/templates/nextblock-template/package.json +1 -1
  254. package/templates/nextblock-template/postcss.config.js +6 -6
  255. package/templates/nextblock-template/scripts/backup.js +115 -115
  256. package/templates/nextblock-template/scripts/restore.js +385 -385
  257. package/templates/nextblock-template/scripts/validate-editor-block-schema.ts +112 -112
  258. package/templates/nextblock-template/tailwind.config.js +25 -25
  259. package/templates/nextblock-template/tools/build-migrate.mjs +102 -102
  260. package/templates/nextblock-template/tools/configure-supabase-auth.js +282 -282
  261. package/templates/nextblock-template/tools/deploy-supabase.js +159 -159
  262. package/templates/nextblock-template/tools/lib/migrate-core.mjs +569 -569
  263. package/templates/nextblock-template/tools/update.mjs +1303 -1303
  264. package/tsconfig.base.json +3 -3
@@ -1,558 +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, 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
- }
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
+ }