@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,317 +1,458 @@
1
- 'use client';
2
- import { jsxs as r, jsx as l, Fragment as O } from "react/jsx-runtime";
3
- import x, { useState as R } from "react";
4
- import { useForm as q } from "react-hook-form";
5
- import { AccountNavigationMenu as J } from "./AccountNavigationMenu.es.js";
6
- import { Avatar as K, AvatarImage as Q, AvatarFallback as Y } from "@nextblock-cms/ui/avatar";
7
- import { Button as Z } from "@nextblock-cms/ui/button";
8
- import { Card as T, CardHeader as B, CardTitle as I, CardContent as L, CardFooter as D } from "@nextblock-cms/ui/card";
9
- import { Checkbox as ee } from "@nextblock-cms/ui/checkbox";
10
- import { Input as i } from "@nextblock-cms/ui/input";
11
- import { Label as t } from "@nextblock-cms/ui/label";
12
- import { Select as le, SelectTrigger as re, SelectValue as se, SelectContent as ae, SelectItem as C } from "@nextblock-cms/ui/select";
13
- import { Separator as te } from "@nextblock-cms/ui/separator";
14
- import { updateProfile as ne } from "../server-actions/customer-actions.es.js";
15
- import { addressesMatch as P, normalizeCustomerAddress as j, emptyCustomerAddress as ie } from "../customer.es.js";
16
- import { createClient as ce } from "@nextblock-cms/db";
17
- import { User as k, Upload as de, Phone as oe, Globe as me } from "lucide-react";
18
- import { useTranslations as X } from "@nextblock-cms/utils";
19
- import { normalizeCountryCode as pe, countries as he } from "../countries.es.js";
20
- function ue(e) {
21
- return e ? e.startsWith("http") ? e : process.env.NEXT_PUBLIC_R2_BASE_URL ? `${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}` : process.env.NEXT_PUBLIC_SUPABASE_URL ? `${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}` : e : null;
1
+ "use client";
2
+ import { countries as e, normalizeCountryCode as t } from "../countries.es.js";
3
+ import { addressesMatch as n, emptyCustomerAddress as r, normalizeCustomerAddress as i } from "../customer.es.js";
4
+ import { AccountNavigationMenu as a } from "./AccountNavigationMenu.es.js";
5
+ import { updateProfile as o } from "../server-actions/customer-actions.es.js";
6
+ import { Button as s } from "@nextblock-cms/ui/button";
7
+ import c, { useState as l } from "react";
8
+ import { Globe as u, Phone as d, Upload as f, User as p } from "lucide-react";
9
+ import { useTranslations as m } from "@nextblock-cms/utils";
10
+ import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
11
+ import { Input as v } from "@nextblock-cms/ui/input";
12
+ import { Label as y } from "@nextblock-cms/ui/label";
13
+ import { Card as b, CardContent as x, CardFooter as S, CardHeader as C, CardTitle as w } from "@nextblock-cms/ui/card";
14
+ import { Checkbox as T } from "@nextblock-cms/ui/checkbox";
15
+ import { Separator as E } from "@nextblock-cms/ui/separator";
16
+ import { Select as D, SelectContent as O, SelectItem as k, SelectTrigger as A, SelectValue as j } from "@nextblock-cms/ui/select";
17
+ import { useForm as M } from "react-hook-form";
18
+ import { Avatar as ee, AvatarFallback as te, AvatarImage as ne } from "@nextblock-cms/ui/avatar";
19
+ import { createClient as re } from "@nextblock-cms/db";
20
+ //#region libs/ecommerce/src/lib/components/CustomerProfileForm.tsx
21
+ function ie(e) {
22
+ return e ? e.startsWith("http") ? e : process.env.NEXT_PUBLIC_R2_BASE_URL ? `${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}` : process.env.NEXT_PUBLIC_SUPABASE_URL ? `${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}` : e : null;
22
23
  }
23
- function v(e) {
24
- return {
25
- company_name: e?.company_name || "",
26
- recipient_name: e?.recipient_name || "",
27
- line1: e?.line1 || "",
28
- line2: e?.line2 || "",
29
- city: e?.city || "",
30
- state: e?.state || "",
31
- postal_code: e?.postal_code || "",
32
- country_code: pe(e?.country_code) || "CA"
33
- };
24
+ function N(e) {
25
+ return {
26
+ company_name: e?.company_name || "",
27
+ recipient_name: e?.recipient_name || "",
28
+ line1: e?.line1 || "",
29
+ line2: e?.line2 || "",
30
+ city: e?.city || "",
31
+ state: e?.state || "",
32
+ postal_code: e?.postal_code || "",
33
+ country_code: t(e?.country_code) || "CA"
34
+ };
34
35
  }
35
- function V({
36
- prefix: e,
37
- title: u,
38
- register: c
39
- }) {
40
- const { t: n } = X(), b = n("company_name") === "company_name" ? "Company name" : n("company_name");
41
- return /* @__PURE__ */ r("div", { className: "space-y-4 rounded-xl border p-4", children: [
42
- /* @__PURE__ */ r("div", { children: [
43
- /* @__PURE__ */ l("h3", { className: "text-lg font-medium", children: u }),
44
- /* @__PURE__ */ l("p", { className: "text-sm text-muted-foreground", children: n("profile_address_defaults_help") })
45
- ] }),
46
- /* @__PURE__ */ r("div", { className: "grid gap-4 md:grid-cols-3", children: [
47
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
48
- /* @__PURE__ */ l(t, { htmlFor: `${e}-company_name`, children: b }),
49
- /* @__PURE__ */ l(i, { id: `${e}-company_name`, ...c(`${e}.company_name`) })
50
- ] }),
51
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
52
- /* @__PURE__ */ l(t, { htmlFor: `${e}-recipient_name`, children: n("full_name") }),
53
- /* @__PURE__ */ l(i, { id: `${e}-recipient_name`, ...c(`${e}.recipient_name`) })
54
- ] }),
55
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
56
- /* @__PURE__ */ l(t, { htmlFor: `${e}-country_code`, children: n("country") }),
57
- /* @__PURE__ */ l(
58
- "select",
59
- {
60
- id: `${e}-country_code`,
61
- className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
62
- ...c(`${e}.country_code`),
63
- children: he.map((d) => /* @__PURE__ */ l("option", { value: d.code, children: d.name }, d.code))
64
- }
65
- )
66
- ] })
67
- ] }),
68
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
69
- /* @__PURE__ */ l(t, { htmlFor: `${e}-line1`, children: n("address_line_1") }),
70
- /* @__PURE__ */ l(i, { id: `${e}-line1`, ...c(`${e}.line1`) })
71
- ] }),
72
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
73
- /* @__PURE__ */ l(t, { htmlFor: `${e}-line2`, children: n("address_line_2") }),
74
- /* @__PURE__ */ l(i, { id: `${e}-line2`, ...c(`${e}.line2`) })
75
- ] }),
76
- /* @__PURE__ */ r("div", { className: "grid gap-4 md:grid-cols-3", children: [
77
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
78
- /* @__PURE__ */ l(t, { htmlFor: `${e}-city`, children: n("city") }),
79
- /* @__PURE__ */ l(i, { id: `${e}-city`, ...c(`${e}.city`) })
80
- ] }),
81
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
82
- /* @__PURE__ */ l(t, { htmlFor: `${e}-state`, children: n("state_province") }),
83
- /* @__PURE__ */ l(i, { id: `${e}-state`, ...c(`${e}.state`) })
84
- ] }),
85
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
86
- /* @__PURE__ */ l(t, { htmlFor: `${e}-postal_code`, children: n("postal_zip_code") }),
87
- /* @__PURE__ */ l(i, { id: `${e}-postal_code`, ...c(`${e}.postal_code`) })
88
- ] })
89
- ] })
90
- ] });
36
+ function P({ prefix: t, title: n, register: r }) {
37
+ let { t: i } = m(), a = i("company_name") === "company_name" ? "Company name" : i("company_name");
38
+ return /* @__PURE__ */ _("div", {
39
+ className: "space-y-4 rounded-xl border p-4",
40
+ children: [
41
+ /* @__PURE__ */ _("div", { children: [/* @__PURE__ */ g("h3", {
42
+ className: "text-lg font-medium",
43
+ children: n
44
+ }), /* @__PURE__ */ g("p", {
45
+ className: "text-sm text-muted-foreground",
46
+ children: i("profile_address_defaults_help")
47
+ })] }),
48
+ /* @__PURE__ */ _("div", {
49
+ className: "grid gap-4 md:grid-cols-3",
50
+ children: [
51
+ /* @__PURE__ */ _("div", {
52
+ className: "space-y-2",
53
+ children: [/* @__PURE__ */ g(y, {
54
+ htmlFor: `${t}-company_name`,
55
+ children: a
56
+ }), /* @__PURE__ */ g(v, {
57
+ id: `${t}-company_name`,
58
+ ...r(`${t}.company_name`)
59
+ })]
60
+ }),
61
+ /* @__PURE__ */ _("div", {
62
+ className: "space-y-2",
63
+ children: [/* @__PURE__ */ g(y, {
64
+ htmlFor: `${t}-recipient_name`,
65
+ children: i("full_name")
66
+ }), /* @__PURE__ */ g(v, {
67
+ id: `${t}-recipient_name`,
68
+ ...r(`${t}.recipient_name`)
69
+ })]
70
+ }),
71
+ /* @__PURE__ */ _("div", {
72
+ className: "space-y-2",
73
+ children: [/* @__PURE__ */ g(y, {
74
+ htmlFor: `${t}-country_code`,
75
+ children: i("country")
76
+ }), /* @__PURE__ */ g("select", {
77
+ id: `${t}-country_code`,
78
+ className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
79
+ ...r(`${t}.country_code`),
80
+ children: e.map((e) => /* @__PURE__ */ g("option", {
81
+ value: e.code,
82
+ children: e.name
83
+ }, e.code))
84
+ })]
85
+ })
86
+ ]
87
+ }),
88
+ /* @__PURE__ */ _("div", {
89
+ className: "space-y-2",
90
+ children: [/* @__PURE__ */ g(y, {
91
+ htmlFor: `${t}-line1`,
92
+ children: i("address_line_1")
93
+ }), /* @__PURE__ */ g(v, {
94
+ id: `${t}-line1`,
95
+ ...r(`${t}.line1`)
96
+ })]
97
+ }),
98
+ /* @__PURE__ */ _("div", {
99
+ className: "space-y-2",
100
+ children: [/* @__PURE__ */ g(y, {
101
+ htmlFor: `${t}-line2`,
102
+ children: i("address_line_2")
103
+ }), /* @__PURE__ */ g(v, {
104
+ id: `${t}-line2`,
105
+ ...r(`${t}.line2`)
106
+ })]
107
+ }),
108
+ /* @__PURE__ */ _("div", {
109
+ className: "grid gap-4 md:grid-cols-3",
110
+ children: [
111
+ /* @__PURE__ */ _("div", {
112
+ className: "space-y-2",
113
+ children: [/* @__PURE__ */ g(y, {
114
+ htmlFor: `${t}-city`,
115
+ children: i("city")
116
+ }), /* @__PURE__ */ g(v, {
117
+ id: `${t}-city`,
118
+ ...r(`${t}.city`)
119
+ })]
120
+ }),
121
+ /* @__PURE__ */ _("div", {
122
+ className: "space-y-2",
123
+ children: [/* @__PURE__ */ g(y, {
124
+ htmlFor: `${t}-state`,
125
+ children: i("state_province")
126
+ }), /* @__PURE__ */ g(v, {
127
+ id: `${t}-state`,
128
+ ...r(`${t}.state`)
129
+ })]
130
+ }),
131
+ /* @__PURE__ */ _("div", {
132
+ className: "space-y-2",
133
+ children: [/* @__PURE__ */ g(y, {
134
+ htmlFor: `${t}-postal_code`,
135
+ children: i("postal_zip_code")
136
+ }), /* @__PURE__ */ g(v, {
137
+ id: `${t}-postal_code`,
138
+ ...r(`${t}.postal_code`)
139
+ })]
140
+ })
141
+ ]
142
+ })
143
+ ]
144
+ });
91
145
  }
92
- function Be({
93
- initialData: e,
94
- MediaPickerComponent: u,
95
- isAdmin: c,
96
- email: n,
97
- accountLinks: b,
98
- onAction: d,
99
- initialSuccessMessage: _,
100
- lockRole: $,
101
- lockRoleReason: z
102
- }) {
103
- const { t: s } = X(), [w, F] = R(!1), [y, N] = R(
104
- _ ? { type: "success", text: _ } : null
105
- ), W = e?.use_billing_for_shipping ?? (!e?.shipping_address || P(e?.billing_address, e?.shipping_address)), {
106
- register: o,
107
- handleSubmit: G,
108
- setValue: g,
109
- getValues: A,
110
- watch: m,
111
- reset: E
112
- } = q({
113
- defaultValues: {
114
- full_name: e?.full_name || "",
115
- avatar_url: e?.avatar_url || "",
116
- website: e?.website || "",
117
- phone: e?.phone || "",
118
- role: e?.role,
119
- use_billing_for_shipping: W,
120
- billing_address: v(e?.billing_address),
121
- shipping_address: v(e?.shipping_address)
122
- }
123
- });
124
- x.useEffect(() => {
125
- e && E({
126
- full_name: e.full_name || "",
127
- avatar_url: e.avatar_url || "",
128
- website: e.website || "",
129
- phone: e.phone || "",
130
- role: e.role,
131
- use_billing_for_shipping: e.use_billing_for_shipping ?? (!e.shipping_address || P(e.billing_address, e.shipping_address)),
132
- billing_address: v(e.billing_address),
133
- shipping_address: v(e.shipping_address)
134
- });
135
- }, [e, E]), x.useEffect(() => {
136
- _ && N({ type: "success", text: _ });
137
- }, [_]), x.useEffect(() => {
138
- const a = ce();
139
- (async () => {
140
- const {
141
- data: { user: f }
142
- } = await a.auth.getUser();
143
- f && !A("full_name") && f.user_metadata?.full_name && g("full_name", f.user_metadata.full_name);
144
- })();
145
- }, [A, g]);
146
- const H = (a) => {
147
- const p = ue(a?.object_key ?? a?.file_path);
148
- p && g("avatar_url", p);
149
- }, M = async (a) => {
150
- F(!0), N(null);
151
- const p = j(a.billing_address) ?? ie(), f = a.use_billing_for_shipping ? p : j(a.shipping_address);
152
- try {
153
- const h = {
154
- ...a,
155
- billing_address: p,
156
- shipping_address: f
157
- };
158
- if (d) {
159
- const S = await d(h);
160
- if (S?.error)
161
- throw new Error(S.error);
162
- } else
163
- await ne(h);
164
- N({ type: "success", text: s("profile_updated_success") });
165
- } catch (h) {
166
- if (h.message === "NEXT_REDIRECT" || h.message?.includes("NEXT_REDIRECT"))
167
- return;
168
- console.error(h), N({ type: "error", text: s("profile_update_failed") });
169
- } finally {
170
- F(!1);
171
- }
172
- }, U = m("use_billing_for_shipping");
173
- return /* @__PURE__ */ r("div", { className: "grid gap-6 md:grid-cols-12 max-w-5xl mx-auto", children: [
174
- /* @__PURE__ */ r(T, { className: "md:col-span-4 h-fit", children: [
175
- /* @__PURE__ */ l(B, { children: /* @__PURE__ */ l(I, { className: "text-xl", children: s("public_profile") }) }),
176
- /* @__PURE__ */ r(L, { className: "flex flex-col items-center text-center space-y-4", children: [
177
- /* @__PURE__ */ r("div", { className: "relative group", children: [
178
- /* @__PURE__ */ r(K, { className: "h-32 w-32 border-4 border-muted", children: [
179
- /* @__PURE__ */ l(Q, { src: m("avatar_url") || void 0, alt: m("full_name") || "", className: "object-cover" }),
180
- /* @__PURE__ */ l(Y, { className: "text-4xl bg-secondary", children: m("full_name")?.charAt(0)?.toUpperCase() || /* @__PURE__ */ l(k, { className: "h-12 w-12" }) })
181
- ] }),
182
- u && // Hover alone hid this from keyboard focus (focusable but invisible) and from
183
- // touch screens, which have no hover at all.
184
- /* @__PURE__ */ l("div", { className: "absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity bg-black/40 rounded-full cursor-pointer", children: /* @__PURE__ */ l(
185
- u,
186
- {
187
- triggerLabel: /* @__PURE__ */ r(O, { children: [
188
- /* @__PURE__ */ l(de, { className: "h-6 w-6 text-white" }),
189
- /* @__PURE__ */ l("span", { className: "sr-only", children: s("profile_change_avatar") === "profile_change_avatar" ? "Change profile picture" : s("profile_change_avatar") })
190
- ] }),
191
- triggerVariant: "ghost",
192
- title: s("customer_profile"),
193
- onSelect: H,
194
- accept: (a) => a.file_type.startsWith("image/"),
195
- hideTrigger: !1
196
- }
197
- ) })
198
- ] }),
199
- !u && /* @__PURE__ */ r("div", { className: "w-full", children: [
200
- /* @__PURE__ */ l(t, { htmlFor: "avatar_url", className: "sr-only", children: s("avatar_url") }),
201
- /* @__PURE__ */ l(i, { id: "avatar_url", type: "url", autoComplete: "off", ...o("avatar_url"), placeholder: "https://…", className: "mt-2" })
202
- ] }),
203
- /* @__PURE__ */ r("div", { className: "w-full space-y-1 text-left mt-4", children: [
204
- /* @__PURE__ */ l("div", { className: "text-sm font-medium text-muted-foreground uppercase tracking-wider", children: s("identity") }),
205
- /* @__PURE__ */ l("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ l("span", { className: "font-semibold text-lg", children: m("full_name") || s("full_name") }) })
206
- ] }),
207
- b?.length ? /* @__PURE__ */ l(
208
- J,
209
- {
210
- links: b,
211
- className: "mt-2 text-left"
212
- }
213
- ) : null
214
- ] })
215
- ] }),
216
- /* @__PURE__ */ l(T, { className: "md:col-span-8", children: /* @__PURE__ */ r("form", { onSubmit: G(M), children: [
217
- /* @__PURE__ */ l(B, { children: /* @__PURE__ */ l(I, { children: s("details") }) }),
218
- /* @__PURE__ */ r(L, { className: "space-y-6", children: [
219
- n && /* @__PURE__ */ r("div", { className: "space-y-2", children: [
220
- /* @__PURE__ */ r(t, { htmlFor: "email", children: [
221
- s("email") === "email" ? "Email" : s("email"),
222
- " (",
223
- s("read_only") === "read_only" ? "read-only" : s("read_only"),
224
- ")"
225
- ] }),
226
- /* @__PURE__ */ l(i, { id: "email", value: n, readOnly: !0, disabled: !0, className: "bg-muted/50" })
227
- ] }),
228
- /* @__PURE__ */ l("div", { className: "rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground", children: s("profile_basic_info_help") }),
229
- /* @__PURE__ */ r("div", { className: "grid gap-4 md:grid-cols-2", children: [
230
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
231
- /* @__PURE__ */ r(t, { htmlFor: "full_name", className: "flex items-center gap-2", children: [
232
- /* @__PURE__ */ l(k, { className: "h-4 w-4" }),
233
- " ",
234
- s("full_name")
235
- ] }),
236
- /* @__PURE__ */ l(i, { id: "full_name", autoComplete: "name", ...o("full_name") })
237
- ] }),
238
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
239
- /* @__PURE__ */ r(t, { htmlFor: "phone", className: "flex items-center gap-2", children: [
240
- /* @__PURE__ */ l(oe, { className: "h-4 w-4" }),
241
- " ",
242
- s("phone_number")
243
- ] }),
244
- /* @__PURE__ */ l(i, { id: "phone", type: "tel", inputMode: "tel", autoComplete: "tel", ...o("phone") })
245
- ] })
246
- ] }),
247
- /* @__PURE__ */ r("div", { className: "space-y-2", children: [
248
- /* @__PURE__ */ r(t, { htmlFor: "website", className: "flex items-center gap-2", children: [
249
- /* @__PURE__ */ l(me, { className: "h-4 w-4" }),
250
- " ",
251
- s("website")
252
- ] }),
253
- /* @__PURE__ */ l(i, { id: "website", type: "url", autoComplete: "url", ...o("website"), placeholder: "https://example.com" })
254
- ] }),
255
- /* @__PURE__ */ l(te, { className: "my-2" }),
256
- /* @__PURE__ */ l(V, { prefix: "billing_address", title: s("billing_address"), register: o }),
257
- /* @__PURE__ */ r("div", { className: "flex items-center space-x-3 rounded-lg border p-4", children: [
258
- /* @__PURE__ */ l(
259
- ee,
260
- {
261
- id: "use_billing_for_shipping",
262
- checked: !!U,
263
- onCheckedChange: (a) => g("use_billing_for_shipping", !!a, { shouldDirty: !0 })
264
- }
265
- ),
266
- /* @__PURE__ */ r("div", { className: "space-y-1", children: [
267
- /* @__PURE__ */ l(t, { htmlFor: "use_billing_for_shipping", className: "cursor-pointer", children: s("use_billing_for_shipping") }),
268
- /* @__PURE__ */ l("p", { className: "text-sm text-muted-foreground", children: s("profile_use_billing_for_shipping_help") })
269
- ] })
270
- ] }),
271
- !U && /* @__PURE__ */ l(
272
- V,
273
- {
274
- prefix: "shipping_address",
275
- title: s("shipping_address"),
276
- register: o
277
- }
278
- ),
279
- y && /* @__PURE__ */ l(
280
- "div",
281
- {
282
- role: y.type === "error" ? "alert" : "status",
283
- className: `mt-4 rounded-xl border p-4 text-sm ${y.type === "success" ? "border-emerald-200 bg-emerald-50 text-emerald-700" : "border-red-200 bg-red-50 text-red-700"}`,
284
- children: y.text
285
- }
286
- ),
287
- c && /* @__PURE__ */ r("div", { className: "border-t pt-4 mt-4", children: [
288
- /* @__PURE__ */ l("h3", { className: "text-sm font-medium mb-3", children: "Admin Settings" }),
289
- /* @__PURE__ */ r("div", { className: "grid gap-2", children: [
290
- /* @__PURE__ */ l(t, { htmlFor: "role", children: "Role" }),
291
- /* @__PURE__ */ r(
292
- le,
293
- {
294
- value: m("role") || "USER",
295
- onValueChange: (a) => g("role", a),
296
- disabled: $,
297
- children: [
298
- /* @__PURE__ */ l(re, { children: /* @__PURE__ */ l(se, { placeholder: "Select role" }) }),
299
- /* @__PURE__ */ r(ae, { children: [
300
- /* @__PURE__ */ l(C, { value: "USER", children: "User" }),
301
- /* @__PURE__ */ l(C, { value: "WRITER", children: "Writer" }),
302
- /* @__PURE__ */ l(C, { value: "ADMIN", children: "Admin" })
303
- ] })
304
- ]
305
- }
306
- ),
307
- $ && /* @__PURE__ */ l("p", { className: "text-xs text-muted-foreground", children: z || "This is the only Admin account, so its role can't be changed. Promote another user to Admin first." })
308
- ] })
309
- ] })
310
- ] }),
311
- /* @__PURE__ */ l(D, { className: "flex justify-end", children: /* @__PURE__ */ l(Z, { type: "submit", disabled: w, size: "lg", children: s(w ? "saving" : "save_changes") }) })
312
- ] }) })
313
- ] });
146
+ function F({ initialData: e, MediaPickerComponent: t, isAdmin: F, email: I, accountLinks: L, onAction: R, initialSuccessMessage: z, lockRole: B, lockRoleReason: V }) {
147
+ let { t: H } = m(), [U, W] = l(!1), [G, K] = l(z ? {
148
+ type: "success",
149
+ text: z
150
+ } : null), q = e?.use_billing_for_shipping ?? (!e?.shipping_address || n(e?.billing_address, e?.shipping_address)), { register: J, handleSubmit: ae, setValue: Y, getValues: X, watch: Z, reset: Q } = M({ defaultValues: {
151
+ full_name: e?.full_name || "",
152
+ avatar_url: e?.avatar_url || "",
153
+ website: e?.website || "",
154
+ phone: e?.phone || "",
155
+ role: e?.role,
156
+ use_billing_for_shipping: q,
157
+ billing_address: N(e?.billing_address),
158
+ shipping_address: N(e?.shipping_address)
159
+ } });
160
+ c.useEffect(() => {
161
+ e && Q({
162
+ full_name: e.full_name || "",
163
+ avatar_url: e.avatar_url || "",
164
+ website: e.website || "",
165
+ phone: e.phone || "",
166
+ role: e.role,
167
+ use_billing_for_shipping: e.use_billing_for_shipping ?? (!e.shipping_address || n(e.billing_address, e.shipping_address)),
168
+ billing_address: N(e.billing_address),
169
+ shipping_address: N(e.shipping_address)
170
+ });
171
+ }, [e, Q]), c.useEffect(() => {
172
+ z && K({
173
+ type: "success",
174
+ text: z
175
+ });
176
+ }, [z]), c.useEffect(() => {
177
+ let e = re();
178
+ (async () => {
179
+ let { data: { user: t } } = await e.auth.getUser();
180
+ t && !X("full_name") && t.user_metadata?.full_name && Y("full_name", t.user_metadata.full_name);
181
+ })();
182
+ }, [X, Y]);
183
+ let oe = (e) => {
184
+ let t = ie(e?.object_key ?? e?.file_path);
185
+ t && Y("avatar_url", t);
186
+ }, se = async (e) => {
187
+ W(!0), K(null);
188
+ let t = i(e.billing_address) ?? r(), n = e.use_billing_for_shipping ? t : i(e.shipping_address);
189
+ try {
190
+ let r = {
191
+ ...e,
192
+ billing_address: t,
193
+ shipping_address: n
194
+ };
195
+ if (R) {
196
+ let e = await R(r);
197
+ if (e?.error) throw Error(e.error);
198
+ } else await o(r);
199
+ K({
200
+ type: "success",
201
+ text: H("profile_updated_success")
202
+ });
203
+ } catch (e) {
204
+ if (e.message === "NEXT_REDIRECT" || e.message?.includes("NEXT_REDIRECT")) return;
205
+ console.error(e), K({
206
+ type: "error",
207
+ text: H("profile_update_failed")
208
+ });
209
+ } finally {
210
+ W(!1);
211
+ }
212
+ }, $ = Z("use_billing_for_shipping");
213
+ return /* @__PURE__ */ _("div", {
214
+ className: "grid gap-6 md:grid-cols-12 max-w-5xl mx-auto",
215
+ children: [/* @__PURE__ */ _(b, {
216
+ className: "md:col-span-4 h-fit",
217
+ children: [/* @__PURE__ */ g(C, { children: /* @__PURE__ */ g(w, {
218
+ className: "text-xl",
219
+ children: H("public_profile")
220
+ }) }), /* @__PURE__ */ _(x, {
221
+ className: "flex flex-col items-center text-center space-y-4",
222
+ children: [
223
+ /* @__PURE__ */ _("div", {
224
+ className: "relative group",
225
+ children: [/* @__PURE__ */ _(ee, {
226
+ className: "h-32 w-32 border-4 border-muted",
227
+ children: [/* @__PURE__ */ g(ne, {
228
+ src: Z("avatar_url") || void 0,
229
+ alt: Z("full_name") || "",
230
+ className: "object-cover"
231
+ }), /* @__PURE__ */ g(te, {
232
+ className: "text-4xl bg-secondary",
233
+ children: Z("full_name")?.charAt(0)?.toUpperCase() || /* @__PURE__ */ g(p, { className: "h-12 w-12" })
234
+ })]
235
+ }), t && /* @__PURE__ */ g("div", {
236
+ className: "absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity bg-black/40 rounded-full cursor-pointer",
237
+ children: /* @__PURE__ */ g(t, {
238
+ triggerLabel: /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g(f, { className: "h-6 w-6 text-white" }), /* @__PURE__ */ g("span", {
239
+ className: "sr-only",
240
+ children: H("profile_change_avatar") === "profile_change_avatar" ? "Change profile picture" : H("profile_change_avatar")
241
+ })] }),
242
+ triggerVariant: "ghost",
243
+ title: H("customer_profile"),
244
+ onSelect: oe,
245
+ accept: (e) => e.file_type.startsWith("image/"),
246
+ hideTrigger: !1
247
+ })
248
+ })]
249
+ }),
250
+ !t && /* @__PURE__ */ _("div", {
251
+ className: "w-full",
252
+ children: [/* @__PURE__ */ g(y, {
253
+ htmlFor: "avatar_url",
254
+ className: "sr-only",
255
+ children: H("avatar_url")
256
+ }), /* @__PURE__ */ g(v, {
257
+ id: "avatar_url",
258
+ type: "url",
259
+ autoComplete: "off",
260
+ ...J("avatar_url"),
261
+ placeholder: "https://…",
262
+ className: "mt-2"
263
+ })]
264
+ }),
265
+ /* @__PURE__ */ _("div", {
266
+ className: "w-full space-y-1 text-left mt-4",
267
+ children: [/* @__PURE__ */ g("div", {
268
+ className: "text-sm font-medium text-muted-foreground uppercase tracking-wider",
269
+ children: H("identity")
270
+ }), /* @__PURE__ */ g("div", {
271
+ className: "flex items-center gap-2",
272
+ children: /* @__PURE__ */ g("span", {
273
+ className: "font-semibold text-lg",
274
+ children: Z("full_name") || H("full_name")
275
+ })
276
+ })]
277
+ }),
278
+ L?.length ? /* @__PURE__ */ g(a, {
279
+ links: L,
280
+ className: "mt-2 text-left"
281
+ }) : null
282
+ ]
283
+ })]
284
+ }), /* @__PURE__ */ g(b, {
285
+ className: "md:col-span-8",
286
+ children: /* @__PURE__ */ _("form", {
287
+ onSubmit: ae(se),
288
+ children: [
289
+ /* @__PURE__ */ g(C, { children: /* @__PURE__ */ g(w, { children: H("details") }) }),
290
+ /* @__PURE__ */ _(x, {
291
+ className: "space-y-6",
292
+ children: [
293
+ I && /* @__PURE__ */ _("div", {
294
+ className: "space-y-2",
295
+ children: [/* @__PURE__ */ _(y, {
296
+ htmlFor: "email",
297
+ children: [
298
+ H("email") === "email" ? "Email" : H("email"),
299
+ " (",
300
+ H("read_only") === "read_only" ? "read-only" : H("read_only"),
301
+ ")"
302
+ ]
303
+ }), /* @__PURE__ */ g(v, {
304
+ id: "email",
305
+ value: I,
306
+ readOnly: !0,
307
+ disabled: !0,
308
+ className: "bg-muted/50"
309
+ })]
310
+ }),
311
+ /* @__PURE__ */ g("div", {
312
+ className: "rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground",
313
+ children: H("profile_basic_info_help")
314
+ }),
315
+ /* @__PURE__ */ _("div", {
316
+ className: "grid gap-4 md:grid-cols-2",
317
+ children: [/* @__PURE__ */ _("div", {
318
+ className: "space-y-2",
319
+ children: [/* @__PURE__ */ _(y, {
320
+ htmlFor: "full_name",
321
+ className: "flex items-center gap-2",
322
+ children: [
323
+ /* @__PURE__ */ g(p, { className: "h-4 w-4" }),
324
+ " ",
325
+ H("full_name")
326
+ ]
327
+ }), /* @__PURE__ */ g(v, {
328
+ id: "full_name",
329
+ autoComplete: "name",
330
+ ...J("full_name")
331
+ })]
332
+ }), /* @__PURE__ */ _("div", {
333
+ className: "space-y-2",
334
+ children: [/* @__PURE__ */ _(y, {
335
+ htmlFor: "phone",
336
+ className: "flex items-center gap-2",
337
+ children: [
338
+ /* @__PURE__ */ g(d, { className: "h-4 w-4" }),
339
+ " ",
340
+ H("phone_number")
341
+ ]
342
+ }), /* @__PURE__ */ g(v, {
343
+ id: "phone",
344
+ type: "tel",
345
+ inputMode: "tel",
346
+ autoComplete: "tel",
347
+ ...J("phone")
348
+ })]
349
+ })]
350
+ }),
351
+ /* @__PURE__ */ _("div", {
352
+ className: "space-y-2",
353
+ children: [/* @__PURE__ */ _(y, {
354
+ htmlFor: "website",
355
+ className: "flex items-center gap-2",
356
+ children: [
357
+ /* @__PURE__ */ g(u, { className: "h-4 w-4" }),
358
+ " ",
359
+ H("website")
360
+ ]
361
+ }), /* @__PURE__ */ g(v, {
362
+ id: "website",
363
+ type: "url",
364
+ autoComplete: "url",
365
+ ...J("website"),
366
+ placeholder: "https://example.com"
367
+ })]
368
+ }),
369
+ /* @__PURE__ */ g(E, { className: "my-2" }),
370
+ /* @__PURE__ */ g(P, {
371
+ prefix: "billing_address",
372
+ title: H("billing_address"),
373
+ register: J
374
+ }),
375
+ /* @__PURE__ */ _("div", {
376
+ className: "flex items-center space-x-3 rounded-lg border p-4",
377
+ children: [/* @__PURE__ */ g(T, {
378
+ id: "use_billing_for_shipping",
379
+ checked: !!$,
380
+ onCheckedChange: (e) => Y("use_billing_for_shipping", !!e, { shouldDirty: !0 })
381
+ }), /* @__PURE__ */ _("div", {
382
+ className: "space-y-1",
383
+ children: [/* @__PURE__ */ g(y, {
384
+ htmlFor: "use_billing_for_shipping",
385
+ className: "cursor-pointer",
386
+ children: H("use_billing_for_shipping")
387
+ }), /* @__PURE__ */ g("p", {
388
+ className: "text-sm text-muted-foreground",
389
+ children: H("profile_use_billing_for_shipping_help")
390
+ })]
391
+ })]
392
+ }),
393
+ !$ && /* @__PURE__ */ g(P, {
394
+ prefix: "shipping_address",
395
+ title: H("shipping_address"),
396
+ register: J
397
+ }),
398
+ G && /* @__PURE__ */ g("div", {
399
+ role: G.type === "error" ? "alert" : "status",
400
+ className: `mt-4 rounded-xl border p-4 text-sm ${G.type === "success" ? "border-emerald-200 bg-emerald-50 text-emerald-700" : "border-red-200 bg-red-50 text-red-700"}`,
401
+ children: G.text
402
+ }),
403
+ F && /* @__PURE__ */ _("div", {
404
+ className: "border-t pt-4 mt-4",
405
+ children: [/* @__PURE__ */ g("h3", {
406
+ className: "text-sm font-medium mb-3",
407
+ children: "Admin Settings"
408
+ }), /* @__PURE__ */ _("div", {
409
+ className: "grid gap-2",
410
+ children: [
411
+ /* @__PURE__ */ g(y, {
412
+ htmlFor: "role",
413
+ children: "Role"
414
+ }),
415
+ /* @__PURE__ */ _(D, {
416
+ value: Z("role") || "USER",
417
+ onValueChange: (e) => Y("role", e),
418
+ disabled: B,
419
+ children: [/* @__PURE__ */ g(A, { children: /* @__PURE__ */ g(j, { placeholder: "Select role" }) }), /* @__PURE__ */ _(O, { children: [
420
+ /* @__PURE__ */ g(k, {
421
+ value: "USER",
422
+ children: "User"
423
+ }),
424
+ /* @__PURE__ */ g(k, {
425
+ value: "WRITER",
426
+ children: "Writer"
427
+ }),
428
+ /* @__PURE__ */ g(k, {
429
+ value: "ADMIN",
430
+ children: "Admin"
431
+ })
432
+ ] })]
433
+ }),
434
+ B && /* @__PURE__ */ g("p", {
435
+ className: "text-xs text-muted-foreground",
436
+ children: V || "This is the only Admin account, so its role can't be changed. Promote another user to Admin first."
437
+ })
438
+ ]
439
+ })]
440
+ })
441
+ ]
442
+ }),
443
+ /* @__PURE__ */ g(S, {
444
+ className: "flex justify-end",
445
+ children: /* @__PURE__ */ g(s, {
446
+ type: "submit",
447
+ disabled: U,
448
+ size: "lg",
449
+ children: H(U ? "saving" : "save_changes")
450
+ })
451
+ })
452
+ ]
453
+ })
454
+ })]
455
+ });
314
456
  }
315
- export {
316
- Be as CustomerProfileForm
317
- };
457
+ //#endregion
458
+ export { F as CustomerProfileForm };