@nextblock-cms/ecom 0.20.3 → 0.21.0

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 (317) hide show
  1. package/_virtual/_rolldown/runtime.cjs.js +1 -0
  2. package/index.cjs.js +1 -1
  3. package/index.es.js +38 -146
  4. package/lib/CurrencyProvider.cjs.js +1 -1
  5. package/lib/CurrencyProvider.d.ts +1 -1
  6. package/lib/CurrencyProvider.es.js +85 -95
  7. package/lib/PaymentReadinessProvider.cjs.js +1 -1
  8. package/lib/PaymentReadinessProvider.d.ts +1 -1
  9. package/lib/PaymentReadinessProvider.es.js +24 -27
  10. package/lib/cart-store.cjs.js +1 -1
  11. package/lib/cart-store.es.js +109 -121
  12. package/lib/components/AccountNavigationMenu.cjs.js +1 -1
  13. package/lib/components/AccountNavigationMenu.d.ts +1 -1
  14. package/lib/components/AccountNavigationMenu.es.js +36 -50
  15. package/lib/components/AddToCartButton.cjs.js +1 -1
  16. package/lib/components/AddToCartButton.d.ts +1 -1
  17. package/lib/components/AddToCartButton.es.js +94 -89
  18. package/lib/components/Cart.cjs.js +1 -1
  19. package/lib/components/Cart.d.ts +1 -1
  20. package/lib/components/Cart.es.js +261 -180
  21. package/lib/components/CartDrawer.cjs.js +1 -1
  22. package/lib/components/CartDrawer.d.ts +1 -1
  23. package/lib/components/CartDrawer.es.js +218 -148
  24. package/lib/components/CartIcon.cjs.js +1 -1
  25. package/lib/components/CartIcon.d.ts +1 -1
  26. package/lib/components/CartIcon.es.js +33 -35
  27. package/lib/components/Checkout.cjs.js +1 -1
  28. package/lib/components/Checkout.d.ts +1 -1
  29. package/lib/components/Checkout.es.js +1092 -1108
  30. package/lib/components/CouponForm.cjs.js +1 -1
  31. package/lib/components/CouponForm.d.ts +1 -1
  32. package/lib/components/CouponForm.es.js +136 -148
  33. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  34. package/lib/components/CurrencySwitcher.d.ts +1 -1
  35. package/lib/components/CurrencySwitcher.es.js +22 -18
  36. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  37. package/lib/components/CustomerProfileForm.es.js +454 -313
  38. package/lib/components/FeaturedProduct.cjs.js +1 -1
  39. package/lib/components/FeaturedProduct.d.ts +1 -1
  40. package/lib/components/FeaturedProduct.es.js +98 -83
  41. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  42. package/lib/components/FreemiusLicensePanel.d.ts +1 -1
  43. package/lib/components/FreemiusLicensePanel.es.js +70 -65
  44. package/lib/components/InvoiceDocument.cjs.js +1 -1
  45. package/lib/components/InvoiceDocument.es.js +256 -192
  46. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  47. package/lib/components/InvoiceViewerShell.d.ts +1 -1
  48. package/lib/components/InvoiceViewerShell.es.js +75 -106
  49. package/lib/components/ProductCard.cjs.js +1 -1
  50. package/lib/components/ProductCard.d.ts +1 -1
  51. package/lib/components/ProductCard.es.js +186 -171
  52. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  53. package/lib/components/ProductDetailsLayout.es.js +405 -404
  54. package/lib/components/ProductGallery.cjs.js +1 -1
  55. package/lib/components/ProductGallery.d.ts +1 -1
  56. package/lib/components/ProductGallery.es.js +51 -54
  57. package/lib/components/ProductGrid.cjs.js +1 -1
  58. package/lib/components/ProductGrid.d.ts +1 -1
  59. package/lib/components/ProductGrid.es.js +23 -25
  60. package/lib/components/ShippingEstimator.cjs.js +1 -1
  61. package/lib/components/ShippingEstimator.d.ts +1 -1
  62. package/lib/components/ShippingEstimator.es.js +158 -153
  63. package/lib/components/ShortDescription.cjs.js +1 -1
  64. package/lib/components/ShortDescription.es.js +17 -17
  65. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  66. package/lib/components/SimpleTiptapRenderer.es.js +238 -211
  67. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  68. package/lib/components/SubscriptionSelector.es.js +159 -154
  69. package/lib/countries.cjs.js +1 -1
  70. package/lib/countries.es.js +232 -75
  71. package/lib/coupon-server.cjs.js +1 -1
  72. package/lib/coupon-server.es.js +180 -224
  73. package/lib/coupons.cjs.js +1 -1
  74. package/lib/coupons.es.js +12 -14
  75. package/lib/currency-constants.cjs.js +1 -1
  76. package/lib/currency-constants.es.js +4 -4
  77. package/lib/currency-rest-client.cjs.js +1 -1
  78. package/lib/currency-rest-client.es.js +15 -22
  79. package/lib/currency-store.cjs.js +1 -1
  80. package/lib/currency-store.es.js +20 -27
  81. package/lib/currency-sync.cjs.js +1 -1
  82. package/lib/currency-sync.es.js +124 -170
  83. package/lib/currency.cjs.js +1 -1
  84. package/lib/currency.es.js +242 -310
  85. package/lib/customer-addresses.cjs.js +1 -1
  86. package/lib/customer-addresses.es.js +80 -109
  87. package/lib/customer-orders.cjs.js +1 -1
  88. package/lib/customer-orders.es.js +31 -43
  89. package/lib/customer.cjs.js +1 -1
  90. package/lib/customer.es.js +43 -52
  91. package/lib/export-helpers.cjs.js +1 -1
  92. package/lib/export-helpers.es.js +53 -52
  93. package/lib/factory.cjs.js +1 -1
  94. package/lib/factory.es.js +10 -7
  95. package/lib/freemius-coupons.cjs.js +1 -1
  96. package/lib/freemius-coupons.es.js +245 -262
  97. package/lib/freemius-license-claim.cjs.js +1 -1
  98. package/lib/freemius-license-claim.es.js +87 -71
  99. package/lib/freemius-license.cjs.js +1 -1
  100. package/lib/freemius-license.es.js +32 -39
  101. package/lib/freemius-order-sync.cjs.js +1 -1
  102. package/lib/freemius-order-sync.es.js +226 -290
  103. package/lib/freemius-trial-provision.cjs.js +1 -1
  104. package/lib/freemius-trial-provision.es.js +136 -130
  105. package/lib/inventory-settings.cjs.js +1 -1
  106. package/lib/inventory-settings.es.js +69 -77
  107. package/lib/invoice-server.cjs.js +3 -3
  108. package/lib/invoice-server.es.js +94 -141
  109. package/lib/invoice-ui.cjs.js +1 -1
  110. package/lib/invoice-ui.es.js +50 -66
  111. package/lib/invoice.cjs.js +1 -1
  112. package/lib/invoice.es.js +85 -94
  113. package/lib/order-inventory.cjs.js +25 -25
  114. package/lib/order-inventory.es.js +67 -79
  115. package/lib/order-tax-details.cjs.js +1 -1
  116. package/lib/order-tax-details.es.js +142 -153
  117. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  118. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
  119. package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
  120. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  121. package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
  122. package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
  123. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  124. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
  125. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
  126. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  127. package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
  128. package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
  129. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  130. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
  131. package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
  132. package/lib/pages/cms/coupons/actions.cjs.js +1 -1
  133. package/lib/pages/cms/coupons/actions.es.js +112 -115
  134. package/lib/pages/cms/coupons/index.cjs.js +1 -0
  135. package/lib/pages/cms/coupons/index.es.js +3 -0
  136. package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
  137. package/lib/pages/cms/coupons/product-options.es.js +21 -23
  138. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  139. package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
  140. package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
  141. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  142. package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
  143. package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
  144. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  145. package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
  146. package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
  147. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  148. package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
  149. package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
  150. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  151. package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
  152. package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
  153. package/lib/pages/cms/orders/actions.cjs.js +3 -3
  154. package/lib/pages/cms/orders/actions.es.js +53 -69
  155. package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
  156. package/lib/pages/cms/orders/export-actions.es.js +23 -26
  157. package/lib/pages/cms/orders/index.cjs.js +1 -0
  158. package/lib/pages/cms/orders/index.es.js +6 -0
  159. package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
  160. package/lib/pages/cms/orders/server-actions.es.js +60 -51
  161. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  162. package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
  163. package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
  164. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  165. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
  166. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
  167. package/lib/pages/cms/payments/actions.cjs.js +1 -1
  168. package/lib/pages/cms/payments/actions.es.js +38 -48
  169. package/lib/pages/cms/payments/index.cjs.js +1 -0
  170. package/lib/pages/cms/payments/index.es.js +3 -0
  171. package/lib/pages/cms/payments/queries.cjs.js +1 -1
  172. package/lib/pages/cms/payments/queries.es.js +38 -48
  173. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  174. package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
  175. package/lib/pages/cms/products/ProductsPage.es.js +63 -66
  176. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
  177. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  178. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
  179. package/lib/pages/cms/products/actions.cjs.js +4 -4
  180. package/lib/pages/cms/products/actions.es.js +121 -162
  181. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  182. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
  183. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
  184. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  185. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  186. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
  187. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  188. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
  189. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
  190. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  191. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
  192. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  193. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
  194. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  195. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
  196. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
  197. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  198. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
  199. package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
  200. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  201. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
  202. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
  203. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  204. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
  205. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  206. package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
  207. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  208. package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
  209. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  210. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
  211. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
  212. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  213. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
  214. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
  215. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  216. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
  217. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
  218. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  219. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
  220. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
  221. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
  222. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  223. package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
  224. package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
  225. package/lib/pages/cms/products/index.cjs.js +1 -0
  226. package/lib/pages/cms/products/index.es.js +8 -0
  227. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  228. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
  229. package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
  230. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  231. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
  232. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
  233. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
  234. package/lib/pages/cms/products/inventory/actions.es.js +83 -91
  235. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  236. package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
  237. package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
  238. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
  239. package/lib/pages/cms/products/product-price-sync.es.js +74 -89
  240. package/lib/pages/cms/products/server-actions.cjs.js +1 -1
  241. package/lib/pages/cms/products/server-actions.es.js +250 -233
  242. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  243. package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
  244. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  245. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  246. package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
  247. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  248. package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
  249. package/lib/pages/cms/shipping/index.cjs.js +1 -0
  250. package/lib/pages/cms/shipping/index.es.js +3 -0
  251. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
  252. package/lib/pages/cms/shipping/server-actions.es.js +131 -149
  253. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  254. package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
  255. package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
  256. package/lib/pages/cms/taxes/actions.cjs.js +1 -1
  257. package/lib/pages/cms/taxes/actions.es.js +41 -53
  258. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  259. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
  260. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
  261. package/lib/pages/cms/taxes/index.cjs.js +1 -0
  262. package/lib/pages/cms/taxes/index.es.js +3 -0
  263. package/lib/payment-config.cjs.js +1 -1
  264. package/lib/payment-config.es.js +110 -126
  265. package/lib/product-actions.cjs.js +4 -4
  266. package/lib/product-actions.es.js +289 -544
  267. package/lib/product-context.cjs.js +1 -1
  268. package/lib/product-context.es.js +13 -15
  269. package/lib/product-schema.cjs.js +1 -1
  270. package/lib/product-schema.es.js +99 -134
  271. package/lib/providers/freemius.cjs.js +1 -5
  272. package/lib/providers/freemius.es.js +446 -530
  273. package/lib/providers/stripe.cjs.js +1 -1
  274. package/lib/providers/stripe.es.js +417 -477
  275. package/lib/server-actions/coupon-actions.cjs.js +1 -1
  276. package/lib/server-actions/coupon-actions.es.js +22 -22
  277. package/lib/server-actions/customer-actions.cjs.js +1 -1
  278. package/lib/server-actions/customer-actions.es.js +26 -28
  279. package/lib/server-actions/product-actions.cjs.js +1 -1
  280. package/lib/server-actions/product-actions.es.js +9 -15
  281. package/lib/server-actions/shipping-actions.cjs.js +1 -1
  282. package/lib/server-actions/shipping-actions.es.js +27 -24
  283. package/lib/server-actions/tax-actions.cjs.js +1 -1
  284. package/lib/server-actions/tax-actions.es.js +33 -39
  285. package/lib/shared-inventory.cjs.js +2 -2
  286. package/lib/shared-inventory.es.js +111 -160
  287. package/lib/shipping/resolver.cjs.js +2 -2
  288. package/lib/shipping/resolver.es.js +44 -61
  289. package/lib/shipping-rate-currency.cjs.js +1 -1
  290. package/lib/shipping-rate-currency.es.js +52 -67
  291. package/lib/states.cjs.js +1 -1
  292. package/lib/states.es.js +333 -154
  293. package/lib/stripe/checkout.cjs.js +1 -1
  294. package/lib/stripe/checkout.es.js +125 -181
  295. package/lib/stripe/client.cjs.js +1 -1
  296. package/lib/stripe/client.es.js +14 -19
  297. package/lib/stripe/order-sync.cjs.js +1 -1
  298. package/lib/stripe/order-sync.es.js +106 -126
  299. package/lib/stripe/webhooks.cjs.js +1 -1
  300. package/lib/stripe/webhooks.es.js +37 -31
  301. package/lib/tax-calculation.cjs.js +1 -1
  302. package/lib/tax-calculation.es.js +84 -98
  303. package/lib/trials.cjs.js +1 -1
  304. package/lib/trials.es.js +24 -30
  305. package/lib/types.cjs.js +1 -1
  306. package/lib/types.es.js +21 -27
  307. package/lib/use-cart.cjs.js +1 -1
  308. package/lib/use-cart.es.js +38 -40
  309. package/lib/use-price-formatter.cjs.js +1 -1
  310. package/lib/use-price-formatter.es.js +10 -11
  311. package/lib/variation-utils.cjs.js +1 -1
  312. package/lib/variation-utils.es.js +199 -261
  313. package/lib/zod-config.cjs.js +1 -1
  314. package/lib/zod-config.es.js +5 -6
  315. package/package.json +16 -16
  316. package/server.cjs.js +1 -1
  317. package/server.es.js +56 -211
@@ -1,128 +1,125 @@
1
- 'use server';
2
- import { createClient as y, getServiceRoleSupabaseClient as C } from "@nextblock-cms/db/server";
3
- import { normalizeCurrencyCode as h, majorUnitAmountToMinor as A } from "@nextblock-cms/utils";
1
+ "use server";
2
+ import { normalizeCouponCode as e } from "../../../coupons.es.js";
3
+ import { deleteCouponFromFreemius as t, syncCouponToFreemius as n } from "../../../freemius-coupons.es.js";
4
+ import { majorUnitAmountToMinor as r, normalizeCurrencyCode as i } from "@nextblock-cms/utils";
5
+ import { createClient as a, getServiceRoleSupabaseClient as o } from "@nextblock-cms/db/server";
6
+ import { redirect as s } from "next/navigation";
4
7
  import { revalidatePath as c } from "next/cache";
5
- import { redirect as l } from "next/navigation";
6
- import { normalizeCouponCode as E } from "../../../coupons.es.js";
7
- import { syncCouponToFreemius as a, deleteCouponFromFreemius as w } from "../../../freemius-coupons.es.js";
8
- async function s() {
9
- const e = y(), {
10
- data: { user: o }
11
- } = await e.auth.getUser();
12
- if (!o)
13
- throw new Error("Unauthorized");
14
- const { data: t } = await e.from("profiles").select("role").eq("id", o.id).single();
15
- if (t?.role !== "ADMIN")
16
- throw new Error("Forbidden");
17
- return C();
8
+ //#region libs/ecommerce/src/lib/pages/cms/coupons/actions.ts
9
+ async function l() {
10
+ let e = a(), { data: { user: t } } = await e.auth.getUser();
11
+ if (!t) throw Error("Unauthorized");
12
+ let { data: n } = await e.from("profiles").select("role").eq("id", t.id).single();
13
+ if (n?.role !== "ADMIN") throw Error("Forbidden");
14
+ return o();
18
15
  }
19
- function i(e) {
20
- return (typeof e == "string" ? e.trim() : "") || null;
16
+ function u(e) {
17
+ return (typeof e == "string" ? e.trim() : "") || null;
21
18
  }
22
- function m(e) {
23
- const o = i(e);
24
- if (!o)
25
- return null;
26
- const t = new Date(o);
27
- return Number.isNaN(t.getTime()) ? null : t.toISOString();
19
+ function d(e) {
20
+ let t = u(e);
21
+ if (!t) return null;
22
+ let n = new Date(t);
23
+ return Number.isNaN(n.getTime()) ? null : n.toISOString();
28
24
  }
29
- function b(e) {
30
- const o = i(e.value), t = o ? Number.parseFloat(o) : Number.NaN;
31
- if (!Number.isFinite(t) || t <= 0)
32
- throw new Error("Discount amount must be greater than zero.");
33
- return e.discountType === "fixed" ? A(t, e.currencyCode) : Math.round(t);
25
+ function f(e) {
26
+ let t = u(e.value), n = t ? Number.parseFloat(t) : NaN;
27
+ if (!Number.isFinite(n) || n <= 0) throw Error("Discount amount must be greater than zero.");
28
+ return e.discountType === "fixed" ? r(n, e.currencyCode) : Math.round(n);
34
29
  }
35
- function v(e, o) {
36
- return e.getAll(o).some((t) => t === "true");
30
+ function p(e, t) {
31
+ return e.getAll(t).some((e) => e === "true");
37
32
  }
38
- function f(e) {
39
- const o = E(i(e.get("code"))), t = i(e.get("name")), n = i(e.get("provider_scope")) || "all", r = i(e.get("discount_type")) || "percent", _ = h(i(e.get("currency_code"))), u = b({
40
- value: e.get("discount_amount"),
41
- discountType: r,
42
- currencyCode: _
43
- }), d = i(e.get("redemption_limit"));
44
- if (!o)
45
- throw new Error("Coupon code is required.");
46
- if (!t)
47
- throw new Error("Coupon name is required.");
48
- if (r === "percent" && u > 100)
49
- throw new Error("Percent discounts cannot exceed 100.");
50
- return {
51
- coupon: {
52
- code: o,
53
- name: t,
54
- internal_note: i(e.get("internal_note")),
55
- provider_scope: n,
56
- discount_type: r,
57
- discount_amount: u,
58
- is_active: v(e, "is_active"),
59
- starts_at: m(e.get("starts_at")),
60
- ends_at: m(e.get("ends_at")),
61
- redemption_limit: d ? Number.parseInt(d, 10) : null,
62
- freemius_sync_status: n === "stripe" ? "not_required" : "pending",
63
- freemius_sync_error: null
64
- },
65
- productIds: e.getAll("product_ids").map((p) => typeof p == "string" ? p.trim() : "").filter(Boolean)
66
- };
33
+ function m(t) {
34
+ let n = e(u(t.get("code"))), r = u(t.get("name")), a = u(t.get("provider_scope")) || "all", o = u(t.get("discount_type")) || "percent", s = i(u(t.get("currency_code"))), c = f({
35
+ value: t.get("discount_amount"),
36
+ discountType: o,
37
+ currencyCode: s
38
+ }), l = u(t.get("redemption_limit"));
39
+ if (!n) throw Error("Coupon code is required.");
40
+ if (!r) throw Error("Coupon name is required.");
41
+ if (o === "percent" && c > 100) throw Error("Percent discounts cannot exceed 100.");
42
+ return {
43
+ coupon: {
44
+ code: n,
45
+ name: r,
46
+ internal_note: u(t.get("internal_note")),
47
+ provider_scope: a,
48
+ discount_type: o,
49
+ discount_amount: c,
50
+ is_active: p(t, "is_active"),
51
+ starts_at: d(t.get("starts_at")),
52
+ ends_at: d(t.get("ends_at")),
53
+ redemption_limit: l ? Number.parseInt(l, 10) : null,
54
+ freemius_sync_status: a === "stripe" ? "not_required" : "pending",
55
+ freemius_sync_error: null
56
+ },
57
+ productIds: t.getAll("product_ids").map((e) => typeof e == "string" ? e.trim() : "").filter(Boolean)
58
+ };
67
59
  }
68
- async function g(e) {
69
- if (await e.client.from("coupon_products").delete().eq("coupon_id", e.couponId), e.productIds.length === 0)
70
- return;
71
- const { error: o } = await e.client.from("coupon_products").insert(
72
- e.productIds.map((t) => ({
73
- coupon_id: e.couponId,
74
- product_id: t
75
- }))
76
- );
77
- if (o)
78
- throw new Error(o.message);
60
+ async function h(e) {
61
+ if (await e.client.from("coupon_products").delete().eq("coupon_id", e.couponId), e.productIds.length === 0) return;
62
+ let { error: t } = await e.client.from("coupon_products").insert(e.productIds.map((t) => ({
63
+ coupon_id: e.couponId,
64
+ product_id: t
65
+ })));
66
+ if (t) throw Error(t.message);
79
67
  }
80
- async function T(e) {
81
- const o = await s(), t = f(e), { data: n, error: r } = await o.from("coupons").insert(t.coupon).select("id").single();
82
- if (r || !n)
83
- throw new Error(r?.message || "Failed to create coupon.");
84
- await g({
85
- client: o,
86
- couponId: n.id,
87
- productIds: t.productIds
88
- }), await a({ couponId: n.id, client: o }), c("/cms/coupons"), l("/cms/coupons");
68
+ async function g(e) {
69
+ let t = await l(), r = m(e), { data: i, error: a } = await t.from("coupons").insert(r.coupon).select("id").single();
70
+ if (a || !i) throw Error(a?.message || "Failed to create coupon.");
71
+ await h({
72
+ client: t,
73
+ couponId: i.id,
74
+ productIds: r.productIds
75
+ }), await n({
76
+ couponId: i.id,
77
+ client: t
78
+ }), c("/cms/coupons"), s("/cms/coupons");
89
79
  }
90
- async function z(e, o) {
91
- const t = await s(), n = f(o), { error: r } = await t.from("coupons").update(n.coupon).eq("id", e);
92
- if (r)
93
- throw new Error(r.message);
94
- await g({
95
- client: t,
96
- couponId: e,
97
- productIds: n.productIds
98
- }), n.coupon.provider_scope === "stripe" ? await w({ couponId: e, client: t }) : await a({ couponId: e, client: t }), c("/cms/coupons"), c(`/cms/coupons/${e}/edit`), l("/cms/coupons");
80
+ async function _(e, r) {
81
+ let i = await l(), a = m(r), { error: o } = await i.from("coupons").update(a.coupon).eq("id", e);
82
+ if (o) throw Error(o.message);
83
+ await h({
84
+ client: i,
85
+ couponId: e,
86
+ productIds: a.productIds
87
+ }), a.coupon.provider_scope === "stripe" ? await t({
88
+ couponId: e,
89
+ client: i
90
+ }) : await n({
91
+ couponId: e,
92
+ client: i
93
+ }), c("/cms/coupons"), c(`/cms/coupons/${e}/edit`), s("/cms/coupons");
99
94
  }
100
- async function P(e, o) {
101
- const t = await s(), { error: n } = await t.from("coupons").update({
102
- is_active: o,
103
- freemius_sync_status: "pending",
104
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
105
- }).eq("id", e);
106
- if (n)
107
- throw new Error(n.message);
108
- await a({ couponId: e, client: t }), c("/cms/coupons");
95
+ async function v(e, t) {
96
+ let r = await l(), { error: i } = await r.from("coupons").update({
97
+ is_active: t,
98
+ freemius_sync_status: "pending",
99
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
100
+ }).eq("id", e);
101
+ if (i) throw Error(i.message);
102
+ await n({
103
+ couponId: e,
104
+ client: r
105
+ }), c("/cms/coupons");
109
106
  }
110
- async function M(e) {
111
- const o = await s();
112
- await a({ couponId: e, client: o }), c("/cms/coupons"), c(`/cms/coupons/${e}/edit`);
107
+ async function y(e) {
108
+ let t = await l();
109
+ await n({
110
+ couponId: e,
111
+ client: t
112
+ }), c("/cms/coupons"), c(`/cms/coupons/${e}/edit`);
113
113
  }
114
- async function U(e) {
115
- const o = await s();
116
- await w({ couponId: e, client: o });
117
- const { error: t } = await o.from("coupons").delete().eq("id", e);
118
- if (t)
119
- throw new Error(t.message);
120
- c("/cms/coupons");
114
+ async function b(e) {
115
+ let n = await l();
116
+ await t({
117
+ couponId: e,
118
+ client: n
119
+ });
120
+ let { error: r } = await n.from("coupons").delete().eq("id", e);
121
+ if (r) throw Error(r.message);
122
+ c("/cms/coupons");
121
123
  }
122
- export {
123
- T as createCouponAction,
124
- U as deleteCouponAction,
125
- M as syncCouponAction,
126
- P as toggleCouponActiveAction,
127
- z as updateCouponAction
128
- };
124
+ //#endregion
125
+ export { g as createCouponAction, b as deleteCouponAction, y as syncCouponAction, v as toggleCouponActiveAction, _ as updateCouponAction };
@@ -0,0 +1 @@
1
+ const e=require("./CouponsPage.cjs.js"),t=require("./EditCouponPage.cjs.js");exports.CouponsPage=e.CouponsPage,exports.EditCouponPage=t.EditCouponPage;
@@ -0,0 +1,3 @@
1
+ import { CouponsPage as e } from "./CouponsPage.es.js";
2
+ import { EditCouponPage as t } from "./EditCouponPage.es.js";
3
+ export { e as CouponsPage, t as EditCouponPage };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(r){return Array.isArray(r)?r[0]??null:r??null}const i=process.env.NEXT_PUBLIC_R2_BASE_URL||"";function l(r){return r?r.startsWith("http")||!i?r:`${i.replace(/\/+$/,"")}/${r.replace(/^\/+/,"")}`:null}function a(r){const e=Array.isArray(r.product_media)?[...r.product_media].sort((t,o)=>(t.sort_order??0)-(o.sort_order??0)):[],n=e[0]?.media?.file_path||e[0]?.media?.object_key||null;return l(n)}function s(r){return(r||[]).map(e=>({id:e.id,title:e.title,sku:e.sku??null,payment_provider:e.payment_provider||"stripe",freemius_product_id:e.freemius_product_id??null,thumbnailUrl:a(e),language:u(e.language)}))}exports.normalizeCouponProductOptions=s;
1
+ function e(e){return Array.isArray(e)?e[0]??null:e??null}var t=process.env.NEXT_PUBLIC_R2_BASE_URL||``;function n(e){return e?e.startsWith(`http`)||!t?e:`${t.replace(/\/+$/,``)}/${e.replace(/^\/+/,``)}`:null}function r(e){let t=Array.isArray(e.product_media)?[...e.product_media].sort((e,t)=>(e.sort_order??0)-(t.sort_order??0)):[];return n(t[0]?.media?.file_path||t[0]?.media?.object_key||null)}function i(t){return(t||[]).map(t=>({id:t.id,title:t.title,sku:t.sku??null,payment_provider:t.payment_provider||`stripe`,freemius_product_id:t.freemius_product_id??null,thumbnailUrl:r(t),language:e(t.language)}))}exports.normalizeCouponProductOptions=i;
@@ -1,27 +1,25 @@
1
- function l(r) {
2
- return Array.isArray(r) ? r[0] ?? null : r ?? null;
1
+ //#region libs/ecommerce/src/lib/pages/cms/coupons/product-options.ts
2
+ function e(e) {
3
+ return Array.isArray(e) ? e[0] ?? null : e ?? null;
3
4
  }
4
- const i = process.env.NEXT_PUBLIC_R2_BASE_URL || "";
5
- function o(r) {
6
- return r ? r.startsWith("http") || !i ? r : `${i.replace(/\/+$/, "")}/${r.replace(/^\/+/, "")}` : null;
5
+ var t = process.env.NEXT_PUBLIC_R2_BASE_URL || "";
6
+ function n(e) {
7
+ return e ? e.startsWith("http") || !t ? e : `${t.replace(/\/+$/, "")}/${e.replace(/^\/+/, "")}` : null;
7
8
  }
8
- function a(r) {
9
- const e = Array.isArray(r.product_media) ? [...r.product_media].sort(
10
- (t, u) => (t.sort_order ?? 0) - (u.sort_order ?? 0)
11
- ) : [], n = e[0]?.media?.file_path || e[0]?.media?.object_key || null;
12
- return o(n);
9
+ function r(e) {
10
+ let t = Array.isArray(e.product_media) ? [...e.product_media].sort((e, t) => (e.sort_order ?? 0) - (t.sort_order ?? 0)) : [];
11
+ return n(t[0]?.media?.file_path || t[0]?.media?.object_key || null);
13
12
  }
14
- function s(r) {
15
- return (r || []).map((e) => ({
16
- id: e.id,
17
- title: e.title,
18
- sku: e.sku ?? null,
19
- payment_provider: e.payment_provider || "stripe",
20
- freemius_product_id: e.freemius_product_id ?? null,
21
- thumbnailUrl: a(e),
22
- language: l(e.language)
23
- }));
13
+ function i(t) {
14
+ return (t || []).map((t) => ({
15
+ id: t.id,
16
+ title: t.title,
17
+ sku: t.sku ?? null,
18
+ payment_provider: t.payment_provider || "stripe",
19
+ freemius_product_id: t.freemius_product_id ?? null,
20
+ thumbnailUrl: r(t),
21
+ language: e(t.language)
22
+ }));
24
23
  }
25
- export {
26
- s as normalizeCouponProductOptions
27
- };
24
+ //#endregion
25
+ export { i as normalizeCouponProductOptions };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),t=require("@nextblock-cms/ui"),r=require("lucide-react"),l=require("sonner"),b=require("./export-actions.cjs.js"),c=require("../../../export-helpers.cjs.js");function D(){const[g,p]=s.useState(!1),[x,d]=s.useState(!1),[n,m]=s.useState(""),[o,h]=s.useState(""),[u,j]=s.useState("general_ledger"),y=async()=>{if(!n||!o){l.toast.error("Please select both start and end dates");return}d(!0);try{l.toast.info("Generating report...");const a=await b.fetchOrderReportData(n,o);if(!a||a.length===0){l.toast.error("No orders found for the selected date range"),d(!1);return}let i=[];const f=`report_${u}_${n}_to_${o}`;switch(u){case"general_ledger":i=c.mapGeneralSalesLedger(a);break;case"tax_liability":i=c.mapTaxLiabilitySummary(a);break;case"currency_summary":i=c.mapMultiCurrencyRevenue(a);break}c.generateCSV(i,`${f}.csv`),l.toast.success("Download complete!"),p(!1)}catch(a){console.error("Export error:",a),l.toast.error("Failed to generate report")}finally{d(!1)}};return e.jsxs(t.Dialog,{open:g,onOpenChange:p,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(r.Download,{className:"h-4 w-4"}),"Export Reports"]})}),e.jsxs(t.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsxs(t.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx(r.FileDown,{className:"h-5 w-5 text-blue-600"}),"Accounting Reports"]}),e.jsx(t.DialogDescription,{children:"Generate and download accountant-friendly order reports."})]}),e.jsxs("div",{className:"grid gap-6 py-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(t.Label,{htmlFor:"start-date",className:"text-xs font-semibold uppercase text-gray-500 tracking-wider",children:"Start Date"}),e.jsxs("div",{className:"relative",children:[e.jsx(t.Input,{id:"start-date",type:"date",value:n,onChange:a=>m(a.target.value),className:"pl-8"}),e.jsx(r.Calendar,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(t.Label,{htmlFor:"end-date",className:"text-xs font-semibold uppercase text-gray-500 tracking-wider",children:"End Date"}),e.jsxs("div",{className:"relative",children:[e.jsx(t.Input,{id:"end-date",type:"date",value:o,onChange:a=>h(a.target.value),className:"pl-8"}),e.jsx(r.Calendar,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(t.Label,{htmlFor:"report-type",className:"text-xs font-semibold uppercase text-gray-500 tracking-wider",children:"Report Type"}),e.jsxs(t.Select,{value:u,onValueChange:a=>j(a),children:[e.jsx(t.SelectTrigger,{id:"report-type",className:"w-full",children:e.jsx(t.SelectValue,{placeholder:"Select report type"})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"general_ledger",children:"General Sales Ledger"}),e.jsx(t.SelectItem,{value:"tax_liability",children:"Tax Liability Summary"}),e.jsx(t.SelectItem,{value:"currency_summary",children:"Multi-Currency Revenue Summary"})]})]})]})]}),e.jsx(t.DialogFooter,{children:e.jsx(t.Button,{onClick:y,disabled:x,className:"w-full bg-blue-600 hover:bg-blue-700 text-white",children:x?e.jsxs(e.Fragment,{children:[e.jsx(r.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Download,{className:"mr-2 h-4 w-4"}),"Download Report"]})})})]})]})}exports.ExportReportsDialog=D;
1
+ "use client";const e=require("../../../../_virtual/_rolldown/runtime.cjs.js"),t=require("./export-actions.cjs.js"),n=require("../../../export-helpers.cjs.js");let r=require("react");r=e.__toESM(r,1);let i=require("lucide-react"),a=require("react/jsx-runtime"),o=require("sonner"),s=require("@nextblock-cms/ui");function c(){let[e,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(``),[h,g]=(0,r.useState)(`general_ledger`);return(0,a.jsxs)(s.Dialog,{open:e,onOpenChange:c,children:[(0,a.jsx)(s.DialogTrigger,{asChild:!0,children:(0,a.jsxs)(s.Button,{variant:`outline`,className:`flex items-center gap-2`,children:[(0,a.jsx)(i.Download,{className:`h-4 w-4`}),`Export Reports`]})}),(0,a.jsxs)(s.DialogContent,{className:`sm:max-w-[425px]`,children:[(0,a.jsxs)(s.DialogHeader,{children:[(0,a.jsxs)(s.DialogTitle,{className:`flex items-center gap-2`,children:[(0,a.jsx)(i.FileDown,{className:`h-5 w-5 text-blue-600`}),`Accounting Reports`]}),(0,a.jsx)(s.DialogDescription,{children:`Generate and download accountant-friendly order reports.`})]}),(0,a.jsxs)(`div`,{className:`grid gap-6 py-4`,children:[(0,a.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,a.jsxs)(`div`,{className:`grid gap-2`,children:[(0,a.jsx)(s.Label,{htmlFor:`start-date`,className:`text-xs font-semibold uppercase text-gray-500 tracking-wider`,children:`Start Date`}),(0,a.jsxs)(`div`,{className:`relative`,children:[(0,a.jsx)(s.Input,{id:`start-date`,type:`date`,value:d,onChange:e=>f(e.target.value),className:`pl-8`}),(0,a.jsx)(i.Calendar,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`})]})]}),(0,a.jsxs)(`div`,{className:`grid gap-2`,children:[(0,a.jsx)(s.Label,{htmlFor:`end-date`,className:`text-xs font-semibold uppercase text-gray-500 tracking-wider`,children:`End Date`}),(0,a.jsxs)(`div`,{className:`relative`,children:[(0,a.jsx)(s.Input,{id:`end-date`,type:`date`,value:p,onChange:e=>m(e.target.value),className:`pl-8`}),(0,a.jsx)(i.Calendar,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`})]})]})]}),(0,a.jsxs)(`div`,{className:`grid gap-2`,children:[(0,a.jsx)(s.Label,{htmlFor:`report-type`,className:`text-xs font-semibold uppercase text-gray-500 tracking-wider`,children:`Report Type`}),(0,a.jsxs)(s.Select,{value:h,onValueChange:e=>g(e),children:[(0,a.jsx)(s.SelectTrigger,{id:`report-type`,className:`w-full`,children:(0,a.jsx)(s.SelectValue,{placeholder:`Select report type`})}),(0,a.jsxs)(s.SelectContent,{children:[(0,a.jsx)(s.SelectItem,{value:`general_ledger`,children:`General Sales Ledger`}),(0,a.jsx)(s.SelectItem,{value:`tax_liability`,children:`Tax Liability Summary`}),(0,a.jsx)(s.SelectItem,{value:`currency_summary`,children:`Multi-Currency Revenue Summary`})]})]})]})]}),(0,a.jsx)(s.DialogFooter,{children:(0,a.jsx)(s.Button,{onClick:async()=>{if(!d||!p){o.toast.error(`Please select both start and end dates`);return}u(!0);try{o.toast.info(`Generating report...`);let e=await t.fetchOrderReportData(d,p);if(!e||e.length===0){o.toast.error(`No orders found for the selected date range`),u(!1);return}let r=[],i=`report_${h}_${d}_to_${p}`;switch(h){case`general_ledger`:r=n.mapGeneralSalesLedger(e);break;case`tax_liability`:r=n.mapTaxLiabilitySummary(e);break;case`currency_summary`:r=n.mapMultiCurrencyRevenue(e)}n.generateCSV(r,`${i}.csv`),o.toast.success(`Download complete!`),c(!1)}catch(e){console.error(`Export error:`,e),o.toast.error(`Failed to generate report`)}finally{u(!1)}},disabled:l,className:`w-full bg-blue-600 hover:bg-blue-700 text-white`,children:l?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(i.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),`Generating...`]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(i.Download,{className:`mr-2 h-4 w-4`}),`Download Report`]})})})]})]})}exports.ExportReportsDialog=c;
@@ -1,130 +1,136 @@
1
- 'use client';
2
- import { jsxs as a, jsx as e, Fragment as h } from "react/jsx-runtime";
3
- import { useState as t } from "react";
4
- import { Dialog as S, DialogTrigger as C, Button as u, DialogContent as _, DialogHeader as R, DialogTitle as T, DialogDescription as k, Label as d, Input as f, Select as F, SelectTrigger as L, SelectValue as E, SelectContent as G, SelectItem as m, DialogFooter as $ } from "@nextblock-cms/ui";
5
- import { Download as y, FileDown as O, Calendar as x, Loader2 as V } from "lucide-react";
6
- import { toast as l } from "sonner";
7
- import { fetchOrderReportData as j } from "./export-actions.es.js";
8
- import { mapMultiCurrencyRevenue as I, mapTaxLiabilitySummary as M, mapGeneralSalesLedger as A, generateCSV as B } from "../../../export-helpers.es.js";
9
- function W() {
10
- const [N, p] = t(!1), [g, i] = t(!1), [n, D] = t(""), [o, v] = t(""), [c, w] = t("general_ledger");
11
- return /* @__PURE__ */ a(S, { open: N, onOpenChange: p, children: [
12
- /* @__PURE__ */ e(C, { asChild: !0, children: /* @__PURE__ */ a(u, { variant: "outline", className: "flex items-center gap-2", children: [
13
- /* @__PURE__ */ e(y, { className: "h-4 w-4" }),
14
- "Export Reports"
15
- ] }) }),
16
- /* @__PURE__ */ a(_, { className: "sm:max-w-[425px]", children: [
17
- /* @__PURE__ */ a(R, { children: [
18
- /* @__PURE__ */ a(T, { className: "flex items-center gap-2", children: [
19
- /* @__PURE__ */ e(O, { className: "h-5 w-5 text-blue-600" }),
20
- "Accounting Reports"
21
- ] }),
22
- /* @__PURE__ */ e(k, { children: "Generate and download accountant-friendly order reports." })
23
- ] }),
24
- /* @__PURE__ */ a("div", { className: "grid gap-6 py-4", children: [
25
- /* @__PURE__ */ a("div", { className: "grid grid-cols-2 gap-4", children: [
26
- /* @__PURE__ */ a("div", { className: "grid gap-2", children: [
27
- /* @__PURE__ */ e(d, { htmlFor: "start-date", className: "text-xs font-semibold uppercase text-gray-500 tracking-wider", children: "Start Date" }),
28
- /* @__PURE__ */ a("div", { className: "relative", children: [
29
- /* @__PURE__ */ e(
30
- f,
31
- {
32
- id: "start-date",
33
- type: "date",
34
- value: n,
35
- onChange: (r) => D(r.target.value),
36
- className: "pl-8"
37
- }
38
- ),
39
- /* @__PURE__ */ e(x, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" })
40
- ] })
41
- ] }),
42
- /* @__PURE__ */ a("div", { className: "grid gap-2", children: [
43
- /* @__PURE__ */ e(d, { htmlFor: "end-date", className: "text-xs font-semibold uppercase text-gray-500 tracking-wider", children: "End Date" }),
44
- /* @__PURE__ */ a("div", { className: "relative", children: [
45
- /* @__PURE__ */ e(
46
- f,
47
- {
48
- id: "end-date",
49
- type: "date",
50
- value: o,
51
- onChange: (r) => v(r.target.value),
52
- className: "pl-8"
53
- }
54
- ),
55
- /* @__PURE__ */ e(x, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" })
56
- ] })
57
- ] })
58
- ] }),
59
- /* @__PURE__ */ a("div", { className: "grid gap-2", children: [
60
- /* @__PURE__ */ e(d, { htmlFor: "report-type", className: "text-xs font-semibold uppercase text-gray-500 tracking-wider", children: "Report Type" }),
61
- /* @__PURE__ */ a(
62
- F,
63
- {
64
- value: c,
65
- onValueChange: (r) => w(r),
66
- children: [
67
- /* @__PURE__ */ e(L, { id: "report-type", className: "w-full", children: /* @__PURE__ */ e(E, { placeholder: "Select report type" }) }),
68
- /* @__PURE__ */ a(G, { children: [
69
- /* @__PURE__ */ e(m, { value: "general_ledger", children: "General Sales Ledger" }),
70
- /* @__PURE__ */ e(m, { value: "tax_liability", children: "Tax Liability Summary" }),
71
- /* @__PURE__ */ e(m, { value: "currency_summary", children: "Multi-Currency Revenue Summary" })
72
- ] })
73
- ]
74
- }
75
- )
76
- ] })
77
- ] }),
78
- /* @__PURE__ */ e($, { children: /* @__PURE__ */ e(
79
- u,
80
- {
81
- onClick: async () => {
82
- if (!n || !o) {
83
- l.error("Please select both start and end dates");
84
- return;
85
- }
86
- i(!0);
87
- try {
88
- l.info("Generating report...");
89
- const r = await j(n, o);
90
- if (!r || r.length === 0) {
91
- l.error("No orders found for the selected date range"), i(!1);
92
- return;
93
- }
94
- let s = [];
95
- const b = `report_${c}_${n}_to_${o}`;
96
- switch (c) {
97
- case "general_ledger":
98
- s = A(r);
99
- break;
100
- case "tax_liability":
101
- s = M(r);
102
- break;
103
- case "currency_summary":
104
- s = I(r);
105
- break;
106
- }
107
- B(s, `${b}.csv`), l.success("Download complete!"), p(!1);
108
- } catch (r) {
109
- console.error("Export error:", r), l.error("Failed to generate report");
110
- } finally {
111
- i(!1);
112
- }
113
- },
114
- disabled: g,
115
- className: "w-full bg-blue-600 hover:bg-blue-700 text-white",
116
- children: g ? /* @__PURE__ */ a(h, { children: [
117
- /* @__PURE__ */ e(V, { className: "mr-2 h-4 w-4 animate-spin" }),
118
- "Generating..."
119
- ] }) : /* @__PURE__ */ a(h, { children: [
120
- /* @__PURE__ */ e(y, { className: "mr-2 h-4 w-4" }),
121
- "Download Report"
122
- ] })
123
- }
124
- ) })
125
- ] })
126
- ] });
1
+ "use client";
2
+ import { fetchOrderReportData as e } from "./export-actions.es.js";
3
+ import { generateCSV as t, mapGeneralSalesLedger as n, mapMultiCurrencyRevenue as r, mapTaxLiabilitySummary as i } from "../../../export-helpers.es.js";
4
+ import { useState as a } from "react";
5
+ import { Calendar as o, Download as s, FileDown as c, Loader2 as l } from "lucide-react";
6
+ import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
7
+ import { toast as p } from "sonner";
8
+ import { Button as m, Dialog as h, DialogContent as g, DialogDescription as _, DialogFooter as v, DialogHeader as y, DialogTitle as b, DialogTrigger as x, Input as S, Label as C, Select as w, SelectContent as T, SelectItem as E, SelectTrigger as D, SelectValue as O } from "@nextblock-cms/ui";
9
+ //#region libs/ecommerce/src/lib/pages/cms/orders/ExportReportsDialog.tsx
10
+ function k() {
11
+ let [k, A] = a(!1), [j, M] = a(!1), [N, P] = a(""), [F, I] = a(""), [L, R] = a("general_ledger");
12
+ return /* @__PURE__ */ f(h, {
13
+ open: k,
14
+ onOpenChange: A,
15
+ children: [/* @__PURE__ */ d(x, {
16
+ asChild: !0,
17
+ children: /* @__PURE__ */ f(m, {
18
+ variant: "outline",
19
+ className: "flex items-center gap-2",
20
+ children: [/* @__PURE__ */ d(s, { className: "h-4 w-4" }), "Export Reports"]
21
+ })
22
+ }), /* @__PURE__ */ f(g, {
23
+ className: "sm:max-w-[425px]",
24
+ children: [
25
+ /* @__PURE__ */ f(y, { children: [/* @__PURE__ */ f(b, {
26
+ className: "flex items-center gap-2",
27
+ children: [/* @__PURE__ */ d(c, { className: "h-5 w-5 text-blue-600" }), "Accounting Reports"]
28
+ }), /* @__PURE__ */ d(_, { children: "Generate and download accountant-friendly order reports." })] }),
29
+ /* @__PURE__ */ f("div", {
30
+ className: "grid gap-6 py-4",
31
+ children: [/* @__PURE__ */ f("div", {
32
+ className: "grid grid-cols-2 gap-4",
33
+ children: [/* @__PURE__ */ f("div", {
34
+ className: "grid gap-2",
35
+ children: [/* @__PURE__ */ d(C, {
36
+ htmlFor: "start-date",
37
+ className: "text-xs font-semibold uppercase text-gray-500 tracking-wider",
38
+ children: "Start Date"
39
+ }), /* @__PURE__ */ f("div", {
40
+ className: "relative",
41
+ children: [/* @__PURE__ */ d(S, {
42
+ id: "start-date",
43
+ type: "date",
44
+ value: N,
45
+ onChange: (e) => P(e.target.value),
46
+ className: "pl-8"
47
+ }), /* @__PURE__ */ d(o, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" })]
48
+ })]
49
+ }), /* @__PURE__ */ f("div", {
50
+ className: "grid gap-2",
51
+ children: [/* @__PURE__ */ d(C, {
52
+ htmlFor: "end-date",
53
+ className: "text-xs font-semibold uppercase text-gray-500 tracking-wider",
54
+ children: "End Date"
55
+ }), /* @__PURE__ */ f("div", {
56
+ className: "relative",
57
+ children: [/* @__PURE__ */ d(S, {
58
+ id: "end-date",
59
+ type: "date",
60
+ value: F,
61
+ onChange: (e) => I(e.target.value),
62
+ className: "pl-8"
63
+ }), /* @__PURE__ */ d(o, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" })]
64
+ })]
65
+ })]
66
+ }), /* @__PURE__ */ f("div", {
67
+ className: "grid gap-2",
68
+ children: [/* @__PURE__ */ d(C, {
69
+ htmlFor: "report-type",
70
+ className: "text-xs font-semibold uppercase text-gray-500 tracking-wider",
71
+ children: "Report Type"
72
+ }), /* @__PURE__ */ f(w, {
73
+ value: L,
74
+ onValueChange: (e) => R(e),
75
+ children: [/* @__PURE__ */ d(D, {
76
+ id: "report-type",
77
+ className: "w-full",
78
+ children: /* @__PURE__ */ d(O, { placeholder: "Select report type" })
79
+ }), /* @__PURE__ */ f(T, { children: [
80
+ /* @__PURE__ */ d(E, {
81
+ value: "general_ledger",
82
+ children: "General Sales Ledger"
83
+ }),
84
+ /* @__PURE__ */ d(E, {
85
+ value: "tax_liability",
86
+ children: "Tax Liability Summary"
87
+ }),
88
+ /* @__PURE__ */ d(E, {
89
+ value: "currency_summary",
90
+ children: "Multi-Currency Revenue Summary"
91
+ })
92
+ ] })]
93
+ })]
94
+ })]
95
+ }),
96
+ /* @__PURE__ */ d(v, { children: /* @__PURE__ */ d(m, {
97
+ onClick: async () => {
98
+ if (!N || !F) {
99
+ p.error("Please select both start and end dates");
100
+ return;
101
+ }
102
+ M(!0);
103
+ try {
104
+ p.info("Generating report...");
105
+ let a = await e(N, F);
106
+ if (!a || a.length === 0) {
107
+ p.error("No orders found for the selected date range"), M(!1);
108
+ return;
109
+ }
110
+ let o = [], s = `report_${L}_${N}_to_${F}`;
111
+ switch (L) {
112
+ case "general_ledger":
113
+ o = n(a);
114
+ break;
115
+ case "tax_liability":
116
+ o = i(a);
117
+ break;
118
+ case "currency_summary": o = r(a);
119
+ }
120
+ t(o, `${s}.csv`), p.success("Download complete!"), A(!1);
121
+ } catch (e) {
122
+ console.error("Export error:", e), p.error("Failed to generate report");
123
+ } finally {
124
+ M(!1);
125
+ }
126
+ },
127
+ disabled: j,
128
+ className: "w-full bg-blue-600 hover:bg-blue-700 text-white",
129
+ children: j ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(l, { className: "mr-2 h-4 w-4 animate-spin" }), "Generating..."] }) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(s, { className: "mr-2 h-4 w-4" }), "Download Report"] })
130
+ }) })
131
+ ]
132
+ })]
133
+ });
127
134
  }
128
- export {
129
- W as ExportReportsDialog
130
- };
135
+ //#endregion
136
+ export { k as ExportReportsDialog };