@drawbridge/components 0.1.46 → 0.1.48

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 (162) hide show
  1. package/dist/bridge/cart-drawer.js +152 -0
  2. package/dist/bridge/cart-drawer.mjs +123 -0
  3. package/dist/bridge/fields.js +278 -0
  4. package/dist/bridge/fields.mjs +276 -1
  5. package/dist/bridge/form-subdomain-checkout.js +687 -0
  6. package/dist/bridge/form-subdomain-checkout.mjs +665 -0
  7. package/dist/bridge/form-subdomain-shop-modal.js +234 -274
  8. package/dist/bridge/form-subdomain-shop-modal.mjs +233 -275
  9. package/dist/bridge/form-subdomain-shop.js +4 -1
  10. package/dist/bridge/form-subdomain-shop.mjs +4 -1
  11. package/dist/bridge/form-subdomain.js +24 -5
  12. package/dist/bridge/form-subdomain.mjs +25 -6
  13. package/dist/bridge/lib/age-gate.js +12 -0
  14. package/dist/bridge/lib/age-gate.mjs +11 -0
  15. package/dist/bridge/lib/cart.js +79 -0
  16. package/dist/bridge/lib/cart.mjs +48 -0
  17. package/dist/bridge/lib/checkout-kit.js +2 -32
  18. package/dist/bridge/lib/checkout-kit.mjs +2 -32
  19. package/dist/bridge/lib/entry.js +41 -0
  20. package/dist/bridge/lib/entry.mjs +40 -0
  21. package/dist/bridge/product-tile.js +13 -6
  22. package/dist/bridge/product-tile.mjs +13 -6
  23. package/dist/bridge/template-layout.js +263 -129
  24. package/dist/bridge/template-layout.mjs +264 -130
  25. package/dist/bridge/template-modal.js +39 -74
  26. package/dist/bridge/template-modal.mjs +40 -75
  27. package/dist/dashboard/avatar.js +2 -3
  28. package/dist/dashboard/avatar.mjs +2 -3
  29. package/dist/dashboard/buttons-subscription.js +1 -1
  30. package/dist/dashboard/buttons-subscription.mjs +1 -1
  31. package/dist/dashboard/campaign-form.js +179 -155
  32. package/dist/dashboard/campaign-form.mjs +179 -155
  33. package/dist/dashboard/campaign-share.js +347 -0
  34. package/dist/dashboard/campaign-share.mjs +314 -0
  35. package/dist/dashboard/card-affiliate.js +1 -1
  36. package/dist/dashboard/card-affiliate.mjs +1 -1
  37. package/dist/dashboard/card-campaign-switch.js +4 -1
  38. package/dist/dashboard/card-campaign-switch.mjs +4 -1
  39. package/dist/dashboard/card-order.js +22 -4
  40. package/dist/dashboard/card-order.mjs +22 -4
  41. package/dist/dashboard/embed-stripe.js +145 -0
  42. package/dist/dashboard/embed-stripe.mjs +116 -0
  43. package/dist/dashboard/form-admin-provider.js +71 -17
  44. package/dist/dashboard/form-admin-provider.mjs +71 -17
  45. package/dist/dashboard/form-file-upload.js +3 -2
  46. package/dist/dashboard/form-file-upload.mjs +4 -3
  47. package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
  48. package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
  49. package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
  50. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
  51. package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
  52. package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
  53. package/dist/dashboard/form-organization-campaign-page.js +73 -39
  54. package/dist/dashboard/form-organization-campaign-page.mjs +73 -39
  55. package/dist/dashboard/form-organization-campaign.js +82 -0
  56. package/dist/dashboard/form-organization-campaign.mjs +81 -0
  57. package/dist/dashboard/form-organization-connection.js +48 -6
  58. package/dist/dashboard/form-organization-connection.mjs +48 -7
  59. package/dist/dashboard/form-organization-product.js +1461 -0
  60. package/dist/dashboard/form-organization-product.mjs +1425 -0
  61. package/dist/dashboard/form-organization-workflow.js +72 -1
  62. package/dist/dashboard/form-organization-workflow.mjs +69 -1
  63. package/dist/dashboard/form-otc.js +4 -5
  64. package/dist/dashboard/form-otc.mjs +4 -5
  65. package/dist/dashboard/form-stripe.js +12 -5
  66. package/dist/dashboard/form-stripe.mjs +12 -5
  67. package/dist/dashboard/input-combobox.js +6 -0
  68. package/dist/dashboard/input-combobox.mjs +6 -0
  69. package/dist/dashboard/input-fields.js +37 -161
  70. package/dist/dashboard/input-fields.mjs +37 -161
  71. package/dist/dashboard/input-file.js +21 -4
  72. package/dist/dashboard/input-file.mjs +21 -4
  73. package/dist/dashboard/input-font.js +2 -0
  74. package/dist/dashboard/input-font.mjs +2 -0
  75. package/dist/dashboard/input-gallery.js +201 -0
  76. package/dist/dashboard/input-gallery.mjs +172 -0
  77. package/dist/dashboard/input-group-ai.js +15 -3
  78. package/dist/dashboard/input-group-ai.mjs +15 -3
  79. package/dist/dashboard/lib/ab-tests.js +2 -2
  80. package/dist/dashboard/lib/ab-tests.mjs +2 -2
  81. package/dist/dashboard/lib/connection-controls.js +5 -2
  82. package/dist/dashboard/lib/connection-controls.mjs +3 -1
  83. package/dist/dashboard/lib/form-page.js +1 -1
  84. package/dist/dashboard/lib/form-page.mjs +1 -1
  85. package/dist/dashboard/lib/menu.js +19 -0
  86. package/dist/dashboard/lib/menu.mjs +18 -0
  87. package/dist/dashboard/lib/products.js +169 -0
  88. package/dist/dashboard/lib/products.mjs +135 -0
  89. package/dist/dashboard/lib/settings-paths.js +35 -0
  90. package/dist/dashboard/lib/settings-paths.mjs +11 -0
  91. package/dist/dashboard/lib/uppy.js +10 -1
  92. package/dist/dashboard/lib/uppy.mjs +11 -2
  93. package/dist/dashboard/menu.js +13 -2
  94. package/dist/dashboard/menu.mjs +13 -2
  95. package/dist/dashboard/order-sections.js +456 -6
  96. package/dist/dashboard/order-sections.mjs +453 -7
  97. package/dist/dashboard/preview.js +119 -52
  98. package/dist/dashboard/preview.mjs +119 -52
  99. package/dist/dashboard/provider-ui.js +9 -7
  100. package/dist/dashboard/provider-ui.mjs +9 -7
  101. package/dist/dashboard/recharts.js +10 -4
  102. package/dist/dashboard/recharts.mjs +10 -4
  103. package/dist/dashboard/shipping-rates.js +404 -0
  104. package/dist/dashboard/shipping-rates.mjs +371 -0
  105. package/dist/dashboard/template-buyer.js +301 -0
  106. package/dist/dashboard/template-buyer.mjs +267 -0
  107. package/dist/dashboard/template-dashboard.js +11 -1
  108. package/dist/dashboard/template-dashboard.mjs +11 -1
  109. package/dist/dashboard/template-design.js +209 -130
  110. package/dist/dashboard/template-design.mjs +210 -131
  111. package/dist/dashboard/template-ui.js +157 -55
  112. package/dist/dashboard/template-ui.mjs +158 -56
  113. package/dist/icons/flags.js +134 -0
  114. package/dist/icons/flags.mjs +115 -0
  115. package/dist/input-checkbox.js +28 -10
  116. package/dist/input-checkbox.mjs +28 -10
  117. package/dist/product.js +96 -24
  118. package/dist/product.mjs +97 -25
  119. package/dist/shared/carousel.js +14 -5
  120. package/dist/shared/carousel.mjs +14 -5
  121. package/dist/shared/lib/helpers.js +54 -6
  122. package/dist/shared/lib/helpers.mjs +53 -8
  123. package/dist/shared/order-summary.js +139 -0
  124. package/dist/shared/order-summary.mjs +110 -0
  125. package/package.json +84 -4
  126. package/types/bridge/cart-drawer.d.ts +31 -0
  127. package/types/bridge/fields.d.ts +14 -2
  128. package/types/bridge/form-subdomain-checkout.d.ts +20 -0
  129. package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
  130. package/types/bridge/form-subdomain.d.ts +13 -0
  131. package/types/bridge/lib/age-gate.d.ts +5 -0
  132. package/types/bridge/lib/cart.d.ts +44 -0
  133. package/types/bridge/lib/checkout-kit.d.ts +2 -10
  134. package/types/bridge/lib/entry.d.ts +5 -0
  135. package/types/bridge/product-tile.d.ts +2 -0
  136. package/types/dashboard/campaign-share.d.ts +16 -0
  137. package/types/dashboard/card-order.d.ts +6 -0
  138. package/types/dashboard/embed-stripe.d.ts +25 -0
  139. package/types/dashboard/form-admin-provider.d.ts +9 -2
  140. package/types/dashboard/form-file-upload.d.ts +2 -1
  141. package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
  142. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
  143. package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
  144. package/types/dashboard/form-organization-campaign-page.d.ts +8 -1
  145. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  146. package/types/dashboard/form-organization-connection.d.ts +11 -0
  147. package/types/dashboard/form-organization-product.d.ts +24 -0
  148. package/types/dashboard/form-otc.d.ts +5 -1
  149. package/types/dashboard/form-stripe.d.ts +3 -2
  150. package/types/dashboard/input-combobox.d.ts +2 -0
  151. package/types/dashboard/input-file.d.ts +2 -0
  152. package/types/dashboard/input-gallery.d.ts +14 -0
  153. package/types/dashboard/lib/products.d.ts +14 -0
  154. package/types/dashboard/lib/settings-paths.d.ts +5 -0
  155. package/types/dashboard/order-sections.d.ts +24 -1
  156. package/types/dashboard/preview.d.ts +11 -3
  157. package/types/dashboard/shipping-rates.d.ts +26 -0
  158. package/types/dashboard/template-buyer.d.ts +50 -0
  159. package/types/icons/flags.d.ts +5 -0
  160. package/types/input-checkbox.d.ts +2 -0
  161. package/types/shared/lib/helpers.d.ts +4 -0
  162. package/types/shared/order-summary.d.ts +19 -0
@@ -43,11 +43,12 @@ var import_guard_navigation = __toESM(require("./guard-navigation"));
43
43
  var import_modal = __toESM(require("./modal"));
44
44
  var import_notice = __toESM(require("./notice"));
45
45
  var import_loader = require("../shared/loader");
46
+ var import_helpers = require("../shared/lib/helpers");
46
47
  const ProviderUi = ({
47
48
  children,
48
49
  token
49
50
  }) => {
50
- var _a, _b, _c, _d, _e, _f;
51
+ var _a, _b, _c, _d, _e, _f, _g, _h;
51
52
  const queryClient = (0, import_react_query.useQueryClient)();
52
53
  queryClient.setQueryDefaults(["socket"], { structuralSharing: false });
53
54
  const tokenRef = (0, import_react.useRef)(token);
@@ -181,8 +182,9 @@ const ProviderUi = ({
181
182
  }
182
183
  ]
183
184
  });
184
- const expired = ((_a = account == null ? void 0 : account.error) == null ? void 0 : _a.status) === 401 && typeof window !== "undefined" ? (0, import_navigation.expiredSessionHref)({
185
- csrf: (_b = document.cookie.match(/(?:^|;\s*)drawbridge\.csrf=([^;]+)/)) == null ? void 0 : _b[1],
185
+ (0, import_helpers.setStripeKey)((_b = (_a = app == null ? void 0 : app.data) == null ? void 0 : _a.credentials) == null ? void 0 : _b.stripePublishableKey);
186
+ const expired = ((_c = account == null ? void 0 : account.error) == null ? void 0 : _c.status) === 401 && typeof window !== "undefined" ? (0, import_navigation.expiredSessionHref)({
187
+ csrf: (_d = document.cookie.match(/(?:^|;\s*)drawbridge\.csrf=([^;]+)/)) == null ? void 0 : _d[1],
186
188
  pathname: window.location.pathname,
187
189
  search: window.location.search
188
190
  }) : null;
@@ -216,7 +218,7 @@ const ProviderUi = ({
216
218
  ...{
217
219
  button: false,
218
220
  href: false,
219
- message: (_c = app == null ? void 0 : app.error) == null ? void 0 : _c.message
221
+ message: (_e = app == null ? void 0 : app.error) == null ? void 0 : _e.message
220
222
  }
221
223
  }
222
224
  );
@@ -229,7 +231,7 @@ const ProviderUi = ({
229
231
  {
230
232
  ...{
231
233
  button: false,
232
- message: (_d = account == null ? void 0 : account.error) == null ? void 0 : _d.message
234
+ message: (_f = account == null ? void 0 : account.error) == null ? void 0 : _f.message
233
235
  }
234
236
  }
235
237
  );
@@ -241,7 +243,7 @@ const ProviderUi = ({
241
243
  ...{
242
244
  button: "Sign in",
243
245
  href: "/auth",
244
- message: (_e = account == null ? void 0 : account.error) == null ? void 0 : _e.message
246
+ message: (_g = account == null ? void 0 : account.error) == null ? void 0 : _g.message
245
247
  }
246
248
  }
247
249
  );
@@ -261,7 +263,7 @@ const ProviderUi = ({
261
263
  })
262
264
  )
263
265
  },
264
- children: (_f = drawer == null ? void 0 : drawer.data) == null ? void 0 : _f.children
266
+ children: (_h = drawer == null ? void 0 : drawer.data) == null ? void 0 : _h.children
265
267
  }
266
268
  ),
267
269
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -11,11 +11,12 @@ import GuardNavigation from "./guard-navigation.mjs";
11
11
  import Modal from "./modal.mjs";
12
12
  import Notice from "./notice.mjs";
13
13
  import { LogoLoader } from "../shared/loader.mjs";
14
+ import { setStripeKey } from "../shared/lib/helpers.mjs";
14
15
  const ProviderUi = ({
15
16
  children,
16
17
  token
17
18
  }) => {
18
- var _a, _b, _c, _d, _e, _f;
19
+ var _a, _b, _c, _d, _e, _f, _g, _h;
19
20
  const queryClient = useQueryClient();
20
21
  queryClient.setQueryDefaults(["socket"], { structuralSharing: false });
21
22
  const tokenRef = useRef(token);
@@ -149,8 +150,9 @@ const ProviderUi = ({
149
150
  }
150
151
  ]
151
152
  });
152
- const expired = ((_a = account == null ? void 0 : account.error) == null ? void 0 : _a.status) === 401 && typeof window !== "undefined" ? expiredSessionHref({
153
- csrf: (_b = document.cookie.match(/(?:^|;\s*)drawbridge\.csrf=([^;]+)/)) == null ? void 0 : _b[1],
153
+ setStripeKey((_b = (_a = app == null ? void 0 : app.data) == null ? void 0 : _a.credentials) == null ? void 0 : _b.stripePublishableKey);
154
+ const expired = ((_c = account == null ? void 0 : account.error) == null ? void 0 : _c.status) === 401 && typeof window !== "undefined" ? expiredSessionHref({
155
+ csrf: (_d = document.cookie.match(/(?:^|;\s*)drawbridge\.csrf=([^;]+)/)) == null ? void 0 : _d[1],
154
156
  pathname: window.location.pathname,
155
157
  search: window.location.search
156
158
  }) : null;
@@ -184,7 +186,7 @@ const ProviderUi = ({
184
186
  ...{
185
187
  button: false,
186
188
  href: false,
187
- message: (_c = app == null ? void 0 : app.error) == null ? void 0 : _c.message
189
+ message: (_e = app == null ? void 0 : app.error) == null ? void 0 : _e.message
188
190
  }
189
191
  }
190
192
  );
@@ -197,7 +199,7 @@ const ProviderUi = ({
197
199
  {
198
200
  ...{
199
201
  button: false,
200
- message: (_d = account == null ? void 0 : account.error) == null ? void 0 : _d.message
202
+ message: (_f = account == null ? void 0 : account.error) == null ? void 0 : _f.message
201
203
  }
202
204
  }
203
205
  );
@@ -209,7 +211,7 @@ const ProviderUi = ({
209
211
  ...{
210
212
  button: "Sign in",
211
213
  href: "/auth",
212
- message: (_e = account == null ? void 0 : account.error) == null ? void 0 : _e.message
214
+ message: (_g = account == null ? void 0 : account.error) == null ? void 0 : _g.message
213
215
  }
214
216
  }
215
217
  );
@@ -229,7 +231,7 @@ const ProviderUi = ({
229
231
  })
230
232
  )
231
233
  },
232
- children: (_f = drawer == null ? void 0 : drawer.data) == null ? void 0 : _f.children
234
+ children: (_h = drawer == null ? void 0 : drawer.data) == null ? void 0 : _h.children
233
235
  }
234
236
  ),
235
237
  /* @__PURE__ */ jsx(
@@ -218,7 +218,10 @@ const ChartBar = ({ data, empty }) => {
218
218
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
219
219
  import_recharts.YAxis,
220
220
  {
221
- ...options.axisY
221
+ ...{
222
+ ...options.axisY,
223
+ allowDecimals: false
224
+ }
222
225
  }
223
226
  ),
224
227
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -256,7 +259,7 @@ const ChartLine = ({
256
259
  "shortcodes"
257
260
  ],
258
261
  empty,
259
- format = (value) => value,
262
+ format,
260
263
  labels: given = {},
261
264
  legend = true,
262
265
  zeros = false
@@ -451,7 +454,10 @@ const ChartLine = ({
451
454
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
452
455
  import_recharts.YAxis,
453
456
  {
454
- ...options.axisY
457
+ ...{
458
+ ...options.axisY,
459
+ allowDecimals: Boolean(format)
460
+ }
455
461
  }
456
462
  ),
457
463
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -462,7 +468,7 @@ const ChartLine = ({
462
468
  // A money chart passes `format` so a day's summed gross reads
463
469
  // "$12.50", not 12.500000000000002; counts pass nothing.
464
470
  formatter: (value, key) => [
465
- format(value),
471
+ format ? format(value) : value,
466
472
  name(key)
467
473
  ]
468
474
  }
@@ -185,7 +185,10 @@ const ChartBar = ({ data, empty }) => {
185
185
  /* @__PURE__ */ jsx(
186
186
  YAxis,
187
187
  {
188
- ...options.axisY
188
+ ...{
189
+ ...options.axisY,
190
+ allowDecimals: false
191
+ }
189
192
  }
190
193
  ),
191
194
  /* @__PURE__ */ jsx(
@@ -223,7 +226,7 @@ const ChartLine = ({
223
226
  "shortcodes"
224
227
  ],
225
228
  empty,
226
- format = (value) => value,
229
+ format,
227
230
  labels: given = {},
228
231
  legend = true,
229
232
  zeros = false
@@ -418,7 +421,10 @@ const ChartLine = ({
418
421
  /* @__PURE__ */ jsx(
419
422
  YAxis,
420
423
  {
421
- ...options.axisY
424
+ ...{
425
+ ...options.axisY,
426
+ allowDecimals: Boolean(format)
427
+ }
422
428
  }
423
429
  ),
424
430
  /* @__PURE__ */ jsx(
@@ -429,7 +435,7 @@ const ChartLine = ({
429
435
  // A money chart passes `format` so a day's summed gross reads
430
436
  // "$12.50", not 12.500000000000002; counts pass nothing.
431
437
  formatter: (value, key) => [
432
- format(value),
438
+ format ? format(value) : value,
433
439
  name(key)
434
440
  ]
435
441
  }
@@ -0,0 +1,404 @@
1
+ "use client";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var shipping_rates_exports = {};
30
+ __export(shipping_rates_exports, {
31
+ FormRate: () => FormRate,
32
+ default: () => shipping_rates_default
33
+ });
34
+ module.exports = __toCommonJS(shipping_rates_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_react_query = require("@tanstack/react-query");
37
+ var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
38
+ var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
39
+ var import_products = require("@drawbridge/drawbridge-utils/products");
40
+ var import_form = require("../shared/lib/form");
41
+ var import_yup = __toESM(require("../shared/lib/yup"));
42
+ var import_hooks = require("./lib/hooks");
43
+ var import_order_sections = require("./order-sections");
44
+ var import_card_section = __toESM(require("./card-section"));
45
+ var import_paged = __toESM(require("./paged"));
46
+ var import_table = __toESM(require("./table"));
47
+ var import_table_cell_title = __toESM(require("./table-cell-title"));
48
+ var import_button = __toESM(require("../shared/button"));
49
+ var import_fieldset = __toESM(require("../shared/fieldset"));
50
+ var import_form2 = __toESM(require("../shared/form"));
51
+ var import_input_switch = __toESM(require("../shared/input-switch"));
52
+ var import_input_group = __toESM(require("../input-group"));
53
+ var import_input_number = __toESM(require("../input-number"));
54
+ var import_input_select = __toESM(require("../input-select"));
55
+ var import_input_text = __toESM(require("../input-text"));
56
+ var import_pencil = __toESM(require("../icons/pencil"));
57
+ var import_plus = __toESM(require("../icons/plus"));
58
+ var import_trash = __toESM(require("../icons/trash"));
59
+ const COUNTRIES = [
60
+ {
61
+ label: "Canada",
62
+ value: "CA"
63
+ },
64
+ {
65
+ label: "United States",
66
+ value: "US"
67
+ }
68
+ ];
69
+ const countryName = (code) => {
70
+ var _a;
71
+ return ((_a = COUNTRIES.find((item) => item.value === code)) == null ? void 0 : _a.label) || code;
72
+ };
73
+ const keyOf = (delivery) => delivery ? delivery.minimum + "-" + delivery.maximum : "";
74
+ const FormRate = ({ currency, endpoint, onError, onSuccess, values }) => {
75
+ const { control, formState, handleSubmit, watch } = (0, import_form.useForm)({
76
+ resolver: (0, import_yup.resolver)(
77
+ import_yup.default.object({
78
+ free: import_yup.default.number().label("Free over").nullable().when("freeOver", ([on], schema) => on ? schema.required().min(0) : schema),
79
+ name: import_yup.default.string().label("Name").trim().required().max(100),
80
+ price: import_yup.default.number().label("Price").typeError("Price is a required field").required().min(0)
81
+ })
82
+ ),
83
+ values: {
84
+ country: (values == null ? void 0 : values.country) || COUNTRIES[0].value,
85
+ delivery: keyOf((values == null ? void 0 : values.delivery) || import_products.DELIVERY[2]),
86
+ free: (values == null ? void 0 : values.free) ?? null,
87
+ freeOver: Number.isFinite(values == null ? void 0 : values.free),
88
+ name: (values == null ? void 0 : values.name) || "",
89
+ price: (values == null ? void 0 : values.price) ?? null
90
+ }
91
+ });
92
+ const onSubmit = async ({ country, delivery, free, freeOver, name, price }) => {
93
+ try {
94
+ const [minimum, maximum] = delivery.split("-").map(Number);
95
+ onSuccess(await (0, import_fetch.request)({
96
+ body: {
97
+ country,
98
+ delivery: {
99
+ maximum,
100
+ minimum
101
+ },
102
+ free: freeOver ? Number(free) : null,
103
+ name: name.trim(),
104
+ price: Number(price)
105
+ },
106
+ endpoint,
107
+ method: (values == null ? void 0 : values.id) ? "PUT" : "POST"
108
+ }));
109
+ } catch (error) {
110
+ onError == null ? void 0 : onError(error);
111
+ }
112
+ };
113
+ const field = (name, label, input, extra = {}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
114
+ import_form.Controller,
115
+ {
116
+ ...{
117
+ control,
118
+ name,
119
+ render: ({ field: { onChange, value } }) => {
120
+ var _a, _b;
121
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
122
+ import_input_group.default,
123
+ {
124
+ ...{
125
+ ...extra,
126
+ error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a[name]) == null ? void 0 : _b.message,
127
+ input: input({ onChange, value }),
128
+ label
129
+ }
130
+ }
131
+ );
132
+ }
133
+ }
134
+ },
135
+ name
136
+ );
137
+ const symbol = { before: (0, import_drawbridge_utils.formatCurrency)({ code: (currency || "usd").toUpperCase(), value: 0 }).replace(/[\d.,\s]/g, "") };
138
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
139
+ import_form2.default,
140
+ {
141
+ ...{
142
+ className: "relative w-full space-y-6",
143
+ onSubmit: handleSubmit(onSubmit)
144
+ },
145
+ children: [
146
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
147
+ import_fieldset.default,
148
+ {
149
+ ...{
150
+ className: "space-y-6",
151
+ disabled: formState == null ? void 0 : formState.isSubmitting
152
+ },
153
+ children: [
154
+ field("name", "Name", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
155
+ import_input_text.default,
156
+ {
157
+ ...{
158
+ onChange,
159
+ placeholder: "Standard",
160
+ value: value || ""
161
+ }
162
+ }
163
+ )),
164
+ field("price", "Price", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
165
+ import_input_number.default,
166
+ {
167
+ ...{
168
+ min: 0,
169
+ onChange,
170
+ step: 0.01,
171
+ value: value ?? ""
172
+ }
173
+ }
174
+ ), symbol),
175
+ field("country", "Country", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
176
+ import_input_select.default,
177
+ {
178
+ ...{
179
+ onChange,
180
+ options: COUNTRIES,
181
+ value
182
+ }
183
+ }
184
+ )),
185
+ field("delivery", "Delivery", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
186
+ import_input_select.default,
187
+ {
188
+ ...{
189
+ onChange,
190
+ options: import_products.DELIVERY.map((item) => ({
191
+ label: (0, import_products.deliveryText)(item),
192
+ value: keyOf(item)
193
+ })),
194
+ value
195
+ }
196
+ }
197
+ )),
198
+ field("freeOver", "Free over", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
199
+ import_input_switch.default,
200
+ {
201
+ ...{
202
+ "aria-label": "Free over",
203
+ onChange,
204
+ value: Boolean(value)
205
+ }
206
+ }
207
+ )),
208
+ watch("freeOver") && field("free", "Order amount", ({ onChange, value }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
209
+ import_input_number.default,
210
+ {
211
+ ...{
212
+ min: 0,
213
+ onChange,
214
+ step: 0.01,
215
+ value: value ?? ""
216
+ }
217
+ }
218
+ ), symbol)
219
+ ]
220
+ }
221
+ ),
222
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
223
+ import_fieldset.default,
224
+ {
225
+ ...{
226
+ disabled: formState == null ? void 0 : formState.isSubmitting
227
+ },
228
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
229
+ import_button.default,
230
+ {
231
+ ...{
232
+ loading: formState == null ? void 0 : formState.isSubmitting,
233
+ type: "submit"
234
+ },
235
+ children: "Submit"
236
+ }
237
+ )
238
+ }
239
+ )
240
+ ]
241
+ }
242
+ );
243
+ };
244
+ const ShippingRates = ({ currency, manage, organization }) => {
245
+ var _a, _b, _c, _d;
246
+ const queryClient = (0, import_react_query.useQueryClient)();
247
+ const modal = (0, import_hooks.useModal)({
248
+ queryClient
249
+ });
250
+ const { onError, onSuccess } = (0, import_hooks.useCallbacks)({
251
+ queryClient
252
+ });
253
+ const confirm = (0, import_order_sections.useConfirm)();
254
+ const queryKey = ["rates", organization];
255
+ const base = "/organization/" + organization;
256
+ const listed = (0, import_react_query.useQuery)({
257
+ enabled: false,
258
+ queryKey: [...queryKey, 0]
259
+ });
260
+ const count = ((_b = (_a = listed.data) == null ? void 0 : _a.pageInfo) == null ? void 0 : _b.total) ?? ((_d = (_c = listed.data) == null ? void 0 : _c.items) == null ? void 0 : _d.length) ?? 0;
261
+ const saved = (response) => onSuccess(response, {
262
+ invalidate: [
263
+ {
264
+ queryKey
265
+ }
266
+ ]
267
+ });
268
+ const money = (value) => (0, import_drawbridge_utils.formatCurrency)({ code: (currency || "usd").toUpperCase(), value });
269
+ const open = (rate) => modal.open({
270
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
271
+ FormRate,
272
+ {
273
+ ...{
274
+ currency,
275
+ endpoint: (rate == null ? void 0 : rate.id) ? base + "/rate/" + rate.id : base + "/rates",
276
+ onError,
277
+ onSuccess: saved,
278
+ values: rate
279
+ }
280
+ }
281
+ ),
282
+ title: (rate == null ? void 0 : rate.id) ? "Edit rate" : "New rate"
283
+ });
284
+ const remove = (rate) => confirm({
285
+ action: "Remove",
286
+ endpoint: base + "/rate/" + rate.id,
287
+ message: "Orders already placed keep the price they recorded.",
288
+ method: "DELETE",
289
+ onSuccess: saved,
290
+ title: "Remove shipping price"
291
+ });
292
+ const cta = count < import_products.MAX_RATES && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
293
+ import_button.default,
294
+ {
295
+ ...{
296
+ "aria-label": "New rate",
297
+ disabled: !manage,
298
+ icon: import_plus.default,
299
+ inline: true,
300
+ onClick: () => open(),
301
+ size: "small",
302
+ variant: "secondary"
303
+ }
304
+ }
305
+ );
306
+ const columns = [
307
+ {
308
+ id: "name",
309
+ header: "Rate",
310
+ cell: ({ row }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
311
+ import_table_cell_title.default,
312
+ {
313
+ ...{
314
+ subtitle: (0, import_products.deliveryText)(row.original.delivery),
315
+ title: row.original.name
316
+ }
317
+ }
318
+ ),
319
+ sortable: false
320
+ },
321
+ {
322
+ id: "country",
323
+ header: "Country",
324
+ cell: ({ row }) => countryName(row.original.country),
325
+ sortable: false
326
+ },
327
+ {
328
+ id: "price",
329
+ header: "Price",
330
+ cell: ({ row }) => row.original.price ? money(row.original.price) : "Free",
331
+ sortable: false
332
+ },
333
+ {
334
+ id: "free",
335
+ header: "Free over",
336
+ cell: ({ row }) => Number.isFinite(row.original.free) ? money(row.original.free) : "\u2014",
337
+ sortable: false
338
+ }
339
+ ];
340
+ const actions = (row) => ({
341
+ controls: [
342
+ {
343
+ "aria-label": "Edit " + row.name,
344
+ disabled: !manage,
345
+ element: "button",
346
+ icon: import_pencil.default,
347
+ onClick: () => open(row),
348
+ type: "button"
349
+ },
350
+ {
351
+ "aria-label": "Remove " + row.name,
352
+ disabled: !manage,
353
+ element: "button",
354
+ icon: import_trash.default,
355
+ onClick: () => remove(row),
356
+ type: "button"
357
+ }
358
+ ]
359
+ });
360
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
361
+ import_card_section.default,
362
+ {
363
+ ...{
364
+ className: "shrink-0",
365
+ cta,
366
+ title: "Shipping"
367
+ },
368
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
369
+ import_paged.default,
370
+ {
371
+ ...{
372
+ empty: {
373
+ message: "No shipping prices",
374
+ variant: "secondary"
375
+ },
376
+ endpoint: base + "/rates",
377
+ params: {
378
+ limit: import_products.MAX_RATES,
379
+ sort: {
380
+ createdAt: 1
381
+ }
382
+ },
383
+ queryKey
384
+ },
385
+ children: ({ items }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
386
+ import_table.default,
387
+ {
388
+ ...{
389
+ actions,
390
+ columns,
391
+ data: items
392
+ }
393
+ }
394
+ )
395
+ }
396
+ )
397
+ }
398
+ );
399
+ };
400
+ var shipping_rates_default = ShippingRates;
401
+ // Annotate the CommonJS export names for ESM import in node:
402
+ 0 && (module.exports = {
403
+ FormRate
404
+ });