@vendure/dashboard 3.2.0 → 3.2.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 (381) hide show
  1. package/LICENSE.md +42 -0
  2. package/README.md +12 -12
  3. package/index.html +15 -15
  4. package/lingui.config.js +12 -12
  5. package/package.json +11 -2
  6. package/src/app/app-providers.tsx +30 -30
  7. package/src/app/main.tsx +97 -97
  8. package/src/app/routes/__root.tsx +24 -24
  9. package/src/app/routes/_authenticated/_administrators/administrators.graphql.ts +79 -79
  10. package/src/app/routes/_authenticated/_administrators/administrators.tsx +86 -86
  11. package/src/app/routes/_authenticated/_administrators/administrators_.$id.tsx +155 -155
  12. package/src/app/routes/_authenticated/_administrators/components/role-permissions-display.tsx +133 -133
  13. package/src/app/routes/_authenticated/_assets/assets.tsx +19 -19
  14. package/src/app/routes/_authenticated/_channels/channels.graphql.ts +93 -93
  15. package/src/app/routes/_authenticated/_channels/channels.tsx +60 -60
  16. package/src/app/routes/_authenticated/_channels/channels_.$id.tsx +248 -248
  17. package/src/app/routes/_authenticated/_collections/collections.graphql.ts +133 -133
  18. package/src/app/routes/_authenticated/_collections/collections.tsx +195 -195
  19. package/src/app/routes/_authenticated/_collections/collections_.$id.tsx +224 -224
  20. package/src/app/routes/_authenticated/_collections/components/collection-contents-preview-table.tsx +127 -127
  21. package/src/app/routes/_authenticated/_collections/components/collection-contents-sheet.tsx +46 -46
  22. package/src/app/routes/_authenticated/_collections/components/collection-contents-table.tsx +82 -82
  23. package/src/app/routes/_authenticated/_collections/components/collection-filters-selector.tsx +91 -91
  24. package/src/app/routes/_authenticated/_countries/countries.graphql.ts +69 -69
  25. package/src/app/routes/_authenticated/_countries/countries.tsx +67 -67
  26. package/src/app/routes/_authenticated/_countries/countries_.$id.tsx +122 -122
  27. package/src/app/routes/_authenticated/_customer-groups/components/customer-group-members-sheet.tsx +44 -44
  28. package/src/app/routes/_authenticated/_customer-groups/components/customer-group-members-table.tsx +129 -129
  29. package/src/app/routes/_authenticated/_customer-groups/customer-groups.graphql.ts +71 -71
  30. package/src/app/routes/_authenticated/_customer-groups/customer-groups.tsx +68 -68
  31. package/src/app/routes/_authenticated/_customer-groups/customer-groups_.$id.tsx +111 -111
  32. package/src/app/routes/_authenticated/_customers/components/customer-address-card.tsx +155 -155
  33. package/src/app/routes/_authenticated/_customers/components/customer-address-form.tsx +344 -344
  34. package/src/app/routes/_authenticated/_customers/components/customer-group-controls.tsx +4 -4
  35. package/src/app/routes/_authenticated/_customers/components/customer-history/customer-history-container.tsx +78 -78
  36. package/src/app/routes/_authenticated/_customers/components/customer-history/customer-history.tsx +77 -77
  37. package/src/app/routes/_authenticated/_customers/components/customer-history/index.ts +3 -3
  38. package/src/app/routes/_authenticated/_customers/components/customer-history/use-customer-history.ts +169 -169
  39. package/src/app/routes/_authenticated/_customers/components/customer-order-table.tsx +88 -88
  40. package/src/app/routes/_authenticated/_customers/components/customer-status-badge.tsx +33 -33
  41. package/src/app/routes/_authenticated/_customers/customers.graphql.ts +204 -204
  42. package/src/app/routes/_authenticated/_customers/customers.tsx +82 -82
  43. package/src/app/routes/_authenticated/_customers/customers_.$id.tsx +274 -274
  44. package/src/app/routes/_authenticated/_facets/components/edit-facet-value.tsx +129 -129
  45. package/src/app/routes/_authenticated/_facets/components/facet-values-sheet.tsx +46 -46
  46. package/src/app/routes/_authenticated/_facets/components/facet-values-table.tsx +97 -97
  47. package/src/app/routes/_authenticated/_facets/facets.graphql.ts +104 -104
  48. package/src/app/routes/_authenticated/_facets/facets.tsx +97 -97
  49. package/src/app/routes/_authenticated/_facets/facets_.$id.tsx +139 -139
  50. package/src/app/routes/_authenticated/_global-settings/global-settings.graphql.ts +28 -28
  51. package/src/app/routes/_authenticated/_global-settings/global-settings.tsx +161 -161
  52. package/src/app/routes/_authenticated/_orders/components/order-address.tsx +58 -58
  53. package/src/app/routes/_authenticated/_orders/components/order-history/index.ts +3 -3
  54. package/src/app/routes/_authenticated/_orders/components/order-history/order-history-container.tsx +72 -72
  55. package/src/app/routes/_authenticated/_orders/components/order-history/order-history.tsx +96 -96
  56. package/src/app/routes/_authenticated/_orders/components/order-history/use-order-history.ts +171 -171
  57. package/src/app/routes/_authenticated/_orders/components/order-table.tsx +169 -169
  58. package/src/app/routes/_authenticated/_orders/components/order-tax-summary.tsx +38 -38
  59. package/src/app/routes/_authenticated/_orders/components/payment-details.tsx +61 -61
  60. package/src/app/routes/_authenticated/_orders/orders.graphql.ts +325 -325
  61. package/src/app/routes/_authenticated/_orders/orders.tsx +120 -120
  62. package/src/app/routes/_authenticated/_orders/orders_.$id.tsx +133 -133
  63. package/src/app/routes/_authenticated/_payment-methods/components/payment-eligibility-checker-selector.tsx +104 -104
  64. package/src/app/routes/_authenticated/_payment-methods/components/payment-handler-selector.tsx +100 -100
  65. package/src/app/routes/_authenticated/_payment-methods/payment-methods.graphql.ts +83 -83
  66. package/src/app/routes/_authenticated/_payment-methods/payment-methods.tsx +64 -64
  67. package/src/app/routes/_authenticated/_payment-methods/payment-methods_.$id.tsx +183 -183
  68. package/src/app/routes/_authenticated/_product-variants/components/variant-price-detail.tsx +87 -87
  69. package/src/app/routes/_authenticated/_product-variants/product-variants.graphql.ts +123 -123
  70. package/src/app/routes/_authenticated/_product-variants/product-variants.tsx +78 -78
  71. package/src/app/routes/_authenticated/_product-variants/product-variants_.$id.tsx +331 -331
  72. package/src/app/routes/_authenticated/_products/components/create-product-variants-dialog.tsx +228 -228
  73. package/src/app/routes/_authenticated/_products/components/create-product-variants.tsx +462 -462
  74. package/src/app/routes/_authenticated/_products/components/option-value-input.tsx +95 -95
  75. package/src/app/routes/_authenticated/_products/components/product-variants-table.tsx +87 -87
  76. package/src/app/routes/_authenticated/_products/products.graphql.ts +116 -116
  77. package/src/app/routes/_authenticated/_products/products.tsx +48 -48
  78. package/src/app/routes/_authenticated/_products/products_.$id.tsx +196 -196
  79. package/src/app/routes/_authenticated/_profile/profile.graphql.ts +23 -23
  80. package/src/app/routes/_authenticated/_profile/profile.tsx +122 -122
  81. package/src/app/routes/_authenticated/_promotions/components/promotion-actions-selector.tsx +107 -107
  82. package/src/app/routes/_authenticated/_promotions/components/promotion-conditions-selector.tsx +107 -107
  83. package/src/app/routes/_authenticated/_promotions/promotions.graphql.ts +96 -96
  84. package/src/app/routes/_authenticated/_promotions/promotions.tsx +61 -61
  85. package/src/app/routes/_authenticated/_promotions/promotions_.$id.tsx +235 -235
  86. package/src/app/routes/_authenticated/_roles/components/expandable-permissions.tsx +54 -54
  87. package/src/app/routes/_authenticated/_roles/components/permissions-grid.tsx +116 -116
  88. package/src/app/routes/_authenticated/_roles/roles.graphql.ts +67 -67
  89. package/src/app/routes/_authenticated/_roles/roles.tsx +96 -96
  90. package/src/app/routes/_authenticated/_roles/roles_.$id.tsx +142 -142
  91. package/src/app/routes/_authenticated/_sellers/sellers.graphql.ts +61 -61
  92. package/src/app/routes/_authenticated/_sellers/sellers.tsx +51 -51
  93. package/src/app/routes/_authenticated/_sellers/sellers_.$id.tsx +111 -111
  94. package/src/app/routes/_authenticated/_shipping-methods/components/fulfillment-handler-selector.tsx +56 -56
  95. package/src/app/routes/_authenticated/_shipping-methods/components/shipping-calculator-selector.tsx +101 -101
  96. package/src/app/routes/_authenticated/_shipping-methods/components/shipping-eligibility-checker-selector.tsx +101 -101
  97. package/src/app/routes/_authenticated/_shipping-methods/components/test-shipping-method-dialog.tsx +32 -32
  98. package/src/app/routes/_authenticated/_shipping-methods/shipping-methods.graphql.ts +83 -83
  99. package/src/app/routes/_authenticated/_shipping-methods/shipping-methods.tsx +55 -55
  100. package/src/app/routes/_authenticated/_shipping-methods/shipping-methods_.$id.tsx +171 -171
  101. package/src/app/routes/_authenticated/_stock-locations/stock-locations.graphql.ts +62 -62
  102. package/src/app/routes/_authenticated/_stock-locations/stock-locations.tsx +48 -48
  103. package/src/app/routes/_authenticated/_stock-locations/stock-locations_.$id.tsx +115 -115
  104. package/src/app/routes/_authenticated/_system/components/payload-dialog.tsx +34 -34
  105. package/src/app/routes/_authenticated/_system/healthchecks.tsx +93 -93
  106. package/src/app/routes/_authenticated/_system/job-queue.graphql.ts +43 -43
  107. package/src/app/routes/_authenticated/_system/job-queue.tsx +161 -161
  108. package/src/app/routes/_authenticated/_tax-categories/tax-categories.graphql.ts +63 -63
  109. package/src/app/routes/_authenticated/_tax-categories/tax-categories.tsx +65 -65
  110. package/src/app/routes/_authenticated/_tax-categories/tax-categories_.$id.tsx +115 -115
  111. package/src/app/routes/_authenticated/_tax-rates/tax-rates.graphql.ts +75 -75
  112. package/src/app/routes/_authenticated/_tax-rates/tax-rates.tsx +108 -108
  113. package/src/app/routes/_authenticated/_tax-rates/tax-rates_.$id.tsx +148 -148
  114. package/src/app/routes/_authenticated/_zones/components/zone-countries-sheet.tsx +31 -31
  115. package/src/app/routes/_authenticated/_zones/components/zone-countries-table.tsx +79 -79
  116. package/src/app/routes/_authenticated/_zones/zones.graphql.ts +96 -96
  117. package/src/app/routes/_authenticated/_zones/zones.tsx +57 -57
  118. package/src/app/routes/_authenticated/_zones/zones_.$id.tsx +103 -103
  119. package/src/app/routes/_authenticated/index.tsx +194 -194
  120. package/src/app/routes/_authenticated.tsx +25 -25
  121. package/src/app/routes/login.tsx +48 -48
  122. package/src/app/styles.css +82 -82
  123. package/src/app/tailwindcss-animate.css +275 -275
  124. package/src/i18n/locales/de.po +1579 -1579
  125. package/src/i18n/locales/en.po +1579 -1579
  126. package/src/lib/components/data-display/boolean.tsx +23 -23
  127. package/src/lib/components/data-display/date-time.tsx +13 -13
  128. package/src/lib/components/data-display/json.tsx +5 -5
  129. package/src/lib/components/data-display/money.tsx +15 -15
  130. package/src/lib/components/data-input/affixed-input.tsx +49 -49
  131. package/src/lib/components/data-input/customer-group-input.tsx +72 -72
  132. package/src/lib/components/data-input/datetime-input.tsx +149 -149
  133. package/src/lib/components/data-input/facet-value-input.tsx +68 -68
  134. package/src/lib/components/data-input/money-input.tsx +112 -112
  135. package/src/lib/components/data-input/richt-text-input.tsx +99 -99
  136. package/src/lib/components/data-table/data-table-column-header.tsx +73 -73
  137. package/src/lib/components/data-table/data-table-faceted-filter.tsx +172 -172
  138. package/src/lib/components/data-table/data-table-filter-dialog.tsx +73 -73
  139. package/src/lib/components/data-table/data-table-pagination.tsx +87 -87
  140. package/src/lib/components/data-table/data-table-view-options.tsx +53 -53
  141. package/src/lib/components/data-table/data-table.tsx +218 -218
  142. package/src/lib/components/layout/app-layout.tsx +42 -42
  143. package/src/lib/components/layout/app-sidebar.tsx +34 -34
  144. package/src/lib/components/layout/channel-switcher.tsx +87 -87
  145. package/src/lib/components/layout/content-language-selector.tsx +41 -41
  146. package/src/lib/components/layout/generated-breadcrumbs.tsx +82 -82
  147. package/src/lib/components/layout/language-dialog.tsx +104 -104
  148. package/src/lib/components/layout/nav-main.tsx +178 -178
  149. package/src/lib/components/layout/nav-projects.tsx +81 -81
  150. package/src/lib/components/layout/nav-user.tsx +176 -176
  151. package/src/lib/components/layout/prerelease-popup.tsx +38 -38
  152. package/src/lib/components/login/login-form.tsx +173 -173
  153. package/src/lib/components/shared/alerts.tsx +20 -20
  154. package/src/lib/components/shared/animated-number.tsx +49 -49
  155. package/src/lib/components/shared/asset-gallery.tsx +433 -433
  156. package/src/lib/components/shared/asset-picker-dialog.tsx +71 -71
  157. package/src/lib/components/shared/asset-preview-dialog.tsx +48 -48
  158. package/src/lib/components/shared/asset-preview.tsx +345 -345
  159. package/src/lib/components/shared/assigned-facet-values.tsx +68 -68
  160. package/src/lib/components/shared/channel-code-label.tsx +7 -7
  161. package/src/lib/components/shared/channel-selector.tsx +51 -51
  162. package/src/lib/components/shared/configurable-operation-arg-input.tsx +51 -51
  163. package/src/lib/components/shared/configurable-operation-input.tsx +133 -133
  164. package/src/lib/components/shared/confirmation-dialog.tsx +58 -58
  165. package/src/lib/components/shared/copyable-text.tsx +31 -31
  166. package/src/lib/components/shared/country-selector.tsx +105 -105
  167. package/src/lib/components/shared/currency-selector.tsx +33 -33
  168. package/src/lib/components/shared/custom-fields-form.tsx +86 -86
  169. package/src/lib/components/shared/customer-address-form.tsx +330 -330
  170. package/src/lib/components/shared/customer-group-chip.tsx +30 -30
  171. package/src/lib/components/shared/customer-group-selector.tsx +62 -62
  172. package/src/lib/components/shared/customer-selector.tsx +107 -107
  173. package/src/lib/components/shared/detail-page-button.tsx +22 -22
  174. package/src/lib/components/shared/entity-assets.tsx +340 -340
  175. package/src/lib/components/shared/error-page.tsx +31 -31
  176. package/src/lib/components/shared/facet-value-chip.tsx +44 -44
  177. package/src/lib/components/shared/facet-value-selector.tsx +306 -306
  178. package/src/lib/components/shared/focal-point-control.tsx +64 -64
  179. package/src/lib/components/shared/form-field-wrapper.tsx +37 -37
  180. package/src/lib/components/shared/history-timeline/history-entry.tsx +112 -112
  181. package/src/lib/components/shared/history-timeline/history-note-checkbox.tsx +28 -28
  182. package/src/lib/components/shared/history-timeline/history-note-editor.tsx +60 -60
  183. package/src/lib/components/shared/history-timeline/history-note-input.tsx +39 -39
  184. package/src/lib/components/shared/history-timeline/history-timeline.tsx +56 -56
  185. package/src/lib/components/shared/icon-mark.tsx +18 -18
  186. package/src/lib/components/shared/language-selector.tsx +48 -48
  187. package/src/lib/components/shared/logo-mark.tsx +24 -24
  188. package/src/lib/components/shared/multi-select.tsx +159 -159
  189. package/src/lib/components/shared/option-value-input.tsx +94 -94
  190. package/src/lib/components/shared/paginated-list-data-table.tsx +520 -520
  191. package/src/lib/components/shared/permission-guard.tsx +20 -20
  192. package/src/lib/components/shared/role-code-label.tsx +8 -8
  193. package/src/lib/components/shared/role-selector.tsx +56 -56
  194. package/src/lib/components/shared/seller-selector.tsx +107 -107
  195. package/src/lib/components/shared/tax-category-selector.tsx +65 -65
  196. package/src/lib/components/shared/translatable-form-field.tsx +74 -74
  197. package/src/lib/components/shared/vendure-image.tsx +159 -159
  198. package/src/lib/components/shared/zone-selector.tsx +66 -66
  199. package/src/lib/components/ui/accordion.tsx +59 -59
  200. package/src/lib/components/ui/alert-dialog.tsx +128 -128
  201. package/src/lib/components/ui/alert.tsx +60 -60
  202. package/src/lib/components/ui/avatar.tsx +38 -38
  203. package/src/lib/components/ui/badge.tsx +38 -38
  204. package/src/lib/components/ui/breadcrumb.tsx +102 -102
  205. package/src/lib/components/ui/button.tsx +51 -51
  206. package/src/lib/components/ui/calendar.tsx +69 -69
  207. package/src/lib/components/ui/card.tsx +47 -47
  208. package/src/lib/components/ui/checkbox.tsx +27 -27
  209. package/src/lib/components/ui/collapsible.tsx +33 -33
  210. package/src/lib/components/ui/command.tsx +133 -133
  211. package/src/lib/components/ui/dialog.tsx +116 -116
  212. package/src/lib/components/ui/dropdown-menu.tsx +220 -220
  213. package/src/lib/components/ui/form.tsx +141 -141
  214. package/src/lib/components/ui/hover-card.tsx +36 -36
  215. package/src/lib/components/ui/input.tsx +19 -19
  216. package/src/lib/components/ui/label.tsx +21 -21
  217. package/src/lib/components/ui/pagination.tsx +127 -127
  218. package/src/lib/components/ui/popover.tsx +40 -40
  219. package/src/lib/components/ui/scroll-area.tsx +50 -50
  220. package/src/lib/components/ui/select.tsx +161 -161
  221. package/src/lib/components/ui/separator.tsx +26 -26
  222. package/src/lib/components/ui/sheet.tsx +118 -118
  223. package/src/lib/components/ui/sidebar.tsx +696 -696
  224. package/src/lib/components/ui/skeleton.tsx +13 -13
  225. package/src/lib/components/ui/sonner.tsx +27 -27
  226. package/src/lib/components/ui/switch.tsx +26 -26
  227. package/src/lib/components/ui/table.tsx +82 -82
  228. package/src/lib/components/ui/tabs.tsx +48 -48
  229. package/src/lib/components/ui/textarea.tsx +18 -18
  230. package/src/lib/components/ui/tooltip.tsx +51 -51
  231. package/src/lib/constants.ts +326 -326
  232. package/src/lib/framework/component-registry/component-registry.tsx +70 -70
  233. package/src/lib/framework/component-registry/dynamic-component.tsx +58 -58
  234. package/src/lib/framework/dashboard-widget/base-widget.tsx +97 -97
  235. package/src/lib/framework/dashboard-widget/latest-orders-widget/index.tsx +96 -96
  236. package/src/lib/framework/dashboard-widget/latest-orders-widget/latest-orders-widget.graphql.ts +35 -35
  237. package/src/lib/framework/dashboard-widget/metrics-widget/chart.tsx +24 -24
  238. package/src/lib/framework/dashboard-widget/metrics-widget/index.tsx +82 -82
  239. package/src/lib/framework/dashboard-widget/metrics-widget/metrics-widget.graphql.ts +14 -14
  240. package/src/lib/framework/dashboard-widget/orders-summary/index.tsx +167 -167
  241. package/src/lib/framework/dashboard-widget/orders-summary/order-summary-widget.graphql.ts +14 -14
  242. package/src/lib/framework/dashboard-widget/types.ts +22 -22
  243. package/src/lib/framework/dashboard-widget/widget-extensions.tsx +19 -19
  244. package/src/lib/framework/defaults.ts +219 -219
  245. package/src/lib/framework/document-introspection/add-custom-fields.spec.ts +242 -242
  246. package/src/lib/framework/document-introspection/add-custom-fields.ts +246 -246
  247. package/src/lib/framework/document-introspection/get-document-structure.spec.ts +310 -310
  248. package/src/lib/framework/document-introspection/get-document-structure.ts +460 -460
  249. package/src/lib/framework/document-introspection/hooks.ts +10 -10
  250. package/src/lib/framework/extension-api/define-dashboard-extension.ts +66 -66
  251. package/src/lib/framework/extension-api/extension-api-types.ts +58 -58
  252. package/src/lib/framework/extension-api/use-dashboard-extensions.ts +26 -26
  253. package/src/lib/framework/form-engine/form-schema-tools.ts +98 -98
  254. package/src/lib/framework/form-engine/use-generated-form.tsx +116 -116
  255. package/src/lib/framework/layout-engine/layout-extensions.ts +30 -30
  256. package/src/lib/framework/layout-engine/location-wrapper.tsx +96 -96
  257. package/src/lib/framework/layout-engine/page-layout.tsx +272 -272
  258. package/src/lib/framework/nav-menu/nav-menu-extensions.ts +66 -66
  259. package/src/lib/framework/page/detail-page-route-loader.tsx +48 -48
  260. package/src/lib/framework/page/detail-page.tsx +131 -131
  261. package/src/lib/framework/page/list-page.tsx +166 -166
  262. package/src/lib/framework/page/page-api.ts +9 -9
  263. package/src/lib/framework/page/page-types.ts +51 -51
  264. package/src/lib/framework/page/use-detail-page.ts +217 -217
  265. package/src/lib/framework/page/use-extended-router.tsx +69 -69
  266. package/src/lib/framework/registry/global-registry.ts +46 -46
  267. package/src/lib/framework/registry/registry-types.ts +15 -15
  268. package/src/lib/graphql/api.ts +61 -61
  269. package/src/lib/graphql/fragments.tsx +54 -54
  270. package/src/lib/graphql/graphql-env.d.ts +499 -499
  271. package/src/lib/graphql/graphql.ts +15 -15
  272. package/src/lib/hooks/use-auth.tsx +11 -11
  273. package/src/lib/hooks/use-channel.ts +12 -12
  274. package/src/lib/hooks/use-custom-field-config.ts +10 -10
  275. package/src/lib/hooks/use-grouped-permissions.ts +54 -54
  276. package/src/lib/hooks/use-local-format.ts +119 -119
  277. package/src/lib/hooks/use-mobile.ts +19 -19
  278. package/src/lib/hooks/use-page.tsx +10 -10
  279. package/src/lib/hooks/use-permissions.ts +22 -22
  280. package/src/lib/hooks/use-server-config.ts +4 -4
  281. package/src/lib/hooks/use-theme.ts +10 -10
  282. package/src/lib/hooks/use-user-settings.tsx +12 -12
  283. package/src/lib/index.ts +149 -149
  284. package/src/lib/lib/trans.tsx +16 -16
  285. package/src/lib/lib/utils.ts +60 -60
  286. package/src/lib/providers/auth.tsx +152 -152
  287. package/src/lib/providers/channel-provider.tsx +121 -121
  288. package/src/lib/providers/i18n-provider.tsx +28 -28
  289. package/src/lib/providers/server-config.tsx +279 -279
  290. package/src/lib/providers/theme-provider.tsx +54 -54
  291. package/src/lib/providers/user-settings.tsx +89 -89
  292. package/src/lib/virtual.d.ts +12 -12
  293. package/vite/config-loader.ts +181 -181
  294. package/vite/constants.ts +280 -280
  295. package/vite/index.ts +1 -1
  296. package/vite/schema-generator.ts +40 -40
  297. package/vite/ui-config.ts +60 -60
  298. package/vite/vite-plugin-admin-api-schema.ts +141 -141
  299. package/vite/vite-plugin-config-loader.ts +64 -64
  300. package/vite/vite-plugin-config.ts +42 -42
  301. package/vite/vite-plugin-dashboard-metadata.ts +58 -58
  302. package/vite/vite-plugin-gql-tada.ts +62 -62
  303. package/vite/vite-plugin-theme.ts +195 -195
  304. package/vite/vite-plugin-ui-config.ts +60 -60
  305. package/vite/vite-plugin-vendure-dashboard.ts +118 -118
  306. package/dist/plugin/.vendure-dashboard-temp/dev-config.js +0 -227
  307. package/dist/plugin/.vendure-dashboard-temp/dev-config.js.map +0 -1
  308. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/api/api-extensions.js +0 -33
  309. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/api/api-extensions.js.map +0 -1
  310. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/api/mv.resolver.js +0 -69
  311. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/api/mv.resolver.js.map +0 -1
  312. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-order-process.js +0 -110
  313. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-order-process.js.map +0 -1
  314. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-order-seller-strategy.js +0 -134
  315. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-order-seller-strategy.js.map +0 -1
  316. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-payment-handler.js +0 -86
  317. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-payment-handler.js.map +0 -1
  318. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-shipping-eligibility-checker.js +0 -49
  319. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-shipping-eligibility-checker.js.map +0 -1
  320. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-shipping-line-assignment-strategy.js +0 -57
  321. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/config/mv-shipping-line-assignment-strategy.js.map +0 -1
  322. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/constants.js +0 -20
  323. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/constants.js.map +0 -1
  324. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/multivendor.plugin.js +0 -151
  325. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/multivendor.plugin.js.map +0 -1
  326. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/payment/mv-connect-sdk.js +0 -47
  327. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/payment/mv-connect-sdk.js.map +0 -1
  328. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/service/mv.service.js +0 -222
  329. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/service/mv.service.js.map +0 -1
  330. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/types.js +0 -4
  331. package/dist/plugin/.vendure-dashboard-temp/example-plugins/multivendor-plugin/types.js.map +0 -1
  332. package/dist/plugin/.vendure-dashboard-temp/package.json +0 -3
  333. package/dist/plugin/.vendure-dashboard-temp/schema.graphql +0 -6378
  334. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/api-extensions.js +0 -103
  335. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/api-extensions.js.map +0 -1
  336. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/product-entity.resolver.js +0 -105
  337. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/product-entity.resolver.js.map +0 -1
  338. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/product-review-admin.resolver.js +0 -183
  339. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/product-review-admin.resolver.js.map +0 -1
  340. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/product-review-entity.resolver.js +0 -113
  341. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/product-review-entity.resolver.js.map +0 -1
  342. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/product-review-shop.resolver.js +0 -112
  343. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/api/product-review-shop.resolver.js.map +0 -1
  344. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/entities/product-review.entity.js +0 -111
  345. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/entities/product-review.entity.js.map +0 -1
  346. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/generated-admin-types.js +0 -616
  347. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/generated-admin-types.js.map +0 -1
  348. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/generated-shop-types.js +0 -563
  349. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/generated-shop-types.js.map +0 -1
  350. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/reviews-plugin.js +0 -135
  351. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/reviews-plugin.js.map +0 -1
  352. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/types.js +0 -4
  353. package/dist/plugin/.vendure-dashboard-temp/test-plugins/reviews/types.js.map +0 -1
  354. package/dist/plugin/.vendure-dashboard-temp/tsconfig.json +0 -10
  355. package/dist/plugin/config-loader.d.ts +0 -27
  356. package/dist/plugin/config-loader.js +0 -141
  357. package/dist/plugin/constants.d.ts +0 -5
  358. package/dist/plugin/constants.js +0 -277
  359. package/dist/plugin/index.d.ts +0 -1
  360. package/dist/plugin/index.js +0 -1
  361. package/dist/plugin/schema-generator.d.ts +0 -5
  362. package/dist/plugin/schema-generator.js +0 -24
  363. package/dist/plugin/ui-config.d.ts +0 -3
  364. package/dist/plugin/ui-config.js +0 -35
  365. package/dist/plugin/vite-plugin-admin-api-schema.d.ts +0 -24
  366. package/dist/plugin/vite-plugin-admin-api-schema.js +0 -82
  367. package/dist/plugin/vite-plugin-config-loader.d.ts +0 -17
  368. package/dist/plugin/vite-plugin-config-loader.js +0 -56
  369. package/dist/plugin/vite-plugin-config.d.ts +0 -4
  370. package/dist/plugin/vite-plugin-config.js +0 -38
  371. package/dist/plugin/vite-plugin-dashboard-metadata.d.ts +0 -9
  372. package/dist/plugin/vite-plugin-dashboard-metadata.js +0 -52
  373. package/dist/plugin/vite-plugin-gql-tada.d.ts +0 -6
  374. package/dist/plugin/vite-plugin-gql-tada.js +0 -51
  375. package/dist/plugin/vite-plugin-set-root.d.ts +0 -4
  376. package/dist/plugin/vite-plugin-set-root.js +0 -15
  377. package/dist/plugin/vite-plugin-ui-config.d.ts +0 -15
  378. package/dist/plugin/vite-plugin-ui-config.js +0 -43
  379. package/dist/plugin/vite-plugin-vendure-dashboard.d.ts +0 -35
  380. package/dist/plugin/vite-plugin-vendure-dashboard.js +0 -81
  381. package/src/app/routeTree.gen.ts +0 -1372
@@ -1,462 +1,462 @@
1
- import { zodResolver } from '@hookform/resolvers/zod';
2
- import { Trans } from '@/lib/trans.js';
3
- import { Plus, Trash2 } from 'lucide-react';
4
- import { useEffect, useMemo } from 'react';
5
- import { FormProvider, useFieldArray, useForm } from 'react-hook-form';
6
- import { z } from 'zod';
7
- import { useQuery } from '@tanstack/react-query';
8
- import { Alert, AlertDescription } from '@/components/ui/alert.js';
9
- import { Button } from '@/components/ui/button.js';
10
- import { Card } from '@/components/ui/card.js';
11
- import { Checkbox } from '@/components/ui/checkbox.js';
12
- import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form.js';
13
- import { Input } from '@/components/ui/input.js';
14
- import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table.js';
15
- import { graphql } from '@/graphql/graphql.js';
16
- import { api } from '@/graphql/api.js';
17
- import { OptionValueInput } from './option-value-input.js';
18
-
19
- const getStockLocationsDocument = graphql(`
20
- query GetStockLocations($options: StockLocationListOptions) {
21
- stockLocations(options: $options) {
22
- items {
23
- id
24
- name
25
- }
26
- totalItems
27
- }
28
- }
29
- `);
30
-
31
- // Define schemas for validation
32
- const optionValueSchema = z.object({
33
- value: z.string().min(1, { message: 'Value cannot be empty' }),
34
- id: z.string().min(1, { message: 'Value cannot be empty' }),
35
- });
36
-
37
- const optionGroupSchema = z.object({
38
- name: z.string().min(1, { message: 'Option name is required' }),
39
- values: z.array(optionValueSchema).min(1, { message: 'At least one value is required' }),
40
- });
41
-
42
-
43
- type VariantOption = {
44
- name: string;
45
- value: string;
46
- id: string;
47
- };
48
-
49
- type GeneratedVariant = {
50
- id: string;
51
- name: string;
52
- values: string[];
53
- options: VariantOption[];
54
- enabled: boolean;
55
- sku: string;
56
- price: string;
57
- stock: string;
58
- };
59
-
60
- export interface VariantConfiguration {
61
- optionGroups: Array<{
62
- name: string;
63
- values: Array<{
64
- value: string;
65
- id: string;
66
- }>;
67
- }>;
68
- variants: Array<{
69
- enabled: boolean;
70
- sku: string;
71
- price: string;
72
- stock: string;
73
- options: VariantOption[];
74
- }>;
75
- }
76
-
77
- const variantSchema = z.object({
78
- enabled: z.boolean().default(true),
79
- sku: z.string().min(1, { message: 'SKU is required' }),
80
- price: z.string().refine(val => !isNaN(Number(val)) && Number(val) >= 0, {
81
- message: 'Price must be a positive number',
82
- }),
83
- stock: z.string().refine(val => !isNaN(Number(val)) && parseInt(val, 10) >= 0, {
84
- message: 'Stock must be a non-negative integer',
85
- }),
86
- });
87
-
88
- const formSchema = z.object({
89
- optionGroups: z.array(optionGroupSchema),
90
- variants: z.record(variantSchema),
91
- });
92
-
93
- type OptionGroupForm = z.infer<typeof optionGroupSchema>;
94
- type VariantForm = z.infer<typeof variantSchema>;
95
- type FormValues = z.infer<typeof formSchema>;
96
-
97
- interface CreateProductVariantsProps {
98
- currencyCode?: string;
99
- onChange?: ({ data }: { data: VariantConfiguration }) => void;
100
- }
101
-
102
- export function CreateProductVariants({ currencyCode = 'USD', onChange }: CreateProductVariantsProps) {
103
- const { data: stockLocationsResult } = useQuery({
104
- queryKey: ['stockLocations'],
105
- queryFn: () => api.query(getStockLocationsDocument, { options: { take: 100 } }),
106
- });
107
- const stockLocations = stockLocationsResult?.stockLocations.items ?? [];
108
-
109
- const form = useForm<FormValues>({
110
- resolver: zodResolver(formSchema),
111
- defaultValues: {
112
- optionGroups: [],
113
- variants: {},
114
- },
115
- mode: 'onChange',
116
- });
117
-
118
- const { control, watch, setValue } = form;
119
- const {
120
- fields: optionGroups,
121
- append: appendOptionGroup,
122
- remove: removeOptionGroup,
123
- } = useFieldArray({
124
- control,
125
- name: 'optionGroups',
126
- });
127
-
128
- const watchedOptionGroups = watch('optionGroups');
129
- // memoize the variants
130
- const variants = useMemo(() => generateVariants(watchedOptionGroups), [JSON.stringify(watchedOptionGroups)]);
131
-
132
- // Use the handleSubmit approach for the entire form
133
- useEffect(() => {
134
- const subscription = form.watch((value, { name, type }) => {
135
- if (value?.optionGroups) {
136
- const formVariants = value.variants || {};
137
- const activeVariants: VariantConfiguration['variants'] = [];
138
-
139
- variants.forEach(variant => {
140
- if (variant && typeof variant === 'object') {
141
- const formVariant = formVariants[variant.id];
142
- if (formVariant) {
143
- activeVariants.push({
144
- enabled: formVariant.enabled ?? true,
145
- sku: formVariant.sku ?? '',
146
- price: formVariant.price ?? '',
147
- stock: formVariant.stock ?? '',
148
- options: variant.options,
149
- });
150
- }
151
- }
152
- });
153
-
154
- const validOptionGroups = value.optionGroups
155
- .filter((group): group is NonNullable<typeof group> => !!group)
156
- .filter(group => typeof group.name === 'string' && Array.isArray(group.values))
157
- .map(group => ({
158
- name: group.name,
159
- values: (group.values || [])
160
- .filter((v): v is NonNullable<typeof v> => !!v)
161
- .filter(v => typeof v.value === 'string' && typeof v.id === 'string')
162
- .map(v => ({
163
- value: v.value,
164
- id: v.id,
165
- })),
166
- }))
167
- .filter(group => group.values.length > 0) as VariantConfiguration['optionGroups'];
168
-
169
- const filteredData: VariantConfiguration = {
170
- optionGroups: validOptionGroups,
171
- variants: activeVariants,
172
- };
173
-
174
- onChange?.({ data: filteredData });
175
- }
176
- });
177
-
178
- return () => subscription.unsubscribe();
179
- }, [form, onChange, variants]);
180
-
181
- // Initialize variant form values when variants change
182
- useEffect(() => {
183
- // Initialize any new variants with default values
184
- const currentVariants = form.getValues().variants || {};
185
- const updatedVariants = { ...currentVariants };
186
-
187
- variants.forEach(variant => {
188
- if (!updatedVariants[variant.id]) {
189
- updatedVariants[variant.id] = {
190
- enabled: true,
191
- sku: '',
192
- price: '',
193
- stock: '',
194
- };
195
- }
196
- });
197
-
198
- setValue('variants', updatedVariants);
199
- }, [variants, form, setValue]);
200
-
201
- const handleAddOptionGroup = () => {
202
- appendOptionGroup({ name: '', values: [] });
203
- };
204
-
205
- return (
206
- <FormProvider {...form}>
207
- {optionGroups.map((group, index) => (
208
- <div key={group.id} className="grid grid-cols-[1fr_2fr_auto] gap-4 mb-6 items-start">
209
- <div>
210
- <FormField
211
- control={form.control}
212
- name={`optionGroups.${index}.name`}
213
- render={({ field }) => (
214
- <FormItem>
215
- <FormLabel>
216
- <Trans>Option</Trans>
217
- </FormLabel>
218
- <FormControl>
219
- <Input placeholder="e.g. Size" {...field} />
220
- </FormControl>
221
- <FormMessage />
222
- </FormItem>
223
- )}
224
- />
225
- </div>
226
-
227
- <div>
228
- <FormItem>
229
- <FormLabel>
230
- <Trans>Option Values</Trans>
231
- </FormLabel>
232
- <FormControl>
233
- <OptionValueInput
234
- groupName={watch(`optionGroups.${index}.name`) || ''}
235
- groupIndex={index}
236
- disabled={!watch(`optionGroups.${index}.name`)}
237
- />
238
- </FormControl>
239
- </FormItem>
240
- </div>
241
-
242
- <div className="pt-8">
243
- <Button
244
- variant="ghost"
245
- size="icon"
246
- onClick={() => removeOptionGroup(index)}
247
- title="Remove Option"
248
- >
249
- <Trash2 className="h-4 w-4" />
250
- </Button>
251
- </div>
252
- </div>
253
- ))}
254
-
255
- <Button type="button" variant="secondary" onClick={handleAddOptionGroup} className="mb-6">
256
- <Plus className="mr-2 h-4 w-4" />
257
- <Trans>Add Option</Trans>
258
- </Button>
259
-
260
- {stockLocations.length === 0 ? (
261
- <Alert variant="destructive">
262
- <AlertDescription>
263
- <Trans>No stock locations available on current channel</Trans>
264
- </AlertDescription>
265
- </Alert>
266
- ) : (
267
- <>
268
- {stockLocations.length > 1 && (
269
- <div className="mb-4">
270
- <FormLabel>
271
- <Trans>Add Stock to Location</Trans>
272
- </FormLabel>
273
- <select className="w-full rounded-md border border-input bg-background px-3 py-2">
274
- {stockLocations.map(location => (
275
- <option key={location.id} value={location.id}>
276
- {location.name}
277
- </option>
278
- ))}
279
- </select>
280
- </div>
281
- )}
282
-
283
- {variants.length > 0 && (
284
- <Table>
285
- <TableHeader>
286
- <TableRow>
287
- {variants.length > 1 && (
288
- <TableHead>
289
- <Trans>Create</Trans>
290
- </TableHead>
291
- )}
292
- {variants.length > 1 && (
293
- <TableHead>
294
- <Trans>Variant</Trans>
295
- </TableHead>
296
- )}
297
- <TableHead>
298
- <Trans>SKU</Trans>
299
- </TableHead>
300
- <TableHead>
301
- <Trans>Price</Trans>
302
- </TableHead>
303
- <TableHead>
304
- <Trans>Stock on Hand</Trans>
305
- </TableHead>
306
- </TableRow>
307
- </TableHeader>
308
- <TableBody>
309
- {variants.map(variant => (
310
- <TableRow key={variant.id}>
311
- {variants.length > 1 && (
312
- <TableCell>
313
- <FormField
314
- control={form.control}
315
- name={`variants.${variant.id}.enabled`}
316
- render={({ field }) => (
317
- <FormItem className="flex items-center space-x-2">
318
- <FormControl>
319
- <Checkbox
320
- checked={field.value}
321
- onCheckedChange={field.onChange}
322
- />
323
- </FormControl>
324
- </FormItem>
325
- )}
326
- />
327
- </TableCell>
328
- )}
329
-
330
- {variants.length > 1 && (
331
- <TableCell>{variant.values.join(' ')}</TableCell>
332
- )}
333
-
334
- <TableCell>
335
- <FormField
336
- control={form.control}
337
- name={`variants.${variant.id}.sku`}
338
- render={({ field }) => (
339
- <FormItem>
340
- <FormControl>
341
- <Input {...field} placeholder="SKU" />
342
- </FormControl>
343
- <FormMessage />
344
- </FormItem>
345
- )}
346
- />
347
- </TableCell>
348
-
349
- <TableCell>
350
- <FormField
351
- control={form.control}
352
- name={`variants.${variant.id}.price`}
353
- render={({ field }) => (
354
- <FormItem>
355
- <FormControl>
356
- <div className="relative">
357
- <span className="absolute left-3 top-2.5">
358
- {currencyCode}
359
- </span>
360
- <Input
361
- {...field}
362
- className="pl-12"
363
- placeholder="0.00"
364
- />
365
- </div>
366
- </FormControl>
367
- <FormMessage />
368
- </FormItem>
369
- )}
370
- />
371
- </TableCell>
372
-
373
- <TableCell>
374
- <FormField
375
- control={form.control}
376
- name={`variants.${variant.id}.stock`}
377
- render={({ field }) => (
378
- <FormItem>
379
- <FormControl>
380
- <Input
381
- {...field}
382
- type="number"
383
- min="0"
384
- step="1"
385
- />
386
- </FormControl>
387
- <FormMessage />
388
- </FormItem>
389
- )}
390
- />
391
- </TableCell>
392
- </TableRow>
393
- ))}
394
- </TableBody>
395
- </Table>
396
- )}
397
- </>
398
- )}
399
- </FormProvider>
400
- );
401
- }
402
-
403
- // Generate all possible combinations of option values
404
- function generateVariants(groups: OptionGroupForm[]): GeneratedVariant[] {
405
- // If there are no groups, return a single variant with no options
406
- if (!groups.length)
407
- return [
408
- {
409
- id: 'default',
410
- name: '',
411
- values: [],
412
- options: [],
413
- enabled: true,
414
- sku: '',
415
- price: '',
416
- stock: '',
417
- },
418
- ];
419
-
420
- // Make sure all groups have at least one value
421
- const validGroups = groups.filter(group => group.name && group.values && group.values.length > 0);
422
- if (!validGroups.length) return [];
423
-
424
- // Generate combinations
425
- const generateCombinations = (
426
- optionGroups: OptionGroupForm[],
427
- currentIndex: number,
428
- currentCombination: VariantOption[],
429
- ): GeneratedVariant[] => {
430
- if (currentIndex === optionGroups.length) {
431
- return [
432
- {
433
- id: currentCombination.map(c => c.id).join('-'),
434
- name: currentCombination.map(c => c.value).join(' '),
435
- values: currentCombination.map(c => c.value),
436
- options: currentCombination,
437
- enabled: true,
438
- sku: '',
439
- price: '',
440
- stock: '',
441
- },
442
- ];
443
- }
444
-
445
- const currentGroup = optionGroups[currentIndex];
446
- const results: GeneratedVariant[] = [];
447
-
448
- currentGroup.values.forEach(optionValue => {
449
- const newCombination = [
450
- ...currentCombination,
451
- { name: currentGroup.name, value: optionValue.value, id: optionValue.id },
452
- ];
453
-
454
- const subResults = generateCombinations(optionGroups, currentIndex + 1, newCombination);
455
- results.push(...subResults);
456
- });
457
-
458
- return results;
459
- };
460
-
461
- return generateCombinations(validGroups, 0, []);
462
- }
1
+ import { zodResolver } from '@hookform/resolvers/zod';
2
+ import { Trans } from '@/lib/trans.js';
3
+ import { Plus, Trash2 } from 'lucide-react';
4
+ import { useEffect, useMemo } from 'react';
5
+ import { FormProvider, useFieldArray, useForm } from 'react-hook-form';
6
+ import { z } from 'zod';
7
+ import { useQuery } from '@tanstack/react-query';
8
+ import { Alert, AlertDescription } from '@/components/ui/alert.js';
9
+ import { Button } from '@/components/ui/button.js';
10
+ import { Card } from '@/components/ui/card.js';
11
+ import { Checkbox } from '@/components/ui/checkbox.js';
12
+ import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form.js';
13
+ import { Input } from '@/components/ui/input.js';
14
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table.js';
15
+ import { graphql } from '@/graphql/graphql.js';
16
+ import { api } from '@/graphql/api.js';
17
+ import { OptionValueInput } from './option-value-input.js';
18
+
19
+ const getStockLocationsDocument = graphql(`
20
+ query GetStockLocations($options: StockLocationListOptions) {
21
+ stockLocations(options: $options) {
22
+ items {
23
+ id
24
+ name
25
+ }
26
+ totalItems
27
+ }
28
+ }
29
+ `);
30
+
31
+ // Define schemas for validation
32
+ const optionValueSchema = z.object({
33
+ value: z.string().min(1, { message: 'Value cannot be empty' }),
34
+ id: z.string().min(1, { message: 'Value cannot be empty' }),
35
+ });
36
+
37
+ const optionGroupSchema = z.object({
38
+ name: z.string().min(1, { message: 'Option name is required' }),
39
+ values: z.array(optionValueSchema).min(1, { message: 'At least one value is required' }),
40
+ });
41
+
42
+
43
+ type VariantOption = {
44
+ name: string;
45
+ value: string;
46
+ id: string;
47
+ };
48
+
49
+ type GeneratedVariant = {
50
+ id: string;
51
+ name: string;
52
+ values: string[];
53
+ options: VariantOption[];
54
+ enabled: boolean;
55
+ sku: string;
56
+ price: string;
57
+ stock: string;
58
+ };
59
+
60
+ export interface VariantConfiguration {
61
+ optionGroups: Array<{
62
+ name: string;
63
+ values: Array<{
64
+ value: string;
65
+ id: string;
66
+ }>;
67
+ }>;
68
+ variants: Array<{
69
+ enabled: boolean;
70
+ sku: string;
71
+ price: string;
72
+ stock: string;
73
+ options: VariantOption[];
74
+ }>;
75
+ }
76
+
77
+ const variantSchema = z.object({
78
+ enabled: z.boolean().default(true),
79
+ sku: z.string().min(1, { message: 'SKU is required' }),
80
+ price: z.string().refine(val => !isNaN(Number(val)) && Number(val) >= 0, {
81
+ message: 'Price must be a positive number',
82
+ }),
83
+ stock: z.string().refine(val => !isNaN(Number(val)) && parseInt(val, 10) >= 0, {
84
+ message: 'Stock must be a non-negative integer',
85
+ }),
86
+ });
87
+
88
+ const formSchema = z.object({
89
+ optionGroups: z.array(optionGroupSchema),
90
+ variants: z.record(variantSchema),
91
+ });
92
+
93
+ type OptionGroupForm = z.infer<typeof optionGroupSchema>;
94
+ type VariantForm = z.infer<typeof variantSchema>;
95
+ type FormValues = z.infer<typeof formSchema>;
96
+
97
+ interface CreateProductVariantsProps {
98
+ currencyCode?: string;
99
+ onChange?: ({ data }: { data: VariantConfiguration }) => void;
100
+ }
101
+
102
+ export function CreateProductVariants({ currencyCode = 'USD', onChange }: CreateProductVariantsProps) {
103
+ const { data: stockLocationsResult } = useQuery({
104
+ queryKey: ['stockLocations'],
105
+ queryFn: () => api.query(getStockLocationsDocument, { options: { take: 100 } }),
106
+ });
107
+ const stockLocations = stockLocationsResult?.stockLocations.items ?? [];
108
+
109
+ const form = useForm<FormValues>({
110
+ resolver: zodResolver(formSchema),
111
+ defaultValues: {
112
+ optionGroups: [],
113
+ variants: {},
114
+ },
115
+ mode: 'onChange',
116
+ });
117
+
118
+ const { control, watch, setValue } = form;
119
+ const {
120
+ fields: optionGroups,
121
+ append: appendOptionGroup,
122
+ remove: removeOptionGroup,
123
+ } = useFieldArray({
124
+ control,
125
+ name: 'optionGroups',
126
+ });
127
+
128
+ const watchedOptionGroups = watch('optionGroups');
129
+ // memoize the variants
130
+ const variants = useMemo(() => generateVariants(watchedOptionGroups), [JSON.stringify(watchedOptionGroups)]);
131
+
132
+ // Use the handleSubmit approach for the entire form
133
+ useEffect(() => {
134
+ const subscription = form.watch((value, { name, type }) => {
135
+ if (value?.optionGroups) {
136
+ const formVariants = value.variants || {};
137
+ const activeVariants: VariantConfiguration['variants'] = [];
138
+
139
+ variants.forEach(variant => {
140
+ if (variant && typeof variant === 'object') {
141
+ const formVariant = formVariants[variant.id];
142
+ if (formVariant) {
143
+ activeVariants.push({
144
+ enabled: formVariant.enabled ?? true,
145
+ sku: formVariant.sku ?? '',
146
+ price: formVariant.price ?? '',
147
+ stock: formVariant.stock ?? '',
148
+ options: variant.options,
149
+ });
150
+ }
151
+ }
152
+ });
153
+
154
+ const validOptionGroups = value.optionGroups
155
+ .filter((group): group is NonNullable<typeof group> => !!group)
156
+ .filter(group => typeof group.name === 'string' && Array.isArray(group.values))
157
+ .map(group => ({
158
+ name: group.name,
159
+ values: (group.values || [])
160
+ .filter((v): v is NonNullable<typeof v> => !!v)
161
+ .filter(v => typeof v.value === 'string' && typeof v.id === 'string')
162
+ .map(v => ({
163
+ value: v.value,
164
+ id: v.id,
165
+ })),
166
+ }))
167
+ .filter(group => group.values.length > 0) as VariantConfiguration['optionGroups'];
168
+
169
+ const filteredData: VariantConfiguration = {
170
+ optionGroups: validOptionGroups,
171
+ variants: activeVariants,
172
+ };
173
+
174
+ onChange?.({ data: filteredData });
175
+ }
176
+ });
177
+
178
+ return () => subscription.unsubscribe();
179
+ }, [form, onChange, variants]);
180
+
181
+ // Initialize variant form values when variants change
182
+ useEffect(() => {
183
+ // Initialize any new variants with default values
184
+ const currentVariants = form.getValues().variants || {};
185
+ const updatedVariants = { ...currentVariants };
186
+
187
+ variants.forEach(variant => {
188
+ if (!updatedVariants[variant.id]) {
189
+ updatedVariants[variant.id] = {
190
+ enabled: true,
191
+ sku: '',
192
+ price: '',
193
+ stock: '',
194
+ };
195
+ }
196
+ });
197
+
198
+ setValue('variants', updatedVariants);
199
+ }, [variants, form, setValue]);
200
+
201
+ const handleAddOptionGroup = () => {
202
+ appendOptionGroup({ name: '', values: [] });
203
+ };
204
+
205
+ return (
206
+ <FormProvider {...form}>
207
+ {optionGroups.map((group, index) => (
208
+ <div key={group.id} className="grid grid-cols-[1fr_2fr_auto] gap-4 mb-6 items-start">
209
+ <div>
210
+ <FormField
211
+ control={form.control}
212
+ name={`optionGroups.${index}.name`}
213
+ render={({ field }) => (
214
+ <FormItem>
215
+ <FormLabel>
216
+ <Trans>Option</Trans>
217
+ </FormLabel>
218
+ <FormControl>
219
+ <Input placeholder="e.g. Size" {...field} />
220
+ </FormControl>
221
+ <FormMessage />
222
+ </FormItem>
223
+ )}
224
+ />
225
+ </div>
226
+
227
+ <div>
228
+ <FormItem>
229
+ <FormLabel>
230
+ <Trans>Option Values</Trans>
231
+ </FormLabel>
232
+ <FormControl>
233
+ <OptionValueInput
234
+ groupName={watch(`optionGroups.${index}.name`) || ''}
235
+ groupIndex={index}
236
+ disabled={!watch(`optionGroups.${index}.name`)}
237
+ />
238
+ </FormControl>
239
+ </FormItem>
240
+ </div>
241
+
242
+ <div className="pt-8">
243
+ <Button
244
+ variant="ghost"
245
+ size="icon"
246
+ onClick={() => removeOptionGroup(index)}
247
+ title="Remove Option"
248
+ >
249
+ <Trash2 className="h-4 w-4" />
250
+ </Button>
251
+ </div>
252
+ </div>
253
+ ))}
254
+
255
+ <Button type="button" variant="secondary" onClick={handleAddOptionGroup} className="mb-6">
256
+ <Plus className="mr-2 h-4 w-4" />
257
+ <Trans>Add Option</Trans>
258
+ </Button>
259
+
260
+ {stockLocations.length === 0 ? (
261
+ <Alert variant="destructive">
262
+ <AlertDescription>
263
+ <Trans>No stock locations available on current channel</Trans>
264
+ </AlertDescription>
265
+ </Alert>
266
+ ) : (
267
+ <>
268
+ {stockLocations.length > 1 && (
269
+ <div className="mb-4">
270
+ <FormLabel>
271
+ <Trans>Add Stock to Location</Trans>
272
+ </FormLabel>
273
+ <select className="w-full rounded-md border border-input bg-background px-3 py-2">
274
+ {stockLocations.map(location => (
275
+ <option key={location.id} value={location.id}>
276
+ {location.name}
277
+ </option>
278
+ ))}
279
+ </select>
280
+ </div>
281
+ )}
282
+
283
+ {variants.length > 0 && (
284
+ <Table>
285
+ <TableHeader>
286
+ <TableRow>
287
+ {variants.length > 1 && (
288
+ <TableHead>
289
+ <Trans>Create</Trans>
290
+ </TableHead>
291
+ )}
292
+ {variants.length > 1 && (
293
+ <TableHead>
294
+ <Trans>Variant</Trans>
295
+ </TableHead>
296
+ )}
297
+ <TableHead>
298
+ <Trans>SKU</Trans>
299
+ </TableHead>
300
+ <TableHead>
301
+ <Trans>Price</Trans>
302
+ </TableHead>
303
+ <TableHead>
304
+ <Trans>Stock on Hand</Trans>
305
+ </TableHead>
306
+ </TableRow>
307
+ </TableHeader>
308
+ <TableBody>
309
+ {variants.map(variant => (
310
+ <TableRow key={variant.id}>
311
+ {variants.length > 1 && (
312
+ <TableCell>
313
+ <FormField
314
+ control={form.control}
315
+ name={`variants.${variant.id}.enabled`}
316
+ render={({ field }) => (
317
+ <FormItem className="flex items-center space-x-2">
318
+ <FormControl>
319
+ <Checkbox
320
+ checked={field.value}
321
+ onCheckedChange={field.onChange}
322
+ />
323
+ </FormControl>
324
+ </FormItem>
325
+ )}
326
+ />
327
+ </TableCell>
328
+ )}
329
+
330
+ {variants.length > 1 && (
331
+ <TableCell>{variant.values.join(' ')}</TableCell>
332
+ )}
333
+
334
+ <TableCell>
335
+ <FormField
336
+ control={form.control}
337
+ name={`variants.${variant.id}.sku`}
338
+ render={({ field }) => (
339
+ <FormItem>
340
+ <FormControl>
341
+ <Input {...field} placeholder="SKU" />
342
+ </FormControl>
343
+ <FormMessage />
344
+ </FormItem>
345
+ )}
346
+ />
347
+ </TableCell>
348
+
349
+ <TableCell>
350
+ <FormField
351
+ control={form.control}
352
+ name={`variants.${variant.id}.price`}
353
+ render={({ field }) => (
354
+ <FormItem>
355
+ <FormControl>
356
+ <div className="relative">
357
+ <span className="absolute left-3 top-2.5">
358
+ {currencyCode}
359
+ </span>
360
+ <Input
361
+ {...field}
362
+ className="pl-12"
363
+ placeholder="0.00"
364
+ />
365
+ </div>
366
+ </FormControl>
367
+ <FormMessage />
368
+ </FormItem>
369
+ )}
370
+ />
371
+ </TableCell>
372
+
373
+ <TableCell>
374
+ <FormField
375
+ control={form.control}
376
+ name={`variants.${variant.id}.stock`}
377
+ render={({ field }) => (
378
+ <FormItem>
379
+ <FormControl>
380
+ <Input
381
+ {...field}
382
+ type="number"
383
+ min="0"
384
+ step="1"
385
+ />
386
+ </FormControl>
387
+ <FormMessage />
388
+ </FormItem>
389
+ )}
390
+ />
391
+ </TableCell>
392
+ </TableRow>
393
+ ))}
394
+ </TableBody>
395
+ </Table>
396
+ )}
397
+ </>
398
+ )}
399
+ </FormProvider>
400
+ );
401
+ }
402
+
403
+ // Generate all possible combinations of option values
404
+ function generateVariants(groups: OptionGroupForm[]): GeneratedVariant[] {
405
+ // If there are no groups, return a single variant with no options
406
+ if (!groups.length)
407
+ return [
408
+ {
409
+ id: 'default',
410
+ name: '',
411
+ values: [],
412
+ options: [],
413
+ enabled: true,
414
+ sku: '',
415
+ price: '',
416
+ stock: '',
417
+ },
418
+ ];
419
+
420
+ // Make sure all groups have at least one value
421
+ const validGroups = groups.filter(group => group.name && group.values && group.values.length > 0);
422
+ if (!validGroups.length) return [];
423
+
424
+ // Generate combinations
425
+ const generateCombinations = (
426
+ optionGroups: OptionGroupForm[],
427
+ currentIndex: number,
428
+ currentCombination: VariantOption[],
429
+ ): GeneratedVariant[] => {
430
+ if (currentIndex === optionGroups.length) {
431
+ return [
432
+ {
433
+ id: currentCombination.map(c => c.id).join('-'),
434
+ name: currentCombination.map(c => c.value).join(' '),
435
+ values: currentCombination.map(c => c.value),
436
+ options: currentCombination,
437
+ enabled: true,
438
+ sku: '',
439
+ price: '',
440
+ stock: '',
441
+ },
442
+ ];
443
+ }
444
+
445
+ const currentGroup = optionGroups[currentIndex];
446
+ const results: GeneratedVariant[] = [];
447
+
448
+ currentGroup.values.forEach(optionValue => {
449
+ const newCombination = [
450
+ ...currentCombination,
451
+ { name: currentGroup.name, value: optionValue.value, id: optionValue.id },
452
+ ];
453
+
454
+ const subResults = generateCombinations(optionGroups, currentIndex + 1, newCombination);
455
+ results.push(...subResults);
456
+ });
457
+
458
+ return results;
459
+ };
460
+
461
+ return generateCombinations(validGroups, 0, []);
462
+ }