@spacemade/ui 0.0.1

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 (594) hide show
  1. package/README.md +705 -0
  2. package/app.sh +806 -0
  3. package/cmd.sh +152 -0
  4. package/docs/cms-quickstart.md +206 -0
  5. package/docs/gallery-quickstart.md +24 -0
  6. package/docs/gpu-marketplace-quickstart.md +27 -0
  7. package/docs/metaverse-quickstart.md +25 -0
  8. package/docs/migration-plan.md +41 -0
  9. package/docs/modules.md +34 -0
  10. package/docs/nft-quickstart.md +26 -0
  11. package/docs/simple-cms-quickstart.md +22 -0
  12. package/middleware.ts +77 -0
  13. package/next-env.d.ts +6 -0
  14. package/next.config.ts +39 -0
  15. package/package.json +92 -0
  16. package/public/android-chrome-192x192.png +0 -0
  17. package/public/android-chrome-512x512.png +0 -0
  18. package/public/apple-touch-icon.png +0 -0
  19. package/public/favicon-16x16.png +0 -0
  20. package/public/favicon-32x32.png +0 -0
  21. package/public/favicon.ico +0 -0
  22. package/public/images/default-profile/1.png +0 -0
  23. package/public/images/default-profile/2.png +0 -0
  24. package/public/images/default-profile/3.png +0 -0
  25. package/public/images/default-profile/4.png +0 -0
  26. package/public/images/default-profile/5.png +0 -0
  27. package/public/images/default-profile/6.png +0 -0
  28. package/public/images/default-profile/7.png +0 -0
  29. package/public/images/defaults/Login-Person-Icon-dark.svg +13 -0
  30. package/public/images/defaults/Login-Person-Icon.svg +16 -0
  31. package/public/images/defaults/default-avatar.png +0 -0
  32. package/public/images/defaults/image-not-available.jpg +0 -0
  33. package/public/images/icons/amazon-icon.jpg +0 -0
  34. package/public/images/icons/azure-icon.png +0 -0
  35. package/public/images/icons/google-icon.jpg +0 -0
  36. package/public/site.webmanifest +1 -0
  37. package/scripts/crud-scaffold/bin/crud-scaffold.mjs +23 -0
  38. package/scripts/crud-scaffold/src/api/index.mjs +666 -0
  39. package/scripts/crud-scaffold/src/app/patches.mjs +355 -0
  40. package/scripts/crud-scaffold/src/core/fields.mjs +165 -0
  41. package/scripts/crud-scaffold/src/core/utils.mjs +161 -0
  42. package/scripts/crud-scaffold/src/frontend/index.mjs +1078 -0
  43. package/scripts/crud-scaffold/src/generator.mjs +103 -0
  44. package/scripts/crud-scaffold/src/templates/.gitkeep +1 -0
  45. package/scripts/crud-scaffold/src/utils/generator-utils.mjs +35 -0
  46. package/scripts/defs/cms-definition.mjs +1393 -0
  47. package/scripts/defs/gallery-definition.mjs +171 -0
  48. package/scripts/defs/gpu-definition.mjs +174 -0
  49. package/scripts/defs/metaverse-definition.mjs +170 -0
  50. package/scripts/defs/nft-definition.mjs +191 -0
  51. package/scripts/defs/simple-cms-definition.mjs +141 -0
  52. package/scripts/generate-cms-install-system.mjs +4 -0
  53. package/scripts/generate-gallery-system.mjs +4 -0
  54. package/scripts/generate-gpu-marketplace-system.mjs +4 -0
  55. package/scripts/generate-metaverse-system.mjs +4 -0
  56. package/scripts/generate-nft-system.mjs +4 -0
  57. package/scripts/generate-simple-cms-system.mjs +4 -0
  58. package/scripts/link-core.mjs +72 -0
  59. package/scripts/spacemade.mjs +446 -0
  60. package/scripts/test-generate-app.mjs +60 -0
  61. package/src/components/Dashboard/DashboardList.tsx +70 -0
  62. package/src/components/Dashboard/dashboardLayout.tsx +57 -0
  63. package/src/components/admin/nav/AdminLeftNav.tsx +168 -0
  64. package/src/components/auth/AuthBootstrap.tsx +47 -0
  65. package/src/components/auth/auth-card-shell.tsx +23 -0
  66. package/src/components/auth/forgot-password-form-template.tsx +37 -0
  67. package/src/components/auth/form/ForgotForm.tsx +146 -0
  68. package/src/components/auth/form/ResetPasswordForm.tsx +122 -0
  69. package/src/components/auth/form/SignInForm.tsx +139 -0
  70. package/src/components/auth/form/SignUpForm.tsx +166 -0
  71. package/src/components/auth/form/UpdateForm.tsx +165 -0
  72. package/src/components/auth/login-form-template.tsx +45 -0
  73. package/src/components/billing/CardBrandIcon.tsx +126 -0
  74. package/src/components/billing/block/BillingDetailsCard.tsx +120 -0
  75. package/src/components/billing/block/BillingHistory.tsx +143 -0
  76. package/src/components/billing/block/PlanDetails.tsx +138 -0
  77. package/src/components/billing/modal/UpdateCardDetailsModal.tsx +451 -0
  78. package/src/components/billing/modal/UpdatePlanModal.tsx +194 -0
  79. package/src/components/category/modal/UpdateCategoryModal.tsx +170 -0
  80. package/src/components/category/table/CategoryTable.tsx +137 -0
  81. package/src/components/common/Icons/BrainCircuitIcon.tsx +14 -0
  82. package/src/components/common/Icons/MagnifyingGlassChartIcon.tsx +14 -0
  83. package/src/components/common/Icons/PeopleGroupIcon.tsx +14 -0
  84. package/src/components/common/Icons/ScrewdriverWrenchIcon.tsx +14 -0
  85. package/src/components/common/Icons/SendMessageIcon.tsx +15 -0
  86. package/src/components/common/Icons/ShareIcon.tsx +22 -0
  87. package/src/components/common/Icons/XTwitterIcon.tsx +14 -0
  88. package/src/components/common/Image/OptimizedImage.tsx +17 -0
  89. package/src/components/common/SettingsPanel.tsx +119 -0
  90. package/src/components/common/badge/Badge.tsx +69 -0
  91. package/src/components/common/blocks/BackgroundImageBlock.tsx +43 -0
  92. package/src/components/common/blocks/Carousel.tsx +59 -0
  93. package/src/components/common/blocks/CodeSnippet.tsx +46 -0
  94. package/src/components/common/blocks/InfinityScrollWrapper.tsx +43 -0
  95. package/src/components/common/blocks/SplitBlock.tsx +47 -0
  96. package/src/components/common/blocks/TopImageBlock.tsx +39 -0
  97. package/src/components/common/button/Button.tsx +49 -0
  98. package/src/components/common/button/ButtonWithActions.tsx +71 -0
  99. package/src/components/common/button/DropdownButton.tsx +61 -0
  100. package/src/components/common/button/ScrollDownArrow.tsx +23 -0
  101. package/src/components/common/button/SharerActionBox.tsx +248 -0
  102. package/src/components/common/button/UserButton.tsx +209 -0
  103. package/src/components/common/contact/ContactForm.tsx +214 -0
  104. package/src/components/common/cta/Cta.tsx +18 -0
  105. package/src/components/common/dialog/ConversationFullscreenModal.tsx +95 -0
  106. package/src/components/common/dialog/DeleteDialog.tsx +90 -0
  107. package/src/components/common/dialog/MobileFiltersDrawer.tsx +60 -0
  108. package/src/components/common/dialog/RenameDialog.tsx +128 -0
  109. package/src/components/common/faq/FAQSection.tsx +119 -0
  110. package/src/components/common/filters/NameSearch.tsx +87 -0
  111. package/src/components/common/footer/SmallFooter.tsx +62 -0
  112. package/src/components/common/forms/AdvanceAccordion.tsx +154 -0
  113. package/src/components/common/forms/CheckBox.tsx +29 -0
  114. package/src/components/common/forms/DateTimePicker.tsx +101 -0
  115. package/src/components/common/forms/Dropzone.tsx +278 -0
  116. package/src/components/common/forms/EmailTagInput.tsx +67 -0
  117. package/src/components/common/forms/FieldAssistantBar.tsx +32 -0
  118. package/src/components/common/forms/HTMLEditor.tsx +48 -0
  119. package/src/components/common/forms/IconPicker.tsx +129 -0
  120. package/src/components/common/forms/Input.tsx +362 -0
  121. package/src/components/common/forms/InputColor.tsx +36 -0
  122. package/src/components/common/forms/RadioInputs.tsx +62 -0
  123. package/src/components/common/forms/Select.tsx +214 -0
  124. package/src/components/common/forms/SimpleTagsInput.tsx +89 -0
  125. package/src/components/common/forms/TagInput.tsx +111 -0
  126. package/src/components/common/forms/Textarea.tsx +99 -0
  127. package/src/components/common/forms/ToggleButton.tsx +67 -0
  128. package/src/components/common/forms/UserInvitePicker.tsx +600 -0
  129. package/src/components/common/header/AppPageTitle.tsx +34 -0
  130. package/src/components/common/header/SubtitleAccordion.tsx +63 -0
  131. package/src/components/common/home/block/GetStarted.tsx +17 -0
  132. package/src/components/common/home/block/Hero.tsx +33 -0
  133. package/src/components/common/home/block/InstallShortcut.tsx +41 -0
  134. package/src/components/common/home/block/MarketplaceBlock.tsx +34 -0
  135. package/src/components/common/home/block/OriginStoryBanner.tsx +17 -0
  136. package/src/components/common/home/block/OsirusCTABlock.tsx +21 -0
  137. package/src/components/common/home/block/PromoFeatureSlider.tsx +260 -0
  138. package/src/components/common/layout/DetailHero.tsx +87 -0
  139. package/src/components/common/layout/SideNavLayout.tsx +1016 -0
  140. package/src/components/common/layout/account/AccountLayout.tsx +99 -0
  141. package/src/components/common/layout/admin/AdminLayout.tsx +17 -0
  142. package/src/components/common/layout/explore/ExploreLayout.tsx +23 -0
  143. package/src/components/common/layout/explore/ExploreLayoutContent.tsx +20 -0
  144. package/src/components/common/layout/explore/ExploreLayoutFilters.tsx +28 -0
  145. package/src/components/common/loading/LoadingScreen.tsx +86 -0
  146. package/src/components/common/loading/Spinner.tsx +12 -0
  147. package/src/components/common/state/InvalidInviteCard.tsx +32 -0
  148. package/src/components/common/table/TableFilter.tsx +205 -0
  149. package/src/components/common/table/TableHeader.tsx +33 -0
  150. package/src/components/common/table/TablePaging.tsx +190 -0
  151. package/src/components/common/table/TablePagingButton.tsx +64 -0
  152. package/src/components/common/table/TablePagingInput.tsx +79 -0
  153. package/src/components/common/useUrlSelectedModel.ts +7 -0
  154. package/src/components/docs/DocsSitePreviewPage.tsx +122 -0
  155. package/src/components/docs/block/DocsPageDetailBlock.tsx +333 -0
  156. package/src/components/docs/block/DocsSidebarTopContent.tsx +8 -0
  157. package/src/components/docs/block/DocsSitePagesBlock.tsx +81 -0
  158. package/src/components/docs/block/DocsSitesBlock.tsx +35 -0
  159. package/src/components/docs/modal/CreateDocsSiteModal.tsx +132 -0
  160. package/src/components/docs/table/DocsPagesTable.tsx +163 -0
  161. package/src/components/docs/table/DocsSitesTable.tsx +109 -0
  162. package/src/components/groups/block/GroupInitialAvatar.tsx +53 -0
  163. package/src/components/groups/grid/OrgGroupMembersGrid.tsx +253 -0
  164. package/src/components/groups/modal/AddGroupModal.tsx +138 -0
  165. package/src/components/groups/modal/OrgGroupMembersModal.tsx +171 -0
  166. package/src/components/groups/modal/OrgGroupPermissionsModal.tsx +184 -0
  167. package/src/components/groups/table/OrgGroupsTable.tsx +470 -0
  168. package/src/components/head/DefaultMetadata.tsx +135 -0
  169. package/src/components/head/PageSeo.tsx +198 -0
  170. package/src/components/hoc/WithAuth.tsx +82 -0
  171. package/src/components/hoc/WithCustomerIO.tsx +48 -0
  172. package/src/components/hoc/WithGTM.tsx +31 -0
  173. package/src/components/hoc/WithGlobalContext.tsx +30 -0
  174. package/src/components/hoc/WithReCaptcha.tsx +31 -0
  175. package/src/components/hoc/WithStripe.tsx +68 -0
  176. package/src/components/layout/SidebarSizer.tsx +63 -0
  177. package/src/components/layout/app-left-nav.tsx +31 -0
  178. package/src/components/layout/app-main-layout.tsx +39 -0
  179. package/src/components/layout/site-footer.tsx +11 -0
  180. package/src/components/layout/site-header.tsx +19 -0
  181. package/src/components/marketplace/card/ProductCard.tsx +178 -0
  182. package/src/components/media/blocks/MediaAttachmentsList.tsx +79 -0
  183. package/src/components/media/blocks/MediaDetails.tsx +139 -0
  184. package/src/components/media/blocks/MediaGrid.tsx +245 -0
  185. package/src/components/media/form/MediaMiniForm.tsx +105 -0
  186. package/src/components/media/form/UpdateMediaForm.tsx +209 -0
  187. package/src/components/media/items/CircleMediaPicker.tsx +76 -0
  188. package/src/components/media/items/MediaAttachmentLinks.tsx +98 -0
  189. package/src/components/media/items/MediaDocumentPreview.tsx +43 -0
  190. package/src/components/media/items/MediaFileIcon.tsx +30 -0
  191. package/src/components/media/items/MediaPickerBox.tsx +94 -0
  192. package/src/components/media/items/MediaPickerButton.tsx +37 -0
  193. package/src/components/media/items/MediaSourcePreview.tsx +35 -0
  194. package/src/components/media/modal/AddMediaModal.tsx +237 -0
  195. package/src/components/media/modal/MediaAttachmentsModal.tsx +113 -0
  196. package/src/components/media/modal/MediaBulkDeleteWarningModal.tsx +142 -0
  197. package/src/components/media/modal/MediaDeleteWarningModal.tsx +98 -0
  198. package/src/components/media/modal/MediaPickerModal.tsx +201 -0
  199. package/src/components/media/table/MediaTable.tsx +340 -0
  200. package/src/components/media/table/MediaTableActions.tsx +130 -0
  201. package/src/components/media/table/MediaTableFilter.tsx +163 -0
  202. package/src/components/modules/module-card-grid.tsx +19 -0
  203. package/src/components/modules/module-page.tsx +27 -0
  204. package/src/components/modules/resource-page.tsx +15 -0
  205. package/src/components/nav/AdminMobileMenu.tsx +228 -0
  206. package/src/components/nav/AppTopNav.tsx +53 -0
  207. package/src/components/nav/MobileMenu.tsx +132 -0
  208. package/src/components/nav/TopNav.tsx +137 -0
  209. package/src/components/openapi/DeleteTokenModal.tsx +72 -0
  210. package/src/components/openapi/actions/ApiTokenActionsMenu.tsx +141 -0
  211. package/src/components/openapi/actions/ApiTokenCreateModal.tsx +107 -0
  212. package/src/components/openapi/actions/ApiTokenEditModal.tsx +168 -0
  213. package/src/components/orgs/OrgCreateModal.tsx +126 -0
  214. package/src/components/orgs/OrgJumpRedirect.tsx +150 -0
  215. package/src/components/page/SiteContentPage.tsx +129 -0
  216. package/src/components/post/accordion/FilterPostCategoriesAccordion.tsx +126 -0
  217. package/src/components/post/block/FeaturedProductCard.tsx +31 -0
  218. package/src/components/post/block/FeaturedProviderCard.tsx +51 -0
  219. package/src/components/post/block/InTheNews.tsx +77 -0
  220. package/src/components/post/block/PostCardsGrid.tsx +56 -0
  221. package/src/components/post/block/PostContent.tsx +128 -0
  222. package/src/components/post/block/PostDetailPage.tsx +95 -0
  223. package/src/components/post/block/PostList.tsx +111 -0
  224. package/src/components/post/block/PostNextAndPrevButtons.tsx +78 -0
  225. package/src/components/post/block/PostPeopleAlsoReadBlock.tsx +69 -0
  226. package/src/components/post/block/PostRelatedCards.tsx +43 -0
  227. package/src/components/post/card/FeaturedPostCard.tsx +107 -0
  228. package/src/components/post/card/InTheNewsCard.tsx +162 -0
  229. package/src/components/post/card/PostCard.tsx +125 -0
  230. package/src/components/post/card/RelatedPostCard.tsx +115 -0
  231. package/src/components/post/form/UpdatePostForm.tsx +639 -0
  232. package/src/components/post/modal/CreatePostModal.tsx +115 -0
  233. package/src/components/post/modal/PreviewPostModal.tsx +82 -0
  234. package/src/components/post/nav/BlogCategoriesSideNav.tsx +55 -0
  235. package/src/components/post/table/PostsTable.tsx +284 -0
  236. package/src/components/pricing/block/AddOnRow.tsx +78 -0
  237. package/src/components/pricing/block/CompletePurchase.tsx +546 -0
  238. package/src/components/pricing/block/PlanPicker.tsx +76 -0
  239. package/src/components/pricing/card/PricingCard.tsx +291 -0
  240. package/src/components/pricing/form/AddBillingInformationForm.tsx +212 -0
  241. package/src/components/pricing/form/AddPaymentMethodForm.tsx +252 -0
  242. package/src/components/pricing/form/CouponCodeForm.tsx +118 -0
  243. package/src/components/pricing/form/StripePaymentForm.tsx +106 -0
  244. package/src/components/product/block/ProductScreenshot.tsx +22 -0
  245. package/src/components/product/block/ProductScreenshotPreview.tsx +46 -0
  246. package/src/components/product/button/MediaScreenshotPicker.tsx +72 -0
  247. package/src/components/product/form/UpdateProductForm.tsx +718 -0
  248. package/src/components/product/modal/CreateProductModal.tsx +128 -0
  249. package/src/components/product/modal/UpdateProductCouponModal.tsx +227 -0
  250. package/src/components/product/modal/UpdateProductPlanModal.tsx +291 -0
  251. package/src/components/product/modal/UpdateProductVersionModal.tsx +236 -0
  252. package/src/components/product/table/ProductCouponsTable.tsx +100 -0
  253. package/src/components/product/table/ProductPlansTable.tsx +118 -0
  254. package/src/components/product/table/ProductVersionsAdminTable.tsx +103 -0
  255. package/src/components/product/table/ProductVersionsTable.tsx +111 -0
  256. package/src/components/product/table/ProductsTable.tsx +133 -0
  257. package/src/components/projects/ProjectFilesCard.tsx +134 -0
  258. package/src/components/projects/ProjectItemOptionButton.tsx +112 -0
  259. package/src/components/projects/ProjectPickerNav.tsx +440 -0
  260. package/src/components/projects/ProjectQuickCreateModal.tsx +159 -0
  261. package/src/components/projects/ProjectSidebarList.tsx +183 -0
  262. package/src/components/projects/actions/ProjectActionsMenu.tsx +77 -0
  263. package/src/components/projects/actions/ProjectCreateModal.tsx +577 -0
  264. package/src/components/projects/actions/ProjectEditModal.tsx +345 -0
  265. package/src/components/projects/actions/ProjectFileGrid.tsx +153 -0
  266. package/src/components/projects/actions/ProjectFilesModal.tsx +259 -0
  267. package/src/components/projects/actions/ProjectFilesPicker.tsx +31 -0
  268. package/src/components/projects/actions/ProjectFilesUploadModal.tsx +181 -0
  269. package/src/components/projects/actions/ProjectInstructions.tsx +160 -0
  270. package/src/components/projects/actions/RenameProjectModal.tsx +120 -0
  271. package/src/components/projects/actions/index.tsx +98 -0
  272. package/src/components/projects/block/HeaderProjectImagePicker.tsx +52 -0
  273. package/src/components/projects/permission/ProjectPermissionInviteModal.tsx +181 -0
  274. package/src/components/projects/permission/ProjectUserPermission.tsx +170 -0
  275. package/src/components/projects/postByCategory.tsx +118 -0
  276. package/src/components/projects/projectFileHistory.tsx +48 -0
  277. package/src/components/projects/table/ProjectTable.tsx +365 -0
  278. package/src/components/provider/BuildspecForm.tsx +288 -0
  279. package/src/components/provider/CreateProviderModal.tsx +210 -0
  280. package/src/components/provider/FeaturedProviders.tsx +137 -0
  281. package/src/components/provider/ProviderConnectModal.tsx +324 -0
  282. package/src/components/provider/form/UpdateProviderForm.tsx +449 -0
  283. package/src/components/provider/table/ProvidersTable.tsx +144 -0
  284. package/src/components/providers/ProviderFeaturesSideNav.tsx +52 -0
  285. package/src/components/settings/SettingsLayout.tsx +14 -0
  286. package/src/components/settings/SettingsSidebarNav.tsx +53 -0
  287. package/src/components/settings/settingsNav.ts +96 -0
  288. package/src/components/site/modal/UpdateSiteModal.tsx +134 -0
  289. package/src/components/site/table/SiteTable.tsx +198 -0
  290. package/src/components/starter/list-panel.tsx +12 -0
  291. package/src/components/starter/starter-overview.tsx +32 -0
  292. package/src/components/starter/stats-grid.tsx +20 -0
  293. package/src/components/storage/VectorStoreFileDeleteButton.tsx +71 -0
  294. package/src/components/storage/actions/VectorStoreActionsMenu.tsx +70 -0
  295. package/src/components/storage/actions/VectorStoreEditModal.tsx +220 -0
  296. package/src/components/storage/actions/VectorStoreFileActions.tsx +61 -0
  297. package/src/components/storage/actions/index.tsx +76 -0
  298. package/src/components/storage/addStorageModal.tsx +552 -0
  299. package/src/components/storage/table/vectorStoreTable.tsx +461 -0
  300. package/src/components/storage/vectorFilesModal.tsx +209 -0
  301. package/src/components/storage/vectorStoreFileGrid.tsx +384 -0
  302. package/src/components/tag/modal/UpdateTagModal.tsx +192 -0
  303. package/src/components/tag/table/TagTable.tsx +138 -0
  304. package/src/components/user/block/BadgesBlock.tsx +26 -0
  305. package/src/components/user/form/ChangePasswordForm.tsx +119 -0
  306. package/src/components/user/form/ProfileForm.tsx +168 -0
  307. package/src/components/user/grid/UserGrid.tsx +475 -0
  308. package/src/components/user/modal/AddUserModal.tsx +165 -0
  309. package/src/components/user/modal/UpdateUserDetailsModal.tsx +319 -0
  310. package/src/components/user/modal/UpgradeUserLimitModal.tsx +123 -0
  311. package/src/components/user/modal/UserPermissionsModal.tsx +251 -0
  312. package/src/components/user/table/UserTable.tsx +202 -0
  313. package/src/config/app.ts +16 -0
  314. package/src/config/modules.ts +100 -0
  315. package/src/config/navigation.ts +28 -0
  316. package/src/config/runtime.ts +3 -0
  317. package/src/context/CheckoutContext.tsx +123 -0
  318. package/src/context/ProjectContext.tsx +123 -0
  319. package/src/context/RouterContext.tsx +127 -0
  320. package/src/context/UIContext.tsx +47 -0
  321. package/src/context/UserAuthContext.tsx +26 -0
  322. package/src/context/VectorStoreContext.tsx +51 -0
  323. package/src/context/index.ts +2 -0
  324. package/src/data/bootstrap-icons.json +2080 -0
  325. package/src/data/bootstrap.ts +196 -0
  326. package/src/data/bootstrapIcons.ts +28 -0
  327. package/src/enum/AppEnvironments.ts +4 -0
  328. package/src/enum/HTTPErrorStatus.ts +10 -0
  329. package/src/helpers/api/index.ts +123 -0
  330. package/src/helpers/constants/index.ts +4 -0
  331. package/src/helpers/constants/messages.ts +1 -0
  332. package/src/helpers/constants/regex.ts +10 -0
  333. package/src/helpers/constants/stripe.ts +1 -0
  334. package/src/helpers/constants/system-agent.ts +12 -0
  335. package/src/helpers/data-transform/bytesToSize.ts +8 -0
  336. package/src/helpers/data-transform/dropzone.ts +116 -0
  337. package/src/helpers/data-transform/filterUtils.ts +21 -0
  338. package/src/helpers/data-transform/index.ts +4 -0
  339. package/src/helpers/data-transform/operations.ts +3 -0
  340. package/src/helpers/data-transform/paging.ts +24 -0
  341. package/src/helpers/data-transform/stringCaseTransform.ts +34 -0
  342. package/src/helpers/date/index.ts +149 -0
  343. package/src/helpers/error/formErrorHandler.tsx +38 -0
  344. package/src/helpers/images/assets.ts +32 -0
  345. package/src/helpers/images/defaultProfileImage.ts +21 -0
  346. package/src/helpers/images/fileType.ts +123 -0
  347. package/src/helpers/images/index.ts +3 -0
  348. package/src/helpers/navigation/routeScroll.ts +29 -0
  349. package/src/helpers/pageScreenshot.ts +176 -0
  350. package/src/helpers/permissions/index.ts +292 -0
  351. package/src/helpers/providers/providerFeatures.ts +29 -0
  352. package/src/helpers/sharer/index.ts +44 -0
  353. package/src/helpers/sitemap/sitemap-utils.ts +50 -0
  354. package/src/helpers/slugUtils/index.ts +39 -0
  355. package/src/helpers/sonicVoices.ts +22 -0
  356. package/src/helpers/string/index.ts +93 -0
  357. package/src/helpers/theme/colors.ts +27 -0
  358. package/src/helpers/types/api.ts +22 -0
  359. package/src/helpers/types/customer-io.ts +47 -0
  360. package/src/helpers/types/data-layer.ts +25 -0
  361. package/src/helpers/types/index.ts +4 -0
  362. package/src/helpers/types/nav.ts +13 -0
  363. package/src/helpers/types/page-props.ts +31 -0
  364. package/src/helpers/types/select-option.ts +4 -0
  365. package/src/helpers/types/utils.ts +7 -0
  366. package/src/helpers/url/index.ts +26 -0
  367. package/src/hooks/auth/useAccountStore.ts +69 -0
  368. package/src/hooks/auth/useAuthStore.ts +162 -0
  369. package/src/hooks/category/useCategoryStore.ts +71 -0
  370. package/src/hooks/index.ts +17 -0
  371. package/src/hooks/media/useMediaStore.ts +46 -0
  372. package/src/hooks/post/usePostStore.ts +64 -0
  373. package/src/hooks/post/usePostUtils.ts +27 -0
  374. package/src/hooks/product/useProductPlanStore.ts +73 -0
  375. package/src/hooks/product/useProductStore.ts +64 -0
  376. package/src/hooks/product/useProductVersionStore.ts +57 -0
  377. package/src/hooks/site/useSiteStore.ts +53 -0
  378. package/src/hooks/tag/useTagStore.ts +65 -0
  379. package/src/hooks/utils/useAutosizeTextArea.ts +20 -0
  380. package/src/hooks/utils/useCountries.ts +25 -0
  381. package/src/hooks/utils/useGA4DataLayer.ts +25 -0
  382. package/src/hooks/utils/useNavOptions.ts +241 -0
  383. package/src/hooks/utils/useSearchAndFilterCommon.ts +78 -0
  384. package/src/hooks/utils/useTrackingEvents.ts +65 -0
  385. package/src/lib/app-paths.ts +19 -0
  386. package/src/lib/auth.ts +42 -0
  387. package/src/lib/next-router.ts +164 -0
  388. package/src/lib/routes.ts +36 -0
  389. package/src/lib/security.ts +19 -0
  390. package/src/pages/404.tsx +104 -0
  391. package/src/pages/500.tsx +26 -0
  392. package/src/pages/_app.tsx +87 -0
  393. package/src/pages/_document.tsx +26 -0
  394. package/src/pages/account/verify.tsx +178 -0
  395. package/src/pages/admin/activity/[activityId].tsx +77 -0
  396. package/src/pages/admin/activity/bans.tsx +197 -0
  397. package/src/pages/admin/activity/index.tsx +207 -0
  398. package/src/pages/admin/activity/settings.tsx +189 -0
  399. package/src/pages/admin/categories/index.tsx +61 -0
  400. package/src/pages/admin/coupons/index.tsx +38 -0
  401. package/src/pages/admin/entitlements/index.tsx +646 -0
  402. package/src/pages/admin/index.tsx +65 -0
  403. package/src/pages/admin/media/[id]/index.tsx +55 -0
  404. package/src/pages/admin/media/index.tsx +62 -0
  405. package/src/pages/admin/orgs/[orgId]/[name].tsx +1 -0
  406. package/src/pages/admin/orgs/index.tsx +256 -0
  407. package/src/pages/admin/plans/index.tsx +26 -0
  408. package/src/pages/admin/posts/[id].tsx +80 -0
  409. package/src/pages/admin/posts/index.tsx +63 -0
  410. package/src/pages/admin/products/[id].tsx +71 -0
  411. package/src/pages/admin/products/index.tsx +62 -0
  412. package/src/pages/admin/profile/index.tsx +26 -0
  413. package/src/pages/admin/providers/[id].tsx +77 -0
  414. package/src/pages/admin/providers/index.tsx +63 -0
  415. package/src/pages/admin/tags/index.tsx +58 -0
  416. package/src/pages/admin/users/[userId]/[name].tsx +1 -0
  417. package/src/pages/admin/users/index.tsx +295 -0
  418. package/src/pages/admin/versions/[id].tsx +211 -0
  419. package/src/pages/admin/versions/index.tsx +25 -0
  420. package/src/pages/blog/[postSlug].tsx +106 -0
  421. package/src/pages/blog/c/[categorySlug]/index.tsx +126 -0
  422. package/src/pages/blog/index.tsx +37 -0
  423. package/src/pages/cart/[productPlanSlug].tsx +631 -0
  424. package/src/pages/checkout/[productPlanSlug].tsx +368 -0
  425. package/src/pages/docs/index.tsx +24 -0
  426. package/src/pages/docs/sites/[siteId]/[siteName]/index.tsx +67 -0
  427. package/src/pages/docs/sites/[siteId]/[siteName]/pages/[pagesId].tsx +79 -0
  428. package/src/pages/docs/sites/[siteId]/[siteName]/pages/index.tsx +67 -0
  429. package/src/pages/docs/sites/[siteId]/[siteName]/preview/[[...slug]].tsx +7 -0
  430. package/src/pages/forgot.tsx +46 -0
  431. package/src/pages/groups/[groupId]/[name].tsx +337 -0
  432. package/src/pages/groups/index.tsx +62 -0
  433. package/src/pages/healthcheck.tsx +7 -0
  434. package/src/pages/index.tsx +309 -0
  435. package/src/pages/login.tsx +75 -0
  436. package/src/pages/marketplace/[slug].tsx +171 -0
  437. package/src/pages/marketplace/index.tsx +92 -0
  438. package/src/pages/openapi/index.tsx +77 -0
  439. package/src/pages/openapi/tokens/index.tsx +128 -0
  440. package/src/pages/org/[name]/settings.tsx +14 -0
  441. package/src/pages/org/[name]/token/index.tsx +109 -0
  442. package/src/pages/pricing.tsx +242 -0
  443. package/src/pages/projects/[projectId]/[name]/files/index.tsx +121 -0
  444. package/src/pages/projects/[projectId]/[name]/index.tsx +305 -0
  445. package/src/pages/projects/[projectId]/[name]/permission/index.tsx +143 -0
  446. package/src/pages/projects/[projectId]/token/index.tsx +120 -0
  447. package/src/pages/projects/index.tsx +129 -0
  448. package/src/pages/providers/[name].tsx +512 -0
  449. package/src/pages/providers/index.tsx +472 -0
  450. package/src/pages/reset.tsx +69 -0
  451. package/src/pages/settings/billing/index.tsx +41 -0
  452. package/src/pages/settings/index.tsx +133 -0
  453. package/src/pages/settings/organizations/[orgId]/invite/index.tsx +162 -0
  454. package/src/pages/settings/organizations/[orgId]/settings/index.tsx +98 -0
  455. package/src/pages/settings/organizations/[orgId]/token/index.tsx +109 -0
  456. package/src/pages/settings/organizations/index.tsx +148 -0
  457. package/src/pages/settings/organizations/new/index.tsx +252 -0
  458. package/src/pages/settings/profile/change-password.tsx +26 -0
  459. package/src/pages/settings/profile/index.tsx +103 -0
  460. package/src/pages/settings/profile/org-profile.tsx +127 -0
  461. package/src/pages/settings/profile/profile.tsx +26 -0
  462. package/src/pages/settings/sites/index.tsx +85 -0
  463. package/src/pages/settings/subscriptions/index.tsx +76 -0
  464. package/src/pages/settings/tokens/index.tsx +149 -0
  465. package/src/pages/signup/index.tsx +83 -0
  466. package/src/pages/signup/verify.tsx +138 -0
  467. package/src/pages/sites/[siteId]/[siteName]/[[...slug]].tsx +103 -0
  468. package/src/pages/sites/[siteId]/[siteName]/pages/[pageId].tsx +243 -0
  469. package/src/pages/sites/[siteId]/[siteName]/pages/index.tsx +140 -0
  470. package/src/pages/sites/host/[[...slug]].tsx +75 -0
  471. package/src/pages/storage/[vectorStoreId]/[name].tsx +653 -0
  472. package/src/pages/storage/index.tsx +526 -0
  473. package/src/pages/update/index.tsx +109 -0
  474. package/src/pages/update/verify.tsx +121 -0
  475. package/src/pages/users/[userId]/[name].tsx +791 -0
  476. package/src/pages/users/index.tsx +152 -0
  477. package/src/sass/app.scss +59 -0
  478. package/src/sass/base/_animations.scss +70 -0
  479. package/src/sass/base/_borders.scss +78 -0
  480. package/src/sass/base/_custom-backgrounds.scss +107 -0
  481. package/src/sass/base/_interactions.scss +35 -0
  482. package/src/sass/base/_main.scss +239 -0
  483. package/src/sass/base/_positions.scss +111 -0
  484. package/src/sass/base/_sizes.scss +120 -0
  485. package/src/sass/base/_typography.scss +184 -0
  486. package/src/sass/components/_accordion.scss +63 -0
  487. package/src/sass/components/_ad.scss +44 -0
  488. package/src/sass/components/_avatar.scss +18 -0
  489. package/src/sass/components/_badge.scss +6 -0
  490. package/src/sass/components/_button.scss +53 -0
  491. package/src/sass/components/_checkbox.scss +52 -0
  492. package/src/sass/components/_circle-media-picker.scss +32 -0
  493. package/src/sass/components/_code-snipped.scss +50 -0
  494. package/src/sass/components/_date-time-picker.scss +796 -0
  495. package/src/sass/components/_dialog.scss +27 -0
  496. package/src/sass/components/_gradients.scss +7 -0
  497. package/src/sass/components/_group-detail.scss +620 -0
  498. package/src/sass/components/_input.scss +567 -0
  499. package/src/sass/components/_menu.scss +31 -0
  500. package/src/sass/components/_modal.scss +273 -0
  501. package/src/sass/components/_popover.scss +29 -0
  502. package/src/sass/components/_rich-content.scss +531 -0
  503. package/src/sass/components/_spinner.scss +71 -0
  504. package/src/sass/components/_swagger.scss +7 -0
  505. package/src/sass/components/_swiper.scss +16 -0
  506. package/src/sass/components/_switch.scss +46 -0
  507. package/src/sass/components/_table.scss +39 -0
  508. package/src/sass/components/_tabs.scss +38 -0
  509. package/src/sass/components/_tag-input.scss +28 -0
  510. package/src/sass/components/_toast.scss +26 -0
  511. package/src/sass/components/_tooltip.scss +31 -0
  512. package/src/sass/layout/_base.scss +937 -0
  513. package/src/sass/layout/_footer.scss +148 -0
  514. package/src/sass/layout/_hero.scss +33 -0
  515. package/src/sass/layout/_nav.scss +77 -0
  516. package/src/sass/layout/_news-card-grid.scss +507 -0
  517. package/src/sass/utilities/_mixins.scss +21 -0
  518. package/src/sass/utilities/_sizes.scss +137 -0
  519. package/src/sass/utilities/_utils.scss +23 -0
  520. package/src/sass/utilities/_variables.scss +115 -0
  521. package/src/store/hooks.ts +5 -0
  522. package/src/store/hydrate.ts +1 -0
  523. package/src/store/model/activity.model.ts +52 -0
  524. package/src/store/model/address.model.ts +9 -0
  525. package/src/store/model/apiToken.model.ts +26 -0
  526. package/src/store/model/category.model.ts +20 -0
  527. package/src/store/model/entityStatus.model.ts +25 -0
  528. package/src/store/model/index.ts +25 -0
  529. package/src/store/model/invoice.model.ts +37 -0
  530. package/src/store/model/media.model.ts +70 -0
  531. package/src/store/model/org-group-permission.model.ts +16 -0
  532. package/src/store/model/org-group.model.ts +14 -0
  533. package/src/store/model/org-membership.model.ts +23 -0
  534. package/src/store/model/org.model.ts +13 -0
  535. package/src/store/model/page.model.ts +33 -0
  536. package/src/store/model/post.model.ts +60 -0
  537. package/src/store/model/product-coupon.model.ts +42 -0
  538. package/src/store/model/product-feature-entitlement.ts +40 -0
  539. package/src/store/model/product-feature.ts +29 -0
  540. package/src/store/model/product-plan.model.ts +120 -0
  541. package/src/store/model/product-version.model.ts +24 -0
  542. package/src/store/model/product.model.ts +91 -0
  543. package/src/store/model/project-file.model.ts +18 -0
  544. package/src/store/model/project-user-permission.model.ts +41 -0
  545. package/src/store/model/project.model.ts +48 -0
  546. package/src/store/model/provider.model.ts +118 -0
  547. package/src/store/model/purchase.model.ts +19 -0
  548. package/src/store/model/site-crawl-job.model.ts +31 -0
  549. package/src/store/model/site-page.model.ts +37 -0
  550. package/src/store/model/site.model.ts +15 -0
  551. package/src/store/model/subscription.model.ts +60 -0
  552. package/src/store/model/tag.model.ts +18 -0
  553. package/src/store/model/user-permission.model.ts +21 -0
  554. package/src/store/model/user.model.ts +97 -0
  555. package/src/store/model/vector-store-file.model.ts +40 -0
  556. package/src/store/model/vector-store.model.ts +41 -0
  557. package/src/store/slice/api/accountApiSlice.ts +92 -0
  558. package/src/store/slice/api/accountSlice.ts +57 -0
  559. package/src/store/slice/api/activityApiSlice.ts +218 -0
  560. package/src/store/slice/api/apiTokenSlice.ts +153 -0
  561. package/src/store/slice/api/authApiSlice.ts +220 -0
  562. package/src/store/slice/api/base-domain-api.ts +19 -0
  563. package/src/store/slice/api/billingUnitTypesApiSlice.ts +45 -0
  564. package/src/store/slice/api/bootstrapIconApiSlice.ts +36 -0
  565. package/src/store/slice/api/categoriesApiSlice.ts +101 -0
  566. package/src/store/slice/api/fontawesomeApiSlice.ts +43 -0
  567. package/src/store/slice/api/invoiceApiSlice.ts +37 -0
  568. package/src/store/slice/api/leadApiSlice.ts +48 -0
  569. package/src/store/slice/api/mediaApiSlice.ts +276 -0
  570. package/src/store/slice/api/orgApiSlice.ts +185 -0
  571. package/src/store/slice/api/orgGroupApiSlice.ts +146 -0
  572. package/src/store/slice/api/pageApiSlice.ts +111 -0
  573. package/src/store/slice/api/paymentApiSlice.ts +27 -0
  574. package/src/store/slice/api/postApiSlice.ts +369 -0
  575. package/src/store/slice/api/productCouponsApiSlice.ts +101 -0
  576. package/src/store/slice/api/productFeaturesApiSlice.ts +93 -0
  577. package/src/store/slice/api/productPlansApiSlice.ts +142 -0
  578. package/src/store/slice/api/productSubscriptionsApiSlice.ts +156 -0
  579. package/src/store/slice/api/productVersionsApiSlice.ts +116 -0
  580. package/src/store/slice/api/productsApiSlice.ts +169 -0
  581. package/src/store/slice/api/projectApiSlice.ts +135 -0
  582. package/src/store/slice/api/projectFileApiSlice.ts +152 -0
  583. package/src/store/slice/api/projectUserPermissionApiSlice.ts +153 -0
  584. package/src/store/slice/api/providerApiSlice.ts +259 -0
  585. package/src/store/slice/api/providerSettingApiSlice.ts +174 -0
  586. package/src/store/slice/api/siteApiSlice.ts +93 -0
  587. package/src/store/slice/api/stripeApiSlice.ts +114 -0
  588. package/src/store/slice/api/tagsApiSlice.ts +96 -0
  589. package/src/store/slice/api/userApiSlice.ts +305 -0
  590. package/src/store/slice/api/vectorStoreApiSlice.ts +119 -0
  591. package/src/store/slice/api/vectorStoreFileApiSlice.ts +127 -0
  592. package/src/store/store.ts +130 -0
  593. package/src/types/bootstrap.ts +30 -0
  594. package/tsconfig.json +103 -0
@@ -0,0 +1,546 @@
1
+ 'use client'
2
+
3
+ import Link from 'next/link'
4
+ import { ProductPlan, ProductPlanPricingModel } from '@store/model'
5
+ import { useGetUserPaymentMethodQuery } from '@store/slice/api/userApiSlice'
6
+ import { useCheckoutContext } from '@context/CheckoutContext'
7
+ import { useUserAuthContext } from '@context/UserAuthContext'
8
+ import Button from '@components/common/button/Button'
9
+ import {
10
+ useGetSubscriptionQuery,
11
+ useGetUpdateSubscriptionPlanPreviewQuery,
12
+ useSubscribeMutation,
13
+ useUpdateSubscriptionPlanMutation,
14
+ } from '@store/slice/api/stripeApiSlice'
15
+ import { useGetOneProductQuery } from '@store/slice/api/productsApiSlice'
16
+ import { useRouter } from 'next/router'
17
+ import { toast } from 'react-toastify'
18
+ import { DEFAULT_ERROR_MESSAGE } from '@helpers/constants'
19
+ import { useState, useMemo } from 'react'
20
+ import Spinner from '@components/common/loading/Spinner'
21
+ import { currencyPipe } from '@helpers/string'
22
+ import { centsToDollars } from '@helpers/data-transform'
23
+ import { CouponCodeForm } from '@components/pricing/form/CouponCodeForm'
24
+ import { useTrackingEvents } from '@hooks'
25
+
26
+ // 🔹 Extended props to support bundles but keep backwards compatible
27
+ type CompletePurchaseProps = {
28
+ plan: ProductPlan
29
+ isBundle?: boolean
30
+ bundlePlans?: ProductPlan[]
31
+ selectedPlanSlugs?: string[]
32
+ product?: any
33
+ }
34
+
35
+ export const CompletePurchase = ({
36
+ plan,
37
+ isBundle,
38
+ bundlePlans,
39
+ selectedPlanSlugs,
40
+ product,
41
+ }: CompletePurchaseProps) => {
42
+ const [isSubmitted, setIsSubmitted] = useState(false)
43
+ const router = useRouter()
44
+ const [subscribe, { isLoading: isLoadingSubscribe }] = useSubscribeMutation()
45
+ const [updateSubscriptionPlan, { isLoading: isLoadingSubscriptionChange }] =
46
+ useUpdateSubscriptionPlanMutation()
47
+
48
+ const { user } = useUserAuthContext()
49
+ const { identifyUserForCustomerIO, trackEvent } = useTrackingEvents()
50
+ const { isBillingCompleted, couponCode, appliedCoupon } = useCheckoutContext()
51
+
52
+ const toNumber = (v: unknown): number | null => {
53
+ if (typeof v === 'number') return Number.isFinite(v) ? v : null
54
+ if (typeof v === 'string') {
55
+ const n = Number(v.replace(/[$,]/g, ''))
56
+ return Number.isFinite(n) ? n : null
57
+ }
58
+ if (typeof v === 'bigint') return Number(v)
59
+ if (v && typeof (v as any).toNumber === 'function') return (v as any).toNumber()
60
+ if (v && typeof (v as any).toString === 'function') {
61
+ const n = Number((v as any).toString())
62
+ return Number.isFinite(n) ? n : null
63
+ }
64
+ return null
65
+ }
66
+
67
+ const norm = (v: any) => (v == null ? '' : String(v).trim().toLowerCase())
68
+
69
+ // 🔄 Hydrate product for this plan (plan only has productId)
70
+ const productId = plan.productId
71
+ const {
72
+ data: hydratedProduct,
73
+ isFetching: isFetchingProduct,
74
+ } = useGetOneProductQuery({ id: String(productId) }, { skip: !productId })
75
+
76
+ // 🔒 Only treat as "plan" swap if the hydrated product is a plan
77
+ const isPlanProduct =
78
+ ((hydratedProduct?.type ?? '') as string).toLowerCase() === 'plan'
79
+
80
+ // ---- Get subscriptions (array) without auto-refetch thrash during submit
81
+ const { data: subscriptionData, isFetching: isFetchingSubscription } =
82
+ useGetSubscriptionQuery(undefined, {
83
+ skip: isSubmitted,
84
+ refetchOnFocus: false,
85
+ refetchOnReconnect: false,
86
+ pollingInterval: 0,
87
+ })
88
+
89
+ const subscriptions = useMemo(() => {
90
+ const d: any = subscriptionData
91
+ if (Array.isArray(d?.subscriptions)) return d.subscriptions
92
+ if (d?.subscription) return [d.subscription]
93
+ return []
94
+ }, [subscriptionData])
95
+
96
+ // (A) Same-slug already subscribed? (only meaningful for plan products)
97
+ const subscribeSlug = useMemo(
98
+ () => String(product?.slug || (plan as any)?.product?.slug || plan?.slug || '').trim(),
99
+ [product?.slug, plan?.slug]
100
+ )
101
+ const planSlugNorm = useMemo(() => norm(subscribeSlug), [subscribeSlug])
102
+ const isSubscribedToSameSlug = useMemo(() => {
103
+ if (!isPlanProduct || !planSlugNorm) return false
104
+ return subscriptions.some(
105
+ (s: any) =>
106
+ Array.isArray(s?.productPlans) &&
107
+ s.productPlans.some(
108
+ (pp: any) =>
109
+ norm(pp?.slug) === planSlugNorm && norm(pp?.product?.type) === 'plan'
110
+ )
111
+ )
112
+ }, [subscriptions, planSlugNorm, isPlanProduct])
113
+
114
+ // (B) Any active plan-type subscription (ignore product match to catch upgrades/downgrades)
115
+ const ACTIVE = new Set(['active', 'trialing'])
116
+ const hasAnyPlanTypeActive = useMemo(() => {
117
+ if (!isPlanProduct) return false
118
+ return subscriptions.some((s: any) => {
119
+ if (!ACTIVE.has(String(s?.status))) return false
120
+ const plans = Array.isArray(s?.productPlans) ? s.productPlans : []
121
+ return plans.some((pp: any) => norm(pp?.product?.type) === 'plan')
122
+ })
123
+ }, [subscriptions, isPlanProduct])
124
+
125
+ // 🟦 Identify the active "plan-type" subscription and its plan meta
126
+ const activePlanSub: any | undefined = useMemo(
127
+ () =>
128
+ subscriptions.find((s: any) => {
129
+ if (!ACTIVE.has(String(s?.status))) return false
130
+ const plans = Array.isArray(s?.productPlans) ? s.productPlans : []
131
+ return plans.some((pp: any) => norm(pp?.product?.type) === 'plan')
132
+ }),
133
+ [subscriptions]
134
+ )
135
+
136
+ const previousPlanPP: any | undefined = useMemo(() => {
137
+ const plans = Array.isArray(activePlanSub?.productPlans)
138
+ ? activePlanSub.productPlans
139
+ : []
140
+ return plans.find((pp: any) => norm(pp?.product?.type) === 'plan')
141
+ }, [activePlanSub])
142
+
143
+ // 🪝 Stripe item id (from backend: subscription.subscription_item_id)
144
+ const activePlanSubItemId: string | null = useMemo(
145
+ () =>
146
+ (activePlanSub as any)?.subscriptionItemId ??
147
+ (activePlanSub as any)?.subscription_item_id ??
148
+ null,
149
+ [activePlanSub]
150
+ )
151
+
152
+ // ✅ Swap only if the selected product is a PLAN and either same slug or any active plan exists
153
+ const shouldSwap = isPlanProduct && (isSubscribedToSameSlug || hasAnyPlanTypeActive)
154
+
155
+ // —— PRICE COMPARISON for label ——
156
+ const fmtUSD = (cents?: number | null) =>
157
+ typeof cents === 'number' && Number.isFinite(cents)
158
+ ? currencyPipe(centsToDollars(cents))
159
+ : '—'
160
+
161
+ const getPlanBasePriceCents = (p?: any): number | null => {
162
+ if (!p) return null
163
+ if (p.pricingModel === ProductPlanPricingModel.Fixed) {
164
+ const amt = toNumber(p.amount)
165
+ return typeof amt === 'number' ? Math.round(amt) : null
166
+ }
167
+ const tiers = Array.isArray(p.usageTiers)
168
+ ? [...p.usageTiers].sort((a, b) => (a.rank ?? 0) - (b.rank ?? 0))
169
+ : []
170
+ const flat = tiers.find(
171
+ (t) => toNumber(t.flatFee) && Number(t.flatFee) > 0
172
+ )
173
+ if (flat?.flatFee != null) {
174
+ const feeNum = toNumber(flat.flatFee) ?? 0
175
+ return feeNum >= 100 ? Math.round(feeNum) : Math.round(feeNum * 100)
176
+ }
177
+ const fallback = toNumber(p.amount)
178
+ return typeof fallback === 'number' ? Math.round(fallback) : null
179
+ }
180
+
181
+ const previousAmountCents: number | null = useMemo(() => {
182
+ const subAmt = toNumber(activePlanSub?.amount)
183
+ if (typeof subAmt === 'number') return Math.round(subAmt)
184
+ const ppAmt = toNumber(previousPlanPP?.amount)
185
+ return typeof ppAmt === 'number' ? Math.round(ppAmt) : null
186
+ }, [activePlanSub, previousPlanPP])
187
+
188
+ const previousPlanName = previousPlanPP?.name ?? 'Current plan'
189
+ const newAmountCents = useMemo(
190
+ () => getPlanBasePriceCents(plan),
191
+ [plan]
192
+ )
193
+
194
+ // —— PREVIEW: now sends explicit IDs so server preview == commit ——
195
+ const {
196
+ data: subscriptionPreview,
197
+ isFetching: isFetchingSubscriptionPreview,
198
+ } = useGetUpdateSubscriptionPlanPreviewQuery(
199
+ {
200
+ plan: subscribeSlug as any,
201
+ nextPlanId: plan.id, // ⭐ new deterministic id
202
+ currentPlanId: previousPlanPP?.id, // optional but good
203
+ currentSubscriptionItemId: activePlanSubItemId || undefined, // ⭐ critical
204
+ couponCode: couponCode || undefined,
205
+ },
206
+ {
207
+ skip: isSubmitted || !shouldSwap,
208
+ refetchOnFocus: false,
209
+ refetchOnReconnect: false,
210
+ pollingInterval: 0,
211
+ }
212
+ )
213
+
214
+ const { data: userPaymentMethod } = useGetUserPaymentMethodQuery(
215
+ { userId: user?.id || '' },
216
+ { skip: !user?.id || isSubmitted }
217
+ )
218
+
219
+ const isUpgradeByPrice: boolean | null = useMemo(() => {
220
+ if (previousAmountCents == null || newAmountCents == null) return null
221
+ return newAmountCents > previousAmountCents
222
+ }, [previousAmountCents, newAmountCents])
223
+
224
+ const isUpgrade = useMemo(() => {
225
+ if (isUpgradeByPrice != null) return isUpgradeByPrice
226
+ const amountDue = subscriptionPreview?.amountDue || 0
227
+ return amountDue > 0
228
+ }, [isUpgradeByPrice, subscriptionPreview])
229
+
230
+ const billingSuffix = plan.billingPeriod ? `/${plan.billingPeriod}` : '/month'
231
+
232
+ // 🔹 Generalized price display helper (works for any plan)
233
+ const getDisplayPriceForPlan = (p: ProductPlan): string => {
234
+ const billing = (p as any).billingPeriod
235
+ ? `/${(p as any).billingPeriod}`
236
+ : billingSuffix
237
+
238
+ if (p.pricingModel === ProductPlanPricingModel.Fixed) {
239
+ const amt = toNumber((p as any).amount)
240
+ const basePrice = amt && amt > 0 ? amt.toFixed(2) : null
241
+ return basePrice ? `$${basePrice}${billing}` : 'Free'
242
+ }
243
+
244
+ const tiers = Array.isArray((p as any).usageTiers)
245
+ ? [...(p as any).usageTiers].sort((a, b) => (a.rank ?? 0) - (b.rank ?? 0))
246
+ : []
247
+
248
+ const flatFeeTier = tiers.find(
249
+ (t) => toNumber(t.flatFee) && Number(t.flatFee) > 0
250
+ )
251
+
252
+ let flatFeeValue = 0
253
+ if (flatFeeTier?.flatFee != null) {
254
+ const feeNum = toNumber(flatFeeTier.flatFee) ?? 0
255
+ flatFeeValue = feeNum >= 100 ? feeNum / 100 : feeNum
256
+ }
257
+
258
+ if (!flatFeeValue) {
259
+ const amt = toNumber((p as any).amount) ?? 0
260
+ flatFeeValue = amt
261
+ }
262
+
263
+ const basePrice = flatFeeValue > 0 ? flatFeeValue.toFixed(2) : null
264
+ return basePrice ? `$${basePrice}${billing}` : 'Free'
265
+ }
266
+
267
+ // Backwards-compatible wrapper for existing usage
268
+ const getDisplayPrice = () => getDisplayPriceForPlan(plan)
269
+
270
+ // 🔹 Bundle-aware summary: which plans should we show in the card?
271
+ const selectedPlansForSummary: ProductPlan[] = useMemo(() => {
272
+ if (!isBundle || !Array.isArray(bundlePlans) || bundlePlans.length === 0) {
273
+ return [plan]
274
+ }
275
+ const slugSet = new Set(
276
+ (selectedPlanSlugs || []).map((s) => String(s).toLowerCase())
277
+ )
278
+ if (slugSet.size === 0) {
279
+ return bundlePlans
280
+ }
281
+ return bundlePlans.filter((p: any) =>
282
+ slugSet.has(String(p.slug).toLowerCase())
283
+ )
284
+ }, [isBundle, bundlePlans, selectedPlanSlugs, plan])
285
+
286
+ const selectedPlanIds = useMemo(
287
+ () => selectedPlansForSummary.map((p) => p.id),
288
+ [selectedPlansForSummary]
289
+ )
290
+
291
+ const selectedPlanSlugsForSubscribe = useMemo(
292
+ () => selectedPlansForSummary.map((p: any) => String(p.slug)),
293
+ [selectedPlansForSummary]
294
+ )
295
+
296
+ const itemCount = selectedPlansForSummary.length
297
+ const isBundleDisplay =
298
+ isBundle && itemCount > 1 && !shouldSwap // never override swap preview
299
+
300
+ const bundleSubtotalCents = useMemo(
301
+ () =>
302
+ selectedPlansForSummary.reduce((sum, p) => {
303
+ const cents = getPlanBasePriceCents(p as any)
304
+ return sum + (cents ?? 0)
305
+ }, 0),
306
+ [selectedPlansForSummary]
307
+ )
308
+
309
+ const bundleSubtotalLabel = useMemo(() => {
310
+ if (!isBundleDisplay || bundleSubtotalCents <= 0) return getDisplayPrice()
311
+ return `${fmtUSD(bundleSubtotalCents)}${billingSuffix}`
312
+ }, [isBundleDisplay, bundleSubtotalCents, billingSuffix])
313
+
314
+ const { data: _userPaymentMethod } = { data: userPaymentMethod } // keep name below
315
+
316
+ const onSubscribe = async () => {
317
+ try {
318
+ if (!subscribeSlug) {
319
+ toast.error('Plan is missing. Please select a plan and try again.')
320
+ return
321
+ }
322
+
323
+ setIsSubmitted(true)
324
+
325
+ if (shouldSwap) {
326
+ await updateSubscriptionPlan({
327
+ plan: subscribeSlug as any,
328
+ couponCode: couponCode || undefined,
329
+ nextPlanId: plan.id,
330
+ currentPlanId: previousPlanPP?.id,
331
+ currentSubscriptionItemId: activePlanSubItemId || undefined,
332
+ }).unwrap()
333
+ } else {
334
+ await subscribe({
335
+ plan: subscribeSlug as any,
336
+ planSlugs: selectedPlanSlugsForSubscribe, // all sub-plan slugs
337
+ couponCode: couponCode || undefined,
338
+ }).unwrap()
339
+ }
340
+
341
+ if (user) {
342
+ identifyUserForCustomerIO(user, plan.slug)
343
+ }
344
+ trackEvent('subscription_updated', { plan_name: plan.slug })
345
+
346
+ toast.success('Your order has been successfully placed!')
347
+ router.replace('/')
348
+ } catch (error) {
349
+ toast.error(DEFAULT_ERROR_MESSAGE)
350
+ setIsSubmitted(false)
351
+ }
352
+ }
353
+
354
+ return (
355
+ <div className="w-100 bg-background rounded-md p-3 p-xl-4">
356
+ <div className="d-flex align-items-center justify-content-between">
357
+ <h2 className="h4 fw-bold mb-3">Order Summary</h2>
358
+ <Link
359
+ href="/pricing"
360
+ className="text-primary text-decoration-underline"
361
+ >
362
+ Edit Order
363
+ </Link>
364
+ </div>
365
+
366
+ {isFetchingProduct ||
367
+ isFetchingSubscription ||
368
+ isFetchingSubscriptionPreview ? (
369
+ <div className="w-100 d-flex justify-content-center py-4">
370
+ <Spinner color="primary" />
371
+ </div>
372
+ ) : (
373
+ <>
374
+ {/* Only show swap/credit banner for plan swaps */}
375
+ {shouldSwap && subscriptionPreview && (
376
+ <div className="alert alert-warning p-2" role="alert">
377
+ {(() => {
378
+ const amountDue = subscriptionPreview.amountDue || 0
379
+ const credit = subscriptionPreview.credit || 0
380
+ const label = isUpgrade ? 'upgrade' : 'downgrade'
381
+ const prevAmt = previousAmountCents
382
+ const nextAmt = newAmountCents
383
+
384
+ const fmt = (c?: number | null) =>
385
+ typeof c === 'number' && Number.isFinite(c)
386
+ ? currencyPipe(centsToDollars(c))
387
+ : '—'
388
+
389
+ return (
390
+ <>
391
+ <p className="small mb-2">
392
+ You are moving from <strong>{previousPlanName}</strong>{' '}
393
+ {prevAmt != null ? `(${fmt(prevAmt)}/mo)` : ''} to{' '}
394
+ <strong>{plan.name}</strong>{' '}
395
+ {nextAmt != null ? `(${fmt(nextAmt)}/mo)` : ''}. This is
396
+ classified as an <strong>{label}</strong>.
397
+ </p>
398
+
399
+ {isUpgrade ? (
400
+ <>
401
+ <p className="small mb-2">
402
+ We’ll apply a credit of{' '}
403
+ <span className="fw-bold">{fmt(credit)}</span> from
404
+ your existing plan toward the cost of your new plan.
405
+ Any remaining balance will be charged once you confirm
406
+ the change.
407
+ </p>
408
+ <p className="mb-0 small">
409
+ Your card will be charged{' '}
410
+ <span className="fw-bold">{fmt(amountDue)}</span> for
411
+ the {label}.
412
+ </p>
413
+ </>
414
+ ) : (
415
+ <>
416
+ <p className="small mb-0">
417
+ A credit of{' '}
418
+ <span className="fw-bold">{fmt(credit)}</span> will be
419
+ applied for the difference between your previous and
420
+ new plans. You won’t be charged now.
421
+ </p>
422
+ </>
423
+ )}
424
+ </>
425
+ )
426
+ })()}
427
+ </div>
428
+ )}
429
+
430
+ <div className="mb-3">
431
+ <CouponCodeForm plans={selectedPlansForSummary} variant="inline" />
432
+ </div>
433
+
434
+ {/* 🔹 Items count (bundle-aware) */}
435
+ <div className="d-flex justify-content-between">
436
+ <span className="fw-bold d-block">
437
+ {itemCount} {itemCount === 1 ? 'Item' : 'Items'}
438
+ </span>
439
+ </div>
440
+
441
+ {/* 🔹 Line items (bundle-aware) */}
442
+ <div className="mt-3">
443
+ {selectedPlansForSummary.map((p) => (
444
+ <div
445
+ key={p.id}
446
+ className="d-flex align-items-center justify-content-between py-1"
447
+ >
448
+ <p className="mb-0">{p.name}</p>
449
+ <p className="mb-0">{getDisplayPriceForPlan(p)}</p>
450
+ </div>
451
+ ))}
452
+ </div>
453
+
454
+ <hr className="text-light-gray opacity-100" />
455
+
456
+ {/* 🔹 Subtotal (bundle-aware, but swap-preview wins if present) */}
457
+ <div className="d-flex align-items-center justify-content-between">
458
+ <p className="mb-0">Subtotal</p>
459
+ <p className="mb-0">
460
+ {shouldSwap && subscriptionPreview
461
+ ? currencyPipe(centsToDollars(subscriptionPreview.amountDue))
462
+ : appliedCoupon
463
+ ? currencyPipe(centsToDollars(appliedCoupon.subtotal))
464
+ : isBundleDisplay
465
+ ? bundleSubtotalLabel
466
+ : getDisplayPrice()}
467
+ </p>
468
+ </div>
469
+
470
+ {appliedCoupon && !shouldSwap ? (
471
+ <>
472
+ <hr className="text-light-gray opacity-100" />
473
+ <div className="d-flex align-items-center justify-content-between text-success">
474
+ <p className="mb-0">Coupon ({appliedCoupon.code})</p>
475
+ <p className="mb-0">-{currencyPipe(centsToDollars(appliedCoupon.discountAmount))}</p>
476
+ </div>
477
+ </>
478
+ ) : null}
479
+
480
+ <hr className="text-light-gray opacity-100" />
481
+
482
+ {/* 🔹 Total (same logic as subtotal) */}
483
+ <div className="d-flex align-items-center justify-content-between">
484
+ <h2 className="h4 fw-bold mb-0">
485
+ Total <small className="fw-light fs-dec-85">(USD)</small>
486
+ </h2>
487
+ <h2 className="h4 mb-0">
488
+ {shouldSwap && subscriptionPreview
489
+ ? currencyPipe(centsToDollars(subscriptionPreview.amountDue))
490
+ : appliedCoupon
491
+ ? currencyPipe(centsToDollars(appliedCoupon.total))
492
+ : isBundleDisplay
493
+ ? bundleSubtotalLabel
494
+ : getDisplayPrice()}
495
+ </h2>
496
+ </div>
497
+
498
+ <Button
499
+ type="button"
500
+ className="w-100 no-min-size h2 py-2 mt-4 text-white"
501
+ color="success"
502
+ disabled={
503
+ !isBillingCompleted ||
504
+ !userPaymentMethod ||
505
+ isLoadingSubscribe ||
506
+ isLoadingSubscriptionChange ||
507
+ isSubmitted ||
508
+ isFetchingProduct
509
+ }
510
+ isLoading={isLoadingSubscribe || isLoadingSubscriptionChange}
511
+ onClick={onSubscribe}
512
+ >
513
+ {shouldSwap ? 'Complete Upgrade' : 'Complete Purchase'}
514
+ </Button>
515
+
516
+ <p className="mt-4 mb-0 small">
517
+ By clicking &quot;Complete {shouldSwap ? 'Upgrade' : 'Purchase'}
518
+ &quot;, you agree to the{' '}
519
+ <Link
520
+ href="/terms"
521
+ className="text-dark text-decoration-underline fw-bold"
522
+ target="_blank"
523
+ rel="noopener noreferrer"
524
+ >
525
+ Terms &amp; Conditions
526
+ </Link>{' '}
527
+ and{' '}
528
+ <Link
529
+ href="/privacy"
530
+ className="text-dark text-decoration-underline fw-bold"
531
+ target="_blank"
532
+ rel="noopener noreferrer"
533
+ >
534
+ Privacy Policy
535
+ </Link>{' '}
536
+ and consent to enroll your product(s) in our automatic renewal
537
+ service, which can be cancelled at any time. Your payment is being
538
+ processed in the United States.
539
+ </p>
540
+ </>
541
+ )}
542
+ </div>
543
+ )
544
+ }
545
+
546
+ export default CompletePurchase
@@ -0,0 +1,76 @@
1
+ import React, { useEffect, useRef, useState } from 'react'
2
+ import { ProductPlan, ProductPlanType } from '@store/model'
3
+ import { useDisclosure } from '@chakra-ui/react'
4
+ import { currencyPipe } from '@helpers/string'
5
+
6
+ export const PlanPicker = ({
7
+ plans,
8
+ onChange,
9
+ } : {
10
+ plans: ProductPlan[]
11
+ onChange: (plan: ProductPlan) => void
12
+ }) => {
13
+ const pickerRef = useRef<HTMLDivElement | null>(null);
14
+
15
+ const {
16
+ isOpen,
17
+ onClose,
18
+ onToggle,
19
+ } = useDisclosure()
20
+
21
+ const [plan, setPlan] = useState(plans[0])
22
+
23
+ useEffect(() => {
24
+ const handleClickOutside = (event: MouseEvent) => {
25
+ if (pickerRef.current && !pickerRef.current.contains(event.target as Node)) {
26
+ onClose()
27
+ }
28
+ };
29
+
30
+ if (isOpen) {
31
+ document.addEventListener('click', handleClickOutside);
32
+ } else {
33
+ document.removeEventListener('click', handleClickOutside);
34
+ }
35
+
36
+ return () => {
37
+ document.removeEventListener('click', handleClickOutside);
38
+ };
39
+ }, [isOpen, onClose]);
40
+
41
+ return (
42
+ <div ref={pickerRef} className='w-xs-300p position-relative w-100'>
43
+ <div onClick={onToggle} className='border p-2 d-flex justify-content-between align-items-center pointer'>
44
+ <p className='mb-0'>{plan.name}</p>
45
+ <div>
46
+ <span className='fw-bold lead'>{currencyPipe(plan.amount)}</span>
47
+ <span>{plan.type === ProductPlanType.Recurring ? `/${plan.billingPeriod}` : ''}</span>
48
+ <span className={`bi bi-chevron-${isOpen ? 'up' : 'down' } opacity-7 ms-3`}></span>
49
+ </div>
50
+ </div>
51
+ {isOpen && (
52
+ <div className='position-absolute bottom-n3r left-0 right-0 bg-white shadow-xs fadeIn rounded overflow-hidden'>
53
+ {plans.filter(p => p.id !== plan.id).map((item, key) => (
54
+ <div onClick={() => {
55
+ setPlan(item)
56
+ onChange(item)
57
+ onClose()
58
+ }}
59
+ key={key}
60
+ role='button'
61
+ className='d-flex align-items-center justify-content-between gap-2 border-bottom p-2 w-100 bg-hover-background pointer'
62
+ >
63
+ <div className='d-flex align-items-center gap-2'>
64
+ <p className='mb-0'>{item.name}</p>
65
+ <div>
66
+ <span className='fw-bold lead'>{currencyPipe(item.amount)}</span>
67
+ <span>{item.type === ProductPlanType.Recurring ? `/${item.billingPeriod}` : ''}</span>
68
+ </div>
69
+ </div>
70
+ </div>
71
+ ))}
72
+ </div>
73
+ )}
74
+ </div>
75
+ )
76
+ }