@mercurjs/admin 2.2.0-canary.21 → 2.2.0-canary.23

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 (52) hide show
  1. package/dist/{add-campaign-promotions-EB2MYHMZ.js → add-campaign-promotions-2IOKLEMG.js} +3 -3
  2. package/dist/{campaign-detail-EAARQB3E.js → campaign-detail-5WNSQVKG.js} +4 -4
  3. package/dist/{category-detail-ABK4MEZP.js → category-detail-SNN3ZBPS.js} +1 -1
  4. package/dist/{category-icon-edit-4GXAK4JZ.js → category-icon-edit-SP5TQYA7.js} +1 -1
  5. package/dist/{category-list-PFOINLTU.js → category-list-OKKJX73E.js} +1 -1
  6. package/dist/{category-media-7SLAXXXM.js → category-media-IGRRTZ65.js} +2 -2
  7. package/dist/{chunk-3LYOKDUA.js → chunk-2H3KXP53.js} +1 -1
  8. package/dist/{chunk-KZB7LCF2.js → chunk-3EQOAHVG.js} +1 -1
  9. package/dist/{chunk-YUECTKEY.js → chunk-3ZCBTIIC.js} +1 -1
  10. package/dist/{chunk-2KPITPB7.js → chunk-5PWXUMCA.js} +1 -1
  11. package/dist/{chunk-ZLETFDWJ.js → chunk-746L7AHM.js} +2 -2
  12. package/dist/{chunk-AH3KBVKC.js → chunk-7PAVVX2P.js} +1 -1
  13. package/dist/{chunk-JEJQKTZO.js → chunk-ASNNJIW7.js} +2 -2
  14. package/dist/{chunk-RXRDZ47F.js → chunk-BHJFT3ST.js} +3 -3
  15. package/dist/{chunk-5NQUJQXX.js → chunk-FP6YPFKF.js} +23 -7
  16. package/dist/{chunk-G66KMUI5.js → chunk-K7EOVKKV.js} +1 -1
  17. package/dist/{chunk-67RX3M6X.js → chunk-MEAFCHUY.js} +2 -2
  18. package/dist/{chunk-EDDKIVMF.js → chunk-NONPU75Q.js} +1 -1
  19. package/dist/{chunk-EG45GIE3.js → chunk-PAGH4K4C.js} +47 -14
  20. package/dist/{chunk-ARN66CDK.js → chunk-PQAEYURH.js} +1 -1
  21. package/dist/{chunk-6YPV4T3R.js → chunk-RXZZEPW3.js} +1 -1
  22. package/dist/{chunk-PN5C4AND.js → chunk-STPSVH3T.js} +1 -1
  23. package/dist/{chunk-LLHYICP5.js → chunk-UWKKDBBZ.js} +1 -1
  24. package/dist/{chunk-JAPKOO4T.js → chunk-ZIIZGCTQ.js} +1 -1
  25. package/dist/{collection-detail-36QTD3ZU.js → collection-detail-UDBTTHLK.js} +1 -1
  26. package/dist/{collection-icon-edit-V4SNBMD5.js → collection-icon-edit-HNYGQJXC.js} +1 -1
  27. package/dist/{collection-list-UN7C36DU.js → collection-list-U74G2R6W.js} +2 -2
  28. package/dist/{collection-media-ESJUYVF7.js → collection-media-G42DRQ6K.js} +2 -2
  29. package/dist/{commission-rule-commission-edit-TA3H3EEN.js → commission-rule-commission-edit-EAOSJNA2.js} +3 -3
  30. package/dist/{commission-rule-create-O7Z25SC7.js → commission-rule-create-X3AYVCQG.js} +183 -67
  31. package/dist/{commission-rule-detail-I7LVSNAM.js → commission-rule-detail-EITJYZG5.js} +3 -3
  32. package/dist/{commission-rule-edit-YSHDTYZY.js → commission-rule-edit-FZLHYL4A.js} +2 -2
  33. package/dist/{commissions-list-OUGVPED6.js → commissions-list-TT2ITT75.js} +4 -3
  34. package/dist/{global-commission-edit-LCD6JJUX.js → global-commission-edit-3CEVUAAP.js} +46 -29
  35. package/dist/index.js +39 -39
  36. package/dist/{order-edit-billing-address-R7DOKCV5.js → order-edit-billing-address-5XHAAGT7.js} +1 -1
  37. package/dist/pages/index.d.ts +2 -2
  38. package/dist/pages/index.js +17 -17
  39. package/dist/{product-create-R5HJ2GYT.js → product-create-LY3HDOLG.js} +3 -3
  40. package/dist/{product-media-OL4ETNFW.js → product-media-PWPVCTC2.js} +2 -2
  41. package/dist/{product-tag-detail-NVTDW7BR.js → product-tag-detail-LPILT2ZS.js} +1 -1
  42. package/dist/{product-tag-list-T6BDTH24.js → product-tag-list-CK6W4LSP.js} +1 -1
  43. package/dist/{promotion-detail-SCS7MWD7.js → promotion-detail-ORDL76NG.js} +3 -3
  44. package/dist/{promotion-list-ZFF4E4ZW.js → promotion-list-NMD23NXJ.js} +4 -4
  45. package/dist/{refund-reason-list-F56TJAGR.js → refund-reason-list-LDLZ4JL6.js} +1 -1
  46. package/dist/{reset-password-Y7HXY2NX.js → reset-password-GA3NEKEX.js} +1 -1
  47. package/dist/{return-reason-list-EJ5DLDR2.js → return-reason-list-2LFMI7CT.js} +1 -1
  48. package/dist/{store-edit-YEWQFHHM.js → store-edit-QJXV27DI.js} +2 -2
  49. package/dist/{tax-region-create-YQ5YBOC3.js → tax-region-create-MS6G5YVE.js} +1 -1
  50. package/dist/{tax-region-tax-override-create-5MIAKHY6.js → tax-region-tax-override-create-I5FQMBBC.js} +1 -1
  51. package/dist/{tax-region-tax-override-edit-EHLIO56A.js → tax-region-tax-override-edit-4X56DGNL.js} +1 -1
  52. package/package.json +1 -1
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  CommissionValueFields,
3
3
  useStoreCurrencies
4
- } from "./chunk-KZB7LCF2.js";
4
+ } from "./chunk-3EQOAHVG.js";
5
5
  import "./chunk-QR3GYYX6.js";
6
6
  import {
7
7
  SCOPE_TYPE_DIMENSIONS,
8
8
  buildRulesFromScope,
9
9
  buildValuesPayload
10
- } from "./chunk-PN5C4AND.js";
10
+ } from "./chunk-STPSVH3T.js";
11
11
  import "./chunk-MAEP2UCK.js";
12
12
  import {
13
13
  useComboboxData
@@ -60,7 +60,7 @@ import { useForm } from "react-hook-form";
60
60
  import { useTranslation as useTranslation3 } from "react-i18next";
61
61
 
62
62
  // src/pages/commissions/commission-rule-create/components/create-commission-rule-form/create-commission-rule-commission.tsx
63
- import { Heading, Select } from "@medusajs/ui";
63
+ import { Heading, RadioGroup } from "@medusajs/ui";
64
64
  import { useTranslation } from "react-i18next";
65
65
  import { jsx, jsxs } from "react/jsx-runtime";
66
66
  var CreateCommissionRuleCommission = () => {
@@ -77,15 +77,47 @@ var CreateCommissionRuleCommission = () => {
77
77
  {
78
78
  control: form.control,
79
79
  name: "commissionType",
80
- render: ({ field: { onChange, ref, ...field } }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
80
+ render: ({ field: { onChange, ...rest } }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
81
81
  /* @__PURE__ */ jsx(Form.Label, { children: t("commissions.fields.type.label", "Type") }),
82
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(Select, { ...field, onValueChange: onChange, dir: direction, children: [
83
- /* @__PURE__ */ jsx(Select.Trigger, { ref, children: /* @__PURE__ */ jsx(Select.Value, {}) }),
84
- /* @__PURE__ */ jsxs(Select.Content, { children: [
85
- /* @__PURE__ */ jsx(Select.Item, { value: "percentage", children: t("commissions.fields.type.percentage", "Percentage") }),
86
- /* @__PURE__ */ jsx(Select.Item, { value: "fixed", children: t("commissions.fields.type.fixed", "Fixed") })
87
- ] })
88
- ] }) }),
82
+ /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(
83
+ RadioGroup,
84
+ {
85
+ dir: direction,
86
+ onValueChange: onChange,
87
+ ...rest,
88
+ className: "grid grid-cols-1 gap-4 md:grid-cols-2",
89
+ "data-testid": "commission-rule-commission-type-radio-group",
90
+ children: [
91
+ /* @__PURE__ */ jsx(
92
+ RadioGroup.ChoiceBox,
93
+ {
94
+ value: "percentage",
95
+ label: t(
96
+ "commissions.fields.type.percentage",
97
+ "Percentage"
98
+ ),
99
+ description: t(
100
+ "commissions.fields.type.percentageHint",
101
+ "Charge a percentage of the order total."
102
+ ),
103
+ "data-testid": "commission-rule-commission-type-option-percentage"
104
+ }
105
+ ),
106
+ /* @__PURE__ */ jsx(
107
+ RadioGroup.ChoiceBox,
108
+ {
109
+ value: "fixed",
110
+ label: t("commissions.fields.type.fixed", "Fixed"),
111
+ description: t(
112
+ "commissions.fields.type.fixedHint",
113
+ "Charge a fixed amount per order."
114
+ ),
115
+ "data-testid": "commission-rule-commission-type-option-fixed"
116
+ }
117
+ )
118
+ ]
119
+ }
120
+ ) }),
89
121
  /* @__PURE__ */ jsx(Form.ErrorMessage, {})
90
122
  ] })
91
123
  }
@@ -133,11 +165,11 @@ var CreateCommissionRuleCommission = () => {
133
165
  CreateCommissionRuleCommission._tabMeta = defineTabMeta({
134
166
  id: "commission",
135
167
  labelKey: "commissions.create.commission",
136
- validationFields: ["commissionType"]
168
+ validationFields: ["commissionType", "value"]
137
169
  });
138
170
 
139
171
  // src/pages/commissions/commission-rule-create/components/create-commission-rule-form/create-commission-rule-details.tsx
140
- import { Heading as Heading2, Input, Select as Select2 } from "@medusajs/ui";
172
+ import { Heading as Heading2, Input, RadioGroup as RadioGroup2 } from "@medusajs/ui";
141
173
  import { useTranslation as useTranslation2 } from "react-i18next";
142
174
  import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
143
175
  var CreateCommissionRuleDetails = () => {
@@ -173,58 +205,109 @@ var CreateCommissionRuleDetails = () => {
173
205
  return /* @__PURE__ */ jsx2("div", { className: "flex flex-col items-center p-16", children: /* @__PURE__ */ jsxs2("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
174
206
  /* @__PURE__ */ jsx2(Heading2, { children: t("commissions.create.details", "Details") }),
175
207
  /* @__PURE__ */ jsxs2("div", { className: "flex flex-col gap-y-4", children: [
176
- /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [
177
- /* @__PURE__ */ jsx2(
178
- Form.Field,
179
- {
180
- control: form.control,
181
- name: "title",
182
- render: ({ field }) => /* @__PURE__ */ jsxs2(Form.Item, { children: [
183
- /* @__PURE__ */ jsx2(Form.Label, { children: t("fields.title") }),
184
- /* @__PURE__ */ jsx2(Form.Control, { children: /* @__PURE__ */ jsx2(Input, { autoComplete: "off", ...field }) }),
185
- /* @__PURE__ */ jsx2(Form.ErrorMessage, {})
186
- ] })
187
- }
188
- ),
189
- /* @__PURE__ */ jsx2(
190
- Form.Field,
191
- {
192
- control: form.control,
193
- name: "code",
194
- render: ({ field }) => /* @__PURE__ */ jsxs2(Form.Item, { children: [
195
- /* @__PURE__ */ jsx2(Form.Label, { children: t("commissions.fields.code", "Code") }),
196
- /* @__PURE__ */ jsx2(Form.Control, { children: /* @__PURE__ */ jsx2(Input, { autoComplete: "off", ...field }) }),
197
- /* @__PURE__ */ jsx2(Form.ErrorMessage, {})
198
- ] })
199
- }
200
- )
201
- ] }),
208
+ /* @__PURE__ */ jsx2(
209
+ Form.Field,
210
+ {
211
+ control: form.control,
212
+ name: "title",
213
+ render: ({ field }) => /* @__PURE__ */ jsxs2(Form.Item, { children: [
214
+ /* @__PURE__ */ jsx2(Form.Label, { children: t("fields.title") }),
215
+ /* @__PURE__ */ jsx2(Form.Control, { children: /* @__PURE__ */ jsx2(Input, { autoComplete: "off", ...field }) }),
216
+ /* @__PURE__ */ jsx2(Form.ErrorMessage, {})
217
+ ] })
218
+ }
219
+ ),
202
220
  /* @__PURE__ */ jsx2(
203
221
  Form.Field,
204
222
  {
205
223
  control: form.control,
206
224
  name: "scopeType",
207
- render: ({ field: { onChange, ref, ...field } }) => /* @__PURE__ */ jsxs2(Form.Item, { children: [
225
+ render: ({ field: { onChange, ...rest } }) => /* @__PURE__ */ jsxs2(Form.Item, { children: [
208
226
  /* @__PURE__ */ jsx2(Form.Label, { children: t("commissions.fields.scopeType.label", "Type") }),
209
- /* @__PURE__ */ jsx2(Form.Control, { children: /* @__PURE__ */ jsxs2(Select2, { ...field, onValueChange: onChange, dir: direction, children: [
210
- /* @__PURE__ */ jsx2(Select2.Trigger, { ref, children: /* @__PURE__ */ jsx2(Select2.Value, {}) }),
211
- /* @__PURE__ */ jsxs2(Select2.Content, { children: [
212
- /* @__PURE__ */ jsx2(Select2.Item, { value: "store", children: t("commissions.fields.scopeType.store", "Store") }),
213
- /* @__PURE__ */ jsx2(Select2.Item, { value: "product_type", children: t(
214
- "commissions.fields.scopeType.productType",
215
- "Product Type"
216
- ) }),
217
- /* @__PURE__ */ jsx2(Select2.Item, { value: "category", children: t("commissions.fields.scopeType.category", "Category") }),
218
- /* @__PURE__ */ jsx2(Select2.Item, { value: "store_product_type", children: t(
219
- "commissions.fields.scopeType.storeProductType",
220
- "Store + Product Type"
221
- ) }),
222
- /* @__PURE__ */ jsx2(Select2.Item, { value: "store_category", children: t(
223
- "commissions.fields.scopeType.storeCategory",
224
- "Store + Category"
225
- ) })
226
- ] })
227
- ] }) }),
227
+ /* @__PURE__ */ jsx2(Form.Control, { children: /* @__PURE__ */ jsxs2(
228
+ RadioGroup2,
229
+ {
230
+ dir: direction,
231
+ onValueChange: onChange,
232
+ ...rest,
233
+ className: "grid grid-cols-1 gap-4 md:grid-cols-2",
234
+ "data-testid": "commission-rule-scope-type-radio-group",
235
+ children: [
236
+ /* @__PURE__ */ jsx2(
237
+ RadioGroup2.ChoiceBox,
238
+ {
239
+ value: "store",
240
+ label: t("commissions.fields.scopeType.store", "Store"),
241
+ description: t(
242
+ "commissions.fields.scopeType.storeHint",
243
+ "Apply to specific stores."
244
+ ),
245
+ "data-testid": "commission-rule-scope-type-option-store"
246
+ }
247
+ ),
248
+ /* @__PURE__ */ jsx2(
249
+ RadioGroup2.ChoiceBox,
250
+ {
251
+ value: "product_type",
252
+ label: t(
253
+ "commissions.fields.scopeType.productType",
254
+ "Product Type"
255
+ ),
256
+ description: t(
257
+ "commissions.fields.scopeType.productTypeHint",
258
+ "Apply to specific product types."
259
+ ),
260
+ "data-testid": "commission-rule-scope-type-option-product-type"
261
+ }
262
+ ),
263
+ /* @__PURE__ */ jsx2(
264
+ RadioGroup2.ChoiceBox,
265
+ {
266
+ value: "category",
267
+ label: t(
268
+ "commissions.fields.scopeType.category",
269
+ "Category"
270
+ ),
271
+ description: t(
272
+ "commissions.fields.scopeType.categoryHint",
273
+ "Apply to specific categories."
274
+ ),
275
+ "data-testid": "commission-rule-scope-type-option-category"
276
+ }
277
+ ),
278
+ /* @__PURE__ */ jsx2(
279
+ RadioGroup2.ChoiceBox,
280
+ {
281
+ value: "store_product_type",
282
+ label: t(
283
+ "commissions.fields.scopeType.storeProductType",
284
+ "Store + Product Type"
285
+ ),
286
+ description: t(
287
+ "commissions.fields.scopeType.storeProductTypeHint",
288
+ "Apply to product types within specific stores."
289
+ ),
290
+ "data-testid": "commission-rule-scope-type-option-store-product-type"
291
+ }
292
+ ),
293
+ /* @__PURE__ */ jsx2(
294
+ RadioGroup2.ChoiceBox,
295
+ {
296
+ value: "store_category",
297
+ label: t(
298
+ "commissions.fields.scopeType.storeCategory",
299
+ "Store + Category"
300
+ ),
301
+ description: t(
302
+ "commissions.fields.scopeType.storeCategoryHint",
303
+ "Apply to categories within specific stores."
304
+ ),
305
+ "data-testid": "commission-rule-scope-type-option-store-category"
306
+ }
307
+ )
308
+ ]
309
+ }
310
+ ) }),
228
311
  /* @__PURE__ */ jsx2(Form.ErrorMessage, {})
229
312
  ] })
230
313
  }
@@ -299,15 +382,20 @@ CreateCommissionRuleDetails._tabMeta = defineTabMeta(
299
382
  {
300
383
  id: "details",
301
384
  labelKey: "commissions.create.details",
302
- validationFields: ["title", "code", "scopeType"]
385
+ validationFields: [
386
+ "title",
387
+ "scopeType",
388
+ "stores",
389
+ "productTypes",
390
+ "categories"
391
+ ]
303
392
  }
304
393
  );
305
394
 
306
395
  // src/pages/commissions/commission-rule-create/components/create-commission-rule-form/schema.ts
307
396
  import * as zod from "zod";
308
397
  var CreateCommissionRuleSchema = zod.object({
309
- title: zod.string().min(1),
310
- code: zod.string().min(1),
398
+ title: zod.string().min(1, "Please enter a title"),
311
399
  scopeType: zod.enum([
312
400
  "store",
313
401
  "product_type",
@@ -319,10 +407,40 @@ var CreateCommissionRuleSchema = zod.object({
319
407
  productTypes: zod.array(zod.string()),
320
408
  categories: zod.array(zod.string()),
321
409
  commissionType: zod.enum(["percentage", "fixed"]),
322
- value: zod.coerce.number().min(0),
410
+ value: zod.coerce.number().optional(),
323
411
  fixed_values: zod.record(zod.string(), zod.coerce.number()).optional(),
324
412
  include_tax: zod.boolean(),
325
413
  include_shipping: zod.boolean()
414
+ }).superRefine((data, ctx) => {
415
+ const dimensions = SCOPE_TYPE_DIMENSIONS[data.scopeType];
416
+ if (dimensions.includes("seller") && data.stores.length === 0) {
417
+ ctx.addIssue({
418
+ code: zod.ZodIssueCode.custom,
419
+ path: ["stores"],
420
+ message: "Please select at least one store"
421
+ });
422
+ }
423
+ if (dimensions.includes("product_type") && data.productTypes.length === 0) {
424
+ ctx.addIssue({
425
+ code: zod.ZodIssueCode.custom,
426
+ path: ["productTypes"],
427
+ message: "Please select at least one product type"
428
+ });
429
+ }
430
+ if (dimensions.includes("product_category") && data.categories.length === 0) {
431
+ ctx.addIssue({
432
+ code: zod.ZodIssueCode.custom,
433
+ path: ["categories"],
434
+ message: "Please select at least one category"
435
+ });
436
+ }
437
+ if (data.commissionType === "percentage" && (data.value === void 0 || Number.isNaN(data.value))) {
438
+ ctx.addIssue({
439
+ code: zod.ZodIssueCode.custom,
440
+ path: ["value"],
441
+ message: "Please enter a value."
442
+ });
443
+ }
326
444
  });
327
445
 
328
446
  // src/pages/commissions/commission-rule-create/components/create-commission-rule-form/create-commission-rule-form.tsx
@@ -334,13 +452,12 @@ var CreateCommissionRuleForm = () => {
334
452
  const form = useForm({
335
453
  defaultValues: {
336
454
  title: "",
337
- code: "",
338
455
  scopeType: "store",
339
456
  stores: [],
340
457
  productTypes: [],
341
458
  categories: [],
342
459
  commissionType: "percentage",
343
- value: 0,
460
+ value: void 0,
344
461
  fixed_values: {},
345
462
  include_tax: false,
346
463
  include_shipping: false
@@ -358,7 +475,6 @@ var CreateCommissionRuleForm = () => {
358
475
  await mutateAsync(
359
476
  {
360
477
  name: values.title,
361
- code: values.code,
362
478
  type: values.commissionType,
363
479
  value: isFixed ? 0 : values.value,
364
480
  ...isFixed ? { values: buildValuesPayload(currencies, values.fixed_values) } : {},
@@ -371,7 +487,7 @@ var CreateCommissionRuleForm = () => {
371
487
  onSuccess: ({ commission_rate }) => {
372
488
  toast.success(
373
489
  t("commissions.create.successToast", {
374
- defaultValue: "Commission rule created"
490
+ defaultValue: "Commission rule was successfully created."
375
491
  })
376
492
  );
377
493
  handleSuccess(`/settings/commissions/${commission_rate.id}`);
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  CommissionRuleDetail
3
- } from "./chunk-JEJQKTZO.js";
4
- import "./chunk-RXRDZ47F.js";
5
- import "./chunk-PN5C4AND.js";
3
+ } from "./chunk-ASNNJIW7.js";
4
+ import "./chunk-BHJFT3ST.js";
5
+ import "./chunk-STPSVH3T.js";
6
6
  import "./chunk-FI474ADU.js";
7
7
  import "./chunk-3XPXUIK3.js";
8
8
  import "./chunk-E74OUNA3.js";
@@ -4,7 +4,7 @@ import {
4
4
  deriveScopeType,
5
5
  diffScopeRules,
6
6
  referenceIds
7
- } from "./chunk-PN5C4AND.js";
7
+ } from "./chunk-STPSVH3T.js";
8
8
  import {
9
9
  useComboboxData
10
10
  } from "./chunk-5KGMGL4N.js";
@@ -126,7 +126,7 @@ var EditCommissionRuleForm = ({ rule }) => {
126
126
  }
127
127
  toast.success(
128
128
  t("commissions.edit.successToast", {
129
- defaultValue: "Commission rule updated"
129
+ defaultValue: "Commission rule was successfully updated."
130
130
  })
131
131
  );
132
132
  handleSuccess();
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  CommissionsPage
3
- } from "./chunk-EG45GIE3.js";
4
- import "./chunk-RXRDZ47F.js";
5
- import "./chunk-PN5C4AND.js";
3
+ } from "./chunk-PAGH4K4C.js";
4
+ import "./chunk-BHJFT3ST.js";
5
+ import "./chunk-STPSVH3T.js";
6
6
  import "./chunk-JHIMVLB2.js";
7
+ import "./chunk-DB6ANJBO.js";
7
8
  import "./chunk-PHOCVOZ5.js";
8
9
  import "./chunk-FQERBIVS.js";
9
10
  import "./chunk-NQEXDLYH.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  CommissionValueFields,
3
3
  useStoreCurrencies
4
- } from "./chunk-KZB7LCF2.js";
4
+ } from "./chunk-3EQOAHVG.js";
5
5
  import {
6
6
  buildValuesPayload,
7
7
  fixedValuesFromRate
8
- } from "./chunk-PN5C4AND.js";
8
+ } from "./chunk-STPSVH3T.js";
9
9
  import "./chunk-MAEP2UCK.js";
10
10
  import {
11
11
  SwitchBox
@@ -38,18 +38,25 @@ import "./chunk-NBMM2TZK.js";
38
38
 
39
39
  // src/pages/commissions/global-commission-edit/global-commission-edit.tsx
40
40
  import { zodResolver } from "@hookform/resolvers/zod";
41
- import { Button, Heading, Input, Select, toast } from "@medusajs/ui";
41
+ import { Button, Heading, RadioGroup, toast } from "@medusajs/ui";
42
42
  import { useForm } from "react-hook-form";
43
43
  import { useTranslation } from "react-i18next";
44
44
  import * as zod from "zod";
45
45
  import { jsx, jsxs } from "react/jsx-runtime";
46
46
  var EditGlobalCommissionSchema = zod.object({
47
- code: zod.string().min(1),
48
47
  type: zod.enum(["percentage", "fixed"]),
49
- value: zod.coerce.number().min(0),
48
+ value: zod.coerce.number().optional(),
50
49
  fixed_values: zod.record(zod.string(), zod.coerce.number()).optional(),
51
50
  include_tax: zod.boolean(),
52
51
  include_shipping: zod.boolean()
52
+ }).superRefine((data, ctx) => {
53
+ if (data.type === "percentage" && (data.value === void 0 || Number.isNaN(data.value))) {
54
+ ctx.addIssue({
55
+ code: zod.ZodIssueCode.custom,
56
+ path: ["value"],
57
+ message: "Please enter a value."
58
+ });
59
+ }
53
60
  });
54
61
  var EditGlobalCommissionForm = ({ rate }) => {
55
62
  const { t } = useTranslation();
@@ -58,7 +65,6 @@ var EditGlobalCommissionForm = ({ rate }) => {
58
65
  const { currencies } = useStoreCurrencies();
59
66
  const form = useForm({
60
67
  defaultValues: {
61
- code: rate.code,
62
68
  type: rate.type,
63
69
  value: rate.value,
64
70
  fixed_values: fixedValuesFromRate(rate),
@@ -71,7 +77,6 @@ var EditGlobalCommissionForm = ({ rate }) => {
71
77
  const handleSubmit = form.handleSubmit(async (values) => {
72
78
  const isFixed = values.type === "fixed";
73
79
  const payload = {
74
- code: values.code,
75
80
  type: values.type,
76
81
  value: isFixed ? 0 : values.value,
77
82
  ...isFixed ? { values: buildValuesPayload(currencies, values.fixed_values) } : {},
@@ -82,7 +87,7 @@ var EditGlobalCommissionForm = ({ rate }) => {
82
87
  onSuccess: () => {
83
88
  toast.success(
84
89
  t("commissions.global.edit.successToast", {
85
- defaultValue: "Global commission updated"
90
+ defaultValue: "Global commission was successfully updated."
86
91
  })
87
92
  );
88
93
  handleSuccess();
@@ -93,37 +98,49 @@ var EditGlobalCommissionForm = ({ rate }) => {
93
98
  const watchType = form.watch("type");
94
99
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { onSubmit: handleSubmit, className: "flex flex-1 flex-col", children: [
95
100
  /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
96
- /* @__PURE__ */ jsx(
97
- Form.Field,
98
- {
99
- control: form.control,
100
- name: "code",
101
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
102
- /* @__PURE__ */ jsx(Form.Label, { children: t("commissions.fields.code", "Code") }),
103
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { autoComplete: "off", ...field }) }),
104
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
105
- ] })
106
- }
107
- ),
108
101
  /* @__PURE__ */ jsx(
109
102
  Form.Field,
110
103
  {
111
104
  control: form.control,
112
105
  name: "type",
113
- render: ({ field: { onChange, ref, ...field } }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
106
+ render: ({ field: { onChange, ...rest } }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
114
107
  /* @__PURE__ */ jsx(Form.Label, { children: t("commissions.fields.type.label", "Type") }),
115
108
  /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(
116
- Select,
109
+ RadioGroup,
117
110
  {
118
- ...field,
119
- onValueChange: onChange,
120
111
  dir: direction,
112
+ onValueChange: onChange,
113
+ ...rest,
114
+ className: "grid grid-cols-1 gap-4 md:grid-cols-2",
115
+ "data-testid": "global-commission-type-radio-group",
121
116
  children: [
122
- /* @__PURE__ */ jsx(Select.Trigger, { ref, children: /* @__PURE__ */ jsx(Select.Value, {}) }),
123
- /* @__PURE__ */ jsxs(Select.Content, { children: [
124
- /* @__PURE__ */ jsx(Select.Item, { value: "percentage", children: t("commissions.fields.type.percentage", "Percentage") }),
125
- /* @__PURE__ */ jsx(Select.Item, { value: "fixed", children: t("commissions.fields.type.fixed", "Fixed") })
126
- ] })
117
+ /* @__PURE__ */ jsx(
118
+ RadioGroup.ChoiceBox,
119
+ {
120
+ value: "percentage",
121
+ label: t(
122
+ "commissions.fields.type.percentage",
123
+ "Percentage"
124
+ ),
125
+ description: t(
126
+ "commissions.fields.type.percentageHint",
127
+ "Charge a percentage of the order total."
128
+ ),
129
+ "data-testid": "global-commission-type-option-percentage"
130
+ }
131
+ ),
132
+ /* @__PURE__ */ jsx(
133
+ RadioGroup.ChoiceBox,
134
+ {
135
+ value: "fixed",
136
+ label: t("commissions.fields.type.fixed", "Fixed"),
137
+ description: t(
138
+ "commissions.fields.type.fixedHint",
139
+ "Charge a fixed amount per order."
140
+ ),
141
+ "data-testid": "global-commission-type-option-fixed"
142
+ }
143
+ )
127
144
  ]
128
145
  }
129
146
  ) }),