@nextblock-cms/ecom 0.20.1 → 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,172 +1,214 @@
1
- import { jsxs as a, jsx as e, Fragment as b } from "react/jsx-runtime";
2
- import { createClient as S, getServiceRoleSupabaseClient as w } from "@nextblock-cms/db/server";
3
- import { Button as l, Badge as u, Card as n, CardHeader as s, CardTitle as d, CardDescription as c, CardContent as o } from "@nextblock-cms/ui";
4
- import { ArrowLeft as T, Settings2 as C, ShieldCheck as _, Trash2 as k } from "lucide-react";
5
- import f from "next/link";
6
- import { getEcommerceInventorySettings as M } from "../../../inventory-settings.es.js";
7
- import { resolveSubdivisionName as A } from "../../../states.es.js";
8
- import { getEnabledPaymentProviders as R } from "../payments/queries.es.js";
9
- import { updateTaxSettingsAction as P, deleteTaxRateAction as j } from "./actions.es.js";
10
- import { TaxRateForm as g } from "./components/TaxRateForm.es.js";
11
- function E(t) {
12
- return `${t.toFixed(4).replace(/\.?0+$/, "")}%`;
1
+ import { resolveSubdivisionName as e } from "../../../states.es.js";
2
+ import { getEcommerceInventorySettings as t } from "../../../inventory-settings.es.js";
3
+ import { getEnabledPaymentProviders as n } from "../payments/queries.es.js";
4
+ import { deleteTaxRateAction as r, updateTaxSettingsAction as i } from "./actions.es.js";
5
+ import { TaxRateForm as a } from "./components/TaxRateForm.es.js";
6
+ import o from "next/link";
7
+ import { ArrowLeft as s, Settings2 as c, ShieldCheck as l, Trash2 as u } from "lucide-react";
8
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
9
+ import { createClient as m, getServiceRoleSupabaseClient as h } from "@nextblock-cms/db/server";
10
+ import { Badge as g, Button as _, Card as v, CardContent as y, CardDescription as b, CardHeader as x, CardTitle as S } from "@nextblock-cms/ui";
11
+ //#region libs/ecommerce/src/lib/pages/cms/taxes/TaxesPage.tsx
12
+ function C(e) {
13
+ return `${e.toFixed(4).replace(/\.?0+$/, "")}%`;
13
14
  }
14
- function F(t) {
15
- return t.state_code ? `${t.country_code} - ${A(t.country_code, t.state_code)}` : `${t.country_code} - Country-wide`;
15
+ function w(t) {
16
+ return t.state_code ? `${t.country_code} - ${e(t.country_code, t.state_code)}` : `${t.country_code} - Country-wide`;
16
17
  }
17
- async function U({
18
- searchParams: t
19
- }) {
20
- const y = S(), v = w(), [i, N, h] = await Promise.all([
21
- M(y),
22
- R(),
23
- v.from("tax_rates").select("id, country_code, state_code, tax_name, tax_rate, created_at, updated_at").order("country_code").order("state_code").order("tax_name")
24
- ]), p = h.data || [], x = h.error, m = N.stripe;
25
- return /* @__PURE__ */ a("div", { className: "mx-auto w-full max-w-6xl space-y-6 px-6 py-8", children: [
26
- t?.success ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-700", children: t.success }) : null,
27
- /* @__PURE__ */ a("div", { className: "flex items-center justify-between gap-4", children: [
28
- /* @__PURE__ */ a("div", { className: "flex items-center gap-3", children: [
29
- /* @__PURE__ */ e(l, { asChild: !0, variant: "outline", size: "icon", "aria-label": "Back to shipping", children: /* @__PURE__ */ e(f, { href: "/cms/shipping", children: /* @__PURE__ */ e(T, { className: "h-4 w-4" }) }) }),
30
- /* @__PURE__ */ a("div", { children: [
31
- /* @__PURE__ */ e("h1", { className: "text-2xl font-bold", children: "Tax Settings" }),
32
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "Configure Stripe tax behavior globally and maintain manual country or state/province tax rates for physical goods." })
33
- ] })
34
- ] }),
35
- /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
36
- /* @__PURE__ */ a(u, { variant: m ? "default" : "outline", className: "uppercase", children: [
37
- "Stripe ",
38
- m ? "Enabled" : "Disabled"
39
- ] }),
40
- /* @__PURE__ */ e("div", { className: "rounded-full border bg-muted/30 p-3 text-muted-foreground", children: /* @__PURE__ */ e(C, { className: "h-5 w-5" }) })
41
- ] })
42
- ] }),
43
- m ? /* @__PURE__ */ a(b, { children: [
44
- /* @__PURE__ */ a(n, { children: [
45
- /* @__PURE__ */ a(s, { children: [
46
- /* @__PURE__ */ e(d, { children: "Global Tax Controls" }),
47
- /* @__PURE__ */ e(c, { children: "Manual mode uses the tax rates below. Automatic mode uses Stripe Tax during Stripe Checkout instead of a free third-party tax API." })
48
- ] }),
49
- /* @__PURE__ */ e(o, { children: /* @__PURE__ */ a("form", { action: P, className: "space-y-6", children: [
50
- /* @__PURE__ */ a("div", { className: "rounded-lg border bg-muted/20 p-4", children: [
51
- /* @__PURE__ */ e("input", { type: "hidden", name: "enableTaxes", value: "false" }),
52
- /* @__PURE__ */ a("label", { htmlFor: "enable-taxes", className: "flex cursor-pointer items-start gap-3", children: [
53
- /* @__PURE__ */ e(
54
- "input",
55
- {
56
- id: "enable-taxes",
57
- name: "enableTaxes",
58
- type: "checkbox",
59
- value: "true",
60
- defaultChecked: i.enableTaxes,
61
- className: "mt-1 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"
62
- }
63
- ),
64
- /* @__PURE__ */ a("span", { className: "space-y-1", children: [
65
- /* @__PURE__ */ e("span", { className: "block font-medium", children: "Enable taxes" }),
66
- /* @__PURE__ */ e("span", { className: "block text-sm text-muted-foreground", children: "When disabled, tax totals resolve to zero even if product or jurisdiction records exist." })
67
- ] })
68
- ] })
69
- ] }),
70
- /* @__PURE__ */ a("div", { className: "grid gap-4 md:grid-cols-[minmax(0,1fr)_auto] md:items-end", children: [
71
- /* @__PURE__ */ a("div", { className: "space-y-2", children: [
72
- /* @__PURE__ */ e(
73
- "label",
74
- {
75
- htmlFor: "tax-calculation-mode",
76
- className: "text-sm font-medium text-foreground",
77
- children: "Tax calculation mode"
78
- }
79
- ),
80
- /* @__PURE__ */ a(
81
- "select",
82
- {
83
- id: "tax-calculation-mode",
84
- name: "taxCalculationMode",
85
- defaultValue: i.taxCalculationMode,
86
- className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
87
- children: [
88
- /* @__PURE__ */ e("option", { value: "manual", children: "Manual tax rates" }),
89
- /* @__PURE__ */ e("option", { value: "automatic", children: "Automatic via Stripe Tax" })
90
- ]
91
- }
92
- ),
93
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "Automatic mode depends on your Stripe Tax setup. Manual rates stay saved and can be used again if you switch back later." })
94
- ] }),
95
- /* @__PURE__ */ e("div", { className: "flex justify-end", children: /* @__PURE__ */ e(l, { type: "submit", children: "Save Tax Settings" }) })
96
- ] })
97
- ] }) })
98
- ] }),
99
- /* @__PURE__ */ a(n, { children: [
100
- /* @__PURE__ */ e(s, { children: /* @__PURE__ */ a("div", { className: "flex items-center justify-between gap-4", children: [
101
- /* @__PURE__ */ a("div", { children: [
102
- /* @__PURE__ */ e(d, { children: "Manual Tax Rates" }),
103
- /* @__PURE__ */ e(c, { children: "Add combined taxes as separate rows. For example, create both GST and PST for the same province if they should stack." })
104
- ] }),
105
- /* @__PURE__ */ e(u, { variant: i.taxCalculationMode === "manual" ? "default" : "outline", children: i.taxCalculationMode === "manual" ? "Active Mode" : "Stored for Manual Mode" })
106
- ] }) }),
107
- /* @__PURE__ */ a(o, { className: "space-y-6", children: [
108
- x ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800", children: "Tax rates couldn't be loaded yet. This usually means the new tax migration hasn't been applied to the current database." }) : null,
109
- x ? null : /* @__PURE__ */ a(b, { children: [
110
- /* @__PURE__ */ a("div", { className: "rounded-xl border bg-card p-4", children: [
111
- /* @__PURE__ */ a("div", { className: "mb-4 flex items-center gap-2", children: [
112
- /* @__PURE__ */ e(_, { className: "h-4 w-4 text-primary" }),
113
- /* @__PURE__ */ e("h2", { className: "font-semibold", children: "Create a Tax Rate" })
114
- ] }),
115
- /* @__PURE__ */ e(g, {})
116
- ] }),
117
- /* @__PURE__ */ e("div", { className: "space-y-4", children: p.length === 0 ? /* @__PURE__ */ a("div", { className: "rounded-xl border border-dashed bg-muted/10 px-4 py-8 text-center", children: [
118
- /* @__PURE__ */ e("p", { className: "font-medium", children: "No manual tax rates yet" }),
119
- /* @__PURE__ */ e("p", { className: "mt-1 text-sm text-muted-foreground", children: "Add country-wide or state/province-specific rows to start calculating manual taxes." })
120
- ] }) : p.map((r) => /* @__PURE__ */ a(n, { className: "border-muted", children: [
121
- /* @__PURE__ */ e(s, { className: "pb-4", children: /* @__PURE__ */ a("div", { className: "flex items-start justify-between gap-4", children: [
122
- /* @__PURE__ */ a("div", { className: "space-y-1", children: [
123
- /* @__PURE__ */ e(d, { className: "text-base", children: r.tax_name }),
124
- /* @__PURE__ */ e(c, { children: F(r) })
125
- ] }),
126
- /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
127
- /* @__PURE__ */ e(u, { variant: "outline", children: E(Number(r.tax_rate)) }),
128
- /* @__PURE__ */ e(
129
- "form",
130
- {
131
- action: async () => {
132
- "use server";
133
- await j(r.id);
134
- },
135
- children: /* @__PURE__ */ e(
136
- l,
137
- {
138
- type: "submit",
139
- variant: "ghost",
140
- size: "icon",
141
- "aria-label": "Delete tax rate",
142
- children: /* @__PURE__ */ e(k, { className: "h-4 w-4" })
143
- }
144
- )
145
- }
146
- )
147
- ] })
148
- ] }) }),
149
- /* @__PURE__ */ e(o, { children: /* @__PURE__ */ e(
150
- g,
151
- {
152
- initialData: r,
153
- submitLabel: "Update tax rate",
154
- compact: !0
155
- }
156
- ) })
157
- ] }, r.id)) })
158
- ] })
159
- ] })
160
- ] })
161
- ] }) : /* @__PURE__ */ a(n, { className: "border-dashed", children: [
162
- /* @__PURE__ */ a(s, { children: [
163
- /* @__PURE__ */ e(d, { children: "Enable Stripe to configure physical-product taxes" }),
164
- /* @__PURE__ */ e(c, { children: "Stripe tax settings apply whenever Stripe is enabled for physical products. Freemius still handles taxes on its own digital checkout flow." })
165
- ] }),
166
- /* @__PURE__ */ e(o, { children: /* @__PURE__ */ e(l, { asChild: !0, variant: "outline", children: /* @__PURE__ */ e(f, { href: "/cms/payments", children: "Open Payment Settings" }) }) })
167
- ] })
168
- ] });
18
+ async function T({ searchParams: e }) {
19
+ let T = m(), E = h(), [D, O, k] = await Promise.all([
20
+ t(T),
21
+ n(),
22
+ E.from("tax_rates").select("id, country_code, state_code, tax_name, tax_rate, created_at, updated_at").order("country_code").order("state_code").order("tax_name")
23
+ ]), A = k.data || [], j = k.error, M = O.stripe;
24
+ return /* @__PURE__ */ p("div", {
25
+ className: "mx-auto w-full max-w-6xl space-y-6 px-6 py-8",
26
+ children: [
27
+ e?.success ? /* @__PURE__ */ f("div", {
28
+ className: "rounded-lg border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-700",
29
+ children: e.success
30
+ }) : null,
31
+ /* @__PURE__ */ p("div", {
32
+ className: "flex items-center justify-between gap-4",
33
+ children: [/* @__PURE__ */ p("div", {
34
+ className: "flex items-center gap-3",
35
+ children: [/* @__PURE__ */ f(_, {
36
+ asChild: !0,
37
+ variant: "outline",
38
+ size: "icon",
39
+ "aria-label": "Back to shipping",
40
+ children: /* @__PURE__ */ f(o, {
41
+ href: "/cms/shipping",
42
+ children: /* @__PURE__ */ f(s, { className: "h-4 w-4" })
43
+ })
44
+ }), /* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("h1", {
45
+ className: "text-2xl font-bold",
46
+ children: "Tax Settings"
47
+ }), /* @__PURE__ */ f("p", {
48
+ className: "text-sm text-muted-foreground",
49
+ children: "Configure Stripe tax behavior globally and maintain manual country or state/province tax rates for physical goods."
50
+ })] })]
51
+ }), /* @__PURE__ */ p("div", {
52
+ className: "flex items-center gap-2",
53
+ children: [/* @__PURE__ */ p(g, {
54
+ variant: M ? "default" : "outline",
55
+ className: "uppercase",
56
+ children: ["Stripe ", M ? "Enabled" : "Disabled"]
57
+ }), /* @__PURE__ */ f("div", {
58
+ className: "rounded-full border bg-muted/30 p-3 text-muted-foreground",
59
+ children: /* @__PURE__ */ f(c, { className: "h-5 w-5" })
60
+ })]
61
+ })]
62
+ }),
63
+ M ? /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p(v, { children: [/* @__PURE__ */ p(x, { children: [/* @__PURE__ */ f(S, { children: "Global Tax Controls" }), /* @__PURE__ */ f(b, { children: "Manual mode uses the tax rates below. Automatic mode uses Stripe Tax during Stripe Checkout instead of a free third-party tax API." })] }), /* @__PURE__ */ f(y, { children: /* @__PURE__ */ p("form", {
64
+ action: i,
65
+ className: "space-y-6",
66
+ children: [/* @__PURE__ */ p("div", {
67
+ className: "rounded-lg border bg-muted/20 p-4",
68
+ children: [/* @__PURE__ */ f("input", {
69
+ type: "hidden",
70
+ name: "enableTaxes",
71
+ value: "false"
72
+ }), /* @__PURE__ */ p("label", {
73
+ htmlFor: "enable-taxes",
74
+ className: "flex cursor-pointer items-start gap-3",
75
+ children: [/* @__PURE__ */ f("input", {
76
+ id: "enable-taxes",
77
+ name: "enableTaxes",
78
+ type: "checkbox",
79
+ value: "true",
80
+ defaultChecked: D.enableTaxes,
81
+ className: "mt-1 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"
82
+ }), /* @__PURE__ */ p("span", {
83
+ className: "space-y-1",
84
+ children: [/* @__PURE__ */ f("span", {
85
+ className: "block font-medium",
86
+ children: "Enable taxes"
87
+ }), /* @__PURE__ */ f("span", {
88
+ className: "block text-sm text-muted-foreground",
89
+ children: "When disabled, tax totals resolve to zero even if product or jurisdiction records exist."
90
+ })]
91
+ })]
92
+ })]
93
+ }), /* @__PURE__ */ p("div", {
94
+ className: "grid gap-4 md:grid-cols-[minmax(0,1fr)_auto] md:items-end",
95
+ children: [/* @__PURE__ */ p("div", {
96
+ className: "space-y-2",
97
+ children: [
98
+ /* @__PURE__ */ f("label", {
99
+ htmlFor: "tax-calculation-mode",
100
+ className: "text-sm font-medium text-foreground",
101
+ children: "Tax calculation mode"
102
+ }),
103
+ /* @__PURE__ */ p("select", {
104
+ id: "tax-calculation-mode",
105
+ name: "taxCalculationMode",
106
+ defaultValue: D.taxCalculationMode,
107
+ className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
108
+ children: [/* @__PURE__ */ f("option", {
109
+ value: "manual",
110
+ children: "Manual tax rates"
111
+ }), /* @__PURE__ */ f("option", {
112
+ value: "automatic",
113
+ children: "Automatic via Stripe Tax"
114
+ })]
115
+ }),
116
+ /* @__PURE__ */ f("p", {
117
+ className: "text-sm text-muted-foreground",
118
+ children: "Automatic mode depends on your Stripe Tax setup. Manual rates stay saved and can be used again if you switch back later."
119
+ })
120
+ ]
121
+ }), /* @__PURE__ */ f("div", {
122
+ className: "flex justify-end",
123
+ children: /* @__PURE__ */ f(_, {
124
+ type: "submit",
125
+ children: "Save Tax Settings"
126
+ })
127
+ })]
128
+ })]
129
+ }) })] }), /* @__PURE__ */ p(v, { children: [/* @__PURE__ */ f(x, { children: /* @__PURE__ */ p("div", {
130
+ className: "flex items-center justify-between gap-4",
131
+ children: [/* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f(S, { children: "Manual Tax Rates" }), /* @__PURE__ */ f(b, { children: "Add combined taxes as separate rows. For example, create both GST and PST for the same province if they should stack." })] }), /* @__PURE__ */ f(g, {
132
+ variant: D.taxCalculationMode === "manual" ? "default" : "outline",
133
+ children: D.taxCalculationMode === "manual" ? "Active Mode" : "Stored for Manual Mode"
134
+ })]
135
+ }) }), /* @__PURE__ */ p(y, {
136
+ className: "space-y-6",
137
+ children: [j ? /* @__PURE__ */ f("div", {
138
+ className: "rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",
139
+ children: "Tax rates couldn't be loaded yet. This usually means the new tax migration hasn't been applied to the current database."
140
+ }) : null, j ? null : /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("div", {
141
+ className: "rounded-xl border bg-card p-4",
142
+ children: [/* @__PURE__ */ p("div", {
143
+ className: "mb-4 flex items-center gap-2",
144
+ children: [/* @__PURE__ */ f(l, { className: "h-4 w-4 text-primary" }), /* @__PURE__ */ f("h2", {
145
+ className: "font-semibold",
146
+ children: "Create a Tax Rate"
147
+ })]
148
+ }), /* @__PURE__ */ f(a, {})]
149
+ }), /* @__PURE__ */ f("div", {
150
+ className: "space-y-4",
151
+ children: A.length === 0 ? /* @__PURE__ */ p("div", {
152
+ className: "rounded-xl border border-dashed bg-muted/10 px-4 py-8 text-center",
153
+ children: [/* @__PURE__ */ f("p", {
154
+ className: "font-medium",
155
+ children: "No manual tax rates yet"
156
+ }), /* @__PURE__ */ f("p", {
157
+ className: "mt-1 text-sm text-muted-foreground",
158
+ children: "Add country-wide or state/province-specific rows to start calculating manual taxes."
159
+ })]
160
+ }) : A.map((e) => /* @__PURE__ */ p(v, {
161
+ className: "border-muted",
162
+ children: [/* @__PURE__ */ f(x, {
163
+ className: "pb-4",
164
+ children: /* @__PURE__ */ p("div", {
165
+ className: "flex items-start justify-between gap-4",
166
+ children: [/* @__PURE__ */ p("div", {
167
+ className: "space-y-1",
168
+ children: [/* @__PURE__ */ f(S, {
169
+ className: "text-base",
170
+ children: e.tax_name
171
+ }), /* @__PURE__ */ f(b, { children: w(e) })]
172
+ }), /* @__PURE__ */ p("div", {
173
+ className: "flex items-center gap-2",
174
+ children: [/* @__PURE__ */ f(g, {
175
+ variant: "outline",
176
+ children: C(Number(e.tax_rate))
177
+ }), /* @__PURE__ */ f("form", {
178
+ action: async () => {
179
+ "use server";
180
+ await r(e.id);
181
+ },
182
+ children: /* @__PURE__ */ f(_, {
183
+ type: "submit",
184
+ variant: "ghost",
185
+ size: "icon",
186
+ "aria-label": "Delete tax rate",
187
+ children: /* @__PURE__ */ f(u, { className: "h-4 w-4" })
188
+ })
189
+ })]
190
+ })]
191
+ })
192
+ }), /* @__PURE__ */ f(y, { children: /* @__PURE__ */ f(a, {
193
+ initialData: e,
194
+ submitLabel: "Update tax rate",
195
+ compact: !0
196
+ }) })]
197
+ }, e.id))
198
+ })] })]
199
+ })] })] }) : /* @__PURE__ */ p(v, {
200
+ className: "border-dashed",
201
+ children: [/* @__PURE__ */ p(x, { children: [/* @__PURE__ */ f(S, { children: "Enable Stripe to configure physical-product taxes" }), /* @__PURE__ */ f(b, { children: "Stripe tax settings apply whenever Stripe is enabled for physical products. Freemius still handles taxes on its own digital checkout flow." })] }), /* @__PURE__ */ f(y, { children: /* @__PURE__ */ f(_, {
202
+ asChild: !0,
203
+ variant: "outline",
204
+ children: /* @__PURE__ */ f(o, {
205
+ href: "/cms/payments",
206
+ children: "Open Payment Settings"
207
+ })
208
+ }) })]
209
+ })
210
+ ]
211
+ });
169
212
  }
170
- export {
171
- U as TaxesPage
172
- };
213
+ //#endregion
214
+ export { T as TaxesPage };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@nextblock-cms/db/server"),i=require("next/cache"),w=require("next/navigation"),x=require("../../../countries.cjs.js"),g=require("../../../inventory-settings.cjs.js"),h=require("../../../states.cjs.js");async function c(){const t=m.createClient(),{data:{user:e}}=await t.auth.getUser();if(!e)throw new Error("Unauthorized");const{data:a}=await t.from("profiles").select("role").eq("id",e.id).single();if(!a||a.role!=="ADMIN")throw new Error("Forbidden");return t}async function y(t){const e=await c(),a=await g.getEcommerceInventorySettings(e),r=t.getAll("enableTaxes").includes("true"),o=t.get("taxCalculationMode")==="automatic"?"automatic":"manual",{error:n}=await g.upsertEcommerceInventorySettings(e,{trackQuantities:a.trackQuantities,enableTaxes:r,taxCalculationMode:o});if(n)throw new Error(n.message);i.revalidatePath("/cms/shipping"),i.revalidatePath("/cms/settings/taxes"),w.redirect("/cms/settings/taxes?success=Tax settings updated")}async function p(t){const e=await c(),a=String(t.get("id")||"").trim(),r=x.normalizeCountryCode(String(t.get("country_code")||"").trim()),o=String(t.get("state_code")||"").trim(),n=String(t.get("tax_name")||"").trim(),s=Number(t.get("tax_rate"));if(!r)throw new Error("Country code is required.");if(!n)throw new Error("Tax name is required.");if(!Number.isFinite(s)||s<0||s>100)throw new Error("Tax rate must be between 0 and 100.");const u={country_code:r,state_code:h.normalizeSubdivisionCode(r,o)||null,tax_name:n,tax_rate:s},l=a?e.from("tax_rates").update(u).eq("id",a):e.from("tax_rates").insert(u),{error:d}=await l;if(d)throw new Error(d.message);i.revalidatePath("/cms/settings/taxes")}async function b(t){const e=await c(),{error:a}=await e.from("tax_rates").delete().eq("id",t);if(a)throw new Error(a.message);i.revalidatePath("/cms/settings/taxes")}exports.deleteTaxRateAction=b;exports.saveTaxRateAction=p;exports.updateTaxSettingsAction=y;
1
+ "use server";const e=require("../../../countries.cjs.js"),t=require("../../../states.cjs.js"),n=require("../../../inventory-settings.cjs.js");let r=require("@nextblock-cms/db/server"),i=require("next/navigation"),a=require("next/cache");async function o(){let e=(0,r.createClient)(),{data:{user:t}}=await e.auth.getUser();if(!t)throw Error(`Unauthorized`);let{data:n}=await e.from(`profiles`).select(`role`).eq(`id`,t.id).single();if(!n||n.role!==`ADMIN`)throw Error(`Forbidden`);return e}async function s(e){let t=await o(),r=await n.getEcommerceInventorySettings(t),s=e.getAll(`enableTaxes`).includes(`true`),c=e.get(`taxCalculationMode`)===`automatic`?`automatic`:`manual`,{error:l}=await n.upsertEcommerceInventorySettings(t,{trackQuantities:r.trackQuantities,enableTaxes:s,taxCalculationMode:c});if(l)throw Error(l.message);(0,a.revalidatePath)(`/cms/shipping`),(0,a.revalidatePath)(`/cms/settings/taxes`),(0,i.redirect)(`/cms/settings/taxes?success=Tax settings updated`)}async function c(n){let r=await o(),i=String(n.get(`id`)||``).trim(),s=e.normalizeCountryCode(String(n.get(`country_code`)||``).trim()),c=String(n.get(`state_code`)||``).trim(),l=String(n.get(`tax_name`)||``).trim(),u=Number(n.get(`tax_rate`));if(!s)throw Error(`Country code is required.`);if(!l)throw Error(`Tax name is required.`);if(!Number.isFinite(u)||u<0||u>100)throw Error(`Tax rate must be between 0 and 100.`);let d={country_code:s,state_code:t.normalizeSubdivisionCode(s,c)||null,tax_name:l,tax_rate:u},{error:f}=await(i?r.from(`tax_rates`).update(d).eq(`id`,i):r.from(`tax_rates`).insert(d));if(f)throw Error(f.message);(0,a.revalidatePath)(`/cms/settings/taxes`)}async function l(e){let{error:t}=await(await o()).from(`tax_rates`).delete().eq(`id`,e);if(t)throw Error(t.message);(0,a.revalidatePath)(`/cms/settings/taxes`)}exports.deleteTaxRateAction=l,exports.saveTaxRateAction=c,exports.updateTaxSettingsAction=s;
@@ -1,57 +1,45 @@
1
- 'use server';
2
- import { createClient as g } from "@nextblock-cms/db/server";
3
- import { revalidatePath as s } from "next/cache";
4
- import { redirect as w } from "next/navigation";
5
- import { normalizeCountryCode as l } from "../../../countries.es.js";
6
- import { getEcommerceInventorySettings as x, upsertEcommerceInventorySettings as p } from "../../../inventory-settings.es.js";
7
- import { normalizeSubdivisionCode as f } from "../../../states.es.js";
8
- async function c() {
9
- const t = g(), {
10
- data: { user: e }
11
- } = await t.auth.getUser();
12
- if (!e)
13
- throw new Error("Unauthorized");
14
- const { data: r } = await t.from("profiles").select("role").eq("id", e.id).single();
15
- if (!r || r.role !== "ADMIN")
16
- throw new Error("Forbidden");
17
- return t;
1
+ "use server";
2
+ import { normalizeCountryCode as e } from "../../../countries.es.js";
3
+ import { normalizeSubdivisionCode as t } from "../../../states.es.js";
4
+ import { getEcommerceInventorySettings as n, upsertEcommerceInventorySettings as r } from "../../../inventory-settings.es.js";
5
+ import { createClient as i } from "@nextblock-cms/db/server";
6
+ import { redirect as a } from "next/navigation";
7
+ import { revalidatePath as o } from "next/cache";
8
+ //#region libs/ecommerce/src/lib/pages/cms/taxes/actions.ts
9
+ async function s() {
10
+ let e = i(), { 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 || n.role !== "ADMIN") throw Error("Forbidden");
14
+ return e;
18
15
  }
19
- async function C(t) {
20
- const e = await c(), r = await x(e), a = t.getAll("enableTaxes").includes("true"), i = t.get("taxCalculationMode") === "automatic" ? "automatic" : "manual", { error: n } = await p(e, {
21
- trackQuantities: r.trackQuantities,
22
- enableTaxes: a,
23
- taxCalculationMode: i
24
- });
25
- if (n)
26
- throw new Error(n.message);
27
- s("/cms/shipping"), s("/cms/settings/taxes"), w("/cms/settings/taxes?success=Tax settings updated");
16
+ async function c(e) {
17
+ let t = await s(), i = await n(t), c = e.getAll("enableTaxes").includes("true"), l = e.get("taxCalculationMode") === "automatic" ? "automatic" : "manual", { error: u } = await r(t, {
18
+ trackQuantities: i.trackQuantities,
19
+ enableTaxes: c,
20
+ taxCalculationMode: l
21
+ });
22
+ if (u) throw Error(u.message);
23
+ o("/cms/shipping"), o("/cms/settings/taxes"), a("/cms/settings/taxes?success=Tax settings updated");
28
24
  }
29
- async function T(t) {
30
- const e = await c(), r = String(t.get("id") || "").trim(), a = l(String(t.get("country_code") || "").trim()), i = String(t.get("state_code") || "").trim(), n = String(t.get("tax_name") || "").trim(), o = Number(t.get("tax_rate"));
31
- if (!a)
32
- throw new Error("Country code is required.");
33
- if (!n)
34
- throw new Error("Tax name is required.");
35
- if (!Number.isFinite(o) || o < 0 || o > 100)
36
- throw new Error("Tax rate must be between 0 and 100.");
37
- const m = {
38
- country_code: a,
39
- state_code: f(a, i) || null,
40
- tax_name: n,
41
- tax_rate: o
42
- }, d = r ? e.from("tax_rates").update(m).eq("id", r) : e.from("tax_rates").insert(m), { error: u } = await d;
43
- if (u)
44
- throw new Error(u.message);
45
- s("/cms/settings/taxes");
25
+ async function l(n) {
26
+ let r = await s(), i = String(n.get("id") || "").trim(), a = e(String(n.get("country_code") || "").trim()), c = String(n.get("state_code") || "").trim(), l = String(n.get("tax_name") || "").trim(), u = Number(n.get("tax_rate"));
27
+ if (!a) throw Error("Country code is required.");
28
+ if (!l) throw Error("Tax name is required.");
29
+ if (!Number.isFinite(u) || u < 0 || u > 100) throw Error("Tax rate must be between 0 and 100.");
30
+ let d = {
31
+ country_code: a,
32
+ state_code: t(a, c) || null,
33
+ tax_name: l,
34
+ tax_rate: u
35
+ }, { error: f } = await (i ? r.from("tax_rates").update(d).eq("id", i) : r.from("tax_rates").insert(d));
36
+ if (f) throw Error(f.message);
37
+ o("/cms/settings/taxes");
46
38
  }
47
- async function q(t) {
48
- const e = await c(), { error: r } = await e.from("tax_rates").delete().eq("id", t);
49
- if (r)
50
- throw new Error(r.message);
51
- s("/cms/settings/taxes");
39
+ async function u(e) {
40
+ let { error: t } = await (await s()).from("tax_rates").delete().eq("id", e);
41
+ if (t) throw Error(t.message);
42
+ o("/cms/settings/taxes");
52
43
  }
53
- export {
54
- q as deleteTaxRateAction,
55
- T as saveTaxRateAction,
56
- C as updateTaxSettingsAction
57
- };
44
+ //#endregion
45
+ export { u as deleteTaxRateAction, l as saveTaxRateAction, c as updateTaxSettingsAction };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),s=require("@nextblock-cms/ui"),u=require("react"),m=require("../../../../countries.cjs.js"),c=require("../../../../states.cjs.js"),S=require("../actions.cjs.js");function C({initialData:e,submitLabel:p="Save tax rate",compact:a=!1}){const l=m.normalizeCountryCode(e?.country_code)||"US",[d,h]=u.useState(l),[o,n]=u.useState(c.normalizeSubdivisionCode(l,e?.state_code)||e?.state_code||""),y=u.useMemo(()=>c.getStatesForCountry(d),[d]),j=c.countryUsesStructuredStates(d);return t.jsxs("form",{action:S.saveTaxRateAction,className:"space-y-4",children:[e?.id?t.jsx("input",{type:"hidden",name:"id",value:e.id}):null,t.jsxs("div",{className:a?"grid gap-4 md:grid-cols-4":"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`country-${e.id}`:"tax-rate-country",children:"Country"}),t.jsx("select",{id:e?.id?`country-${e.id}`:"tax-rate-country",name:"country_code",value:d,onChange:r=>{const x=r.target.value,g=c.getStatesForCountry(x);h(x),n(g.some(v=>v.code===o)?o:"")},className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:m.countries.map(r=>t.jsx("option",{value:r.code,children:r.name},r.code))})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`state-${e.id}`:"tax-rate-state",children:"State / Province"}),j?t.jsxs("select",{id:e?.id?`state-${e.id}`:"tax-rate-state",name:"state_code",value:o,onChange:r=>n(r.target.value),className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:[t.jsx("option",{value:"",children:"Country-wide / federal"}),y.map(r=>t.jsx("option",{value:r.code,children:r.name},r.code))]}):t.jsx(s.Input,{id:e?.id?`state-${e.id}`:"tax-rate-state",name:"state_code",value:o,onChange:r=>n(r.target.value),placeholder:"Optional"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`name-${e.id}`:"tax-rate-name",children:"Tax name"}),t.jsx(s.Input,{id:e?.id?`name-${e.id}`:"tax-rate-name",name:"tax_name",defaultValue:e?.tax_name||"",placeholder:"GST, PST, State Sales Tax",required:!0})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`rate-${e.id}`:"tax-rate-rate",children:"Rate (%)"}),t.jsx(s.Input,{id:e?.id?`rate-${e.id}`:"tax-rate-rate",name:"tax_rate",type:"number",min:"0",max:"100",step:"0.0001",defaultValue:typeof e?.tax_rate=="number"?e.tax_rate.toString():"",placeholder:"5.0000",required:!0})]})]}),t.jsx("div",{className:"flex justify-end",children:t.jsx(s.Button,{type:"submit",size:a?"sm":"default",children:p})})]})}exports.TaxRateForm=C;
1
+ "use client";const e=require("../../../../countries.cjs.js"),t=require("../../../../states.cjs.js"),n=require("../actions.cjs.js");let r=require("react"),i=require("react/jsx-runtime"),a=require("@nextblock-cms/ui");function o({initialData:o,submitLabel:s=`Save tax rate`,compact:c=!1}){let l=e.normalizeCountryCode(o?.country_code)||`US`,[u,d]=(0,r.useState)(l),[f,p]=(0,r.useState)(t.normalizeSubdivisionCode(l,o?.state_code)||o?.state_code||``),m=(0,r.useMemo)(()=>t.getStatesForCountry(u),[u]),h=t.countryUsesStructuredStates(u);return(0,i.jsxs)(`form`,{action:n.saveTaxRateAction,className:`space-y-4`,children:[o?.id?(0,i.jsx)(`input`,{type:`hidden`,name:`id`,value:o.id}):null,(0,i.jsxs)(`div`,{className:c?`grid gap-4 md:grid-cols-4`:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(a.Label,{htmlFor:o?.id?`country-${o.id}`:`tax-rate-country`,children:`Country`}),(0,i.jsx)(`select`,{id:o?.id?`country-${o.id}`:`tax-rate-country`,name:`country_code`,value:u,onChange:e=>{let n=e.target.value,r=t.getStatesForCountry(n);d(n),p(r.some(e=>e.code===f)?f:``)},className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,children:e.countries.map(e=>(0,i.jsx)(`option`,{value:e.code,children:e.name},e.code))})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(a.Label,{htmlFor:o?.id?`state-${o.id}`:`tax-rate-state`,children:`State / Province`}),h?(0,i.jsxs)(`select`,{id:o?.id?`state-${o.id}`:`tax-rate-state`,name:`state_code`,value:f,onChange:e=>p(e.target.value),className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,children:[(0,i.jsx)(`option`,{value:``,children:`Country-wide / federal`}),m.map(e=>(0,i.jsx)(`option`,{value:e.code,children:e.name},e.code))]}):(0,i.jsx)(a.Input,{id:o?.id?`state-${o.id}`:`tax-rate-state`,name:`state_code`,value:f,onChange:e=>p(e.target.value),placeholder:`Optional`})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(a.Label,{htmlFor:o?.id?`name-${o.id}`:`tax-rate-name`,children:`Tax name`}),(0,i.jsx)(a.Input,{id:o?.id?`name-${o.id}`:`tax-rate-name`,name:`tax_name`,defaultValue:o?.tax_name||``,placeholder:`GST, PST, State Sales Tax`,required:!0})]}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsx)(a.Label,{htmlFor:o?.id?`rate-${o.id}`:`tax-rate-rate`,children:`Rate (%)`}),(0,i.jsx)(a.Input,{id:o?.id?`rate-${o.id}`:`tax-rate-rate`,name:`tax_rate`,type:`number`,min:`0`,max:`100`,step:`0.0001`,defaultValue:typeof o?.tax_rate==`number`?o.tax_rate.toString():``,placeholder:`5.0000`,required:!0})]})]}),(0,i.jsx)(`div`,{className:`flex justify-end`,children:(0,i.jsx)(a.Button,{type:`submit`,size:c?`sm`:`default`,children:s})})]})}exports.TaxRateForm=o;
@@ -4,5 +4,5 @@ interface TaxRateFormProps {
4
4
  submitLabel?: string;
5
5
  compact?: boolean;
6
6
  }
7
- export declare function TaxRateForm({ initialData, submitLabel, compact, }: TaxRateFormProps): import("react").JSX.Element;
7
+ export declare function TaxRateForm({ initialData, submitLabel, compact, }: TaxRateFormProps): import('react').JSX.Element;
8
8
  export {};