@mercurjs/admin 2.0.1 → 2.0.2

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.
package/dist/index.js CHANGED
@@ -4176,7 +4176,7 @@ function getRouteMap({
4176
4176
  children: [
4177
4177
  {
4178
4178
  path: "create",
4179
- lazy: () => import("./region-create-BFA7ATKB.js")
4179
+ lazy: () => import("./region-create-NI7QPOS5.js")
4180
4180
  }
4181
4181
  ]
4182
4182
  },
@@ -4199,7 +4199,7 @@ function getRouteMap({
4199
4199
  children: [
4200
4200
  {
4201
4201
  path: "edit",
4202
- lazy: () => import("./region-edit-75ZVOJ3U.js")
4202
+ lazy: () => import("./region-edit-AGC3N4RU.js")
4203
4203
  },
4204
4204
  {
4205
4205
  path: "countries/add",
@@ -0,0 +1,659 @@
1
+ import {
2
+ useCountries,
3
+ useCountryTableColumns,
4
+ useCountryTableQuery
5
+ } from "./chunk-TUJIAA5O.js";
6
+ import {
7
+ formatProvider
8
+ } from "./chunk-VW56KWO2.js";
9
+ import {
10
+ countries
11
+ } from "./chunk-JRTZWK77.js";
12
+ import "./chunk-FQERBIVS.js";
13
+ import {
14
+ _DataTable,
15
+ useDataTable
16
+ } from "./chunk-ULJ3OMWU.js";
17
+ import "./chunk-YBZWO4ZV.js";
18
+ import "./chunk-KAZ5BYTQ.js";
19
+ import "./chunk-3EF54XFY.js";
20
+ import {
21
+ currencies
22
+ } from "./chunk-IQPN4PZJ.js";
23
+ import {
24
+ useComboboxData
25
+ } from "./chunk-AEFDAU3Y.js";
26
+ import {
27
+ Combobox
28
+ } from "./chunk-AW77UWCZ.js";
29
+ import "./chunk-TKGWSUEI.js";
30
+ import {
31
+ KeyboundForm
32
+ } from "./chunk-U2ZFCAPX.js";
33
+ import "./chunk-INNFZYX2.js";
34
+ import {
35
+ useDocumentDirection
36
+ } from "./chunk-Y7QKP6QU.js";
37
+ import "./chunk-KBYZLKI4.js";
38
+ import "./chunk-YWWUOGJA.js";
39
+ import "./chunk-THHRRYRS.js";
40
+ import "./chunk-UZWFZMOX.js";
41
+ import "./chunk-XQNVC4Q7.js";
42
+ import {
43
+ RouteFocusModal,
44
+ StackedFocusModal,
45
+ useRouteModal,
46
+ useStackedModal
47
+ } from "./chunk-OV7R2AH5.js";
48
+ import {
49
+ Form
50
+ } from "./chunk-3QSRE5LS.js";
51
+ import {
52
+ useCreateRegion
53
+ } from "./chunk-W5UPPL3W.js";
54
+ import {
55
+ useStore
56
+ } from "./chunk-LC6TM5OT.js";
57
+ import "./chunk-7SJC6BWZ.js";
58
+ import "./chunk-RHKRREUU.js";
59
+ import "./chunk-ZA2KFUFR.js";
60
+ import {
61
+ sdk
62
+ } from "./chunk-RIN4CBRB.js";
63
+ import "./chunk-NBMM2TZK.js";
64
+
65
+ // src/pages/regions/region-create/components/create-region-form/create-region-form.tsx
66
+ import { zodResolver } from "@hookform/resolvers/zod";
67
+ import { XMarkMini } from "@medusajs/icons";
68
+ import {
69
+ Button,
70
+ Checkbox,
71
+ Heading,
72
+ Input,
73
+ Select,
74
+ Switch,
75
+ Text,
76
+ clx,
77
+ toast
78
+ } from "@medusajs/ui";
79
+ import { createColumnHelper } from "@tanstack/react-table";
80
+ import { useMemo, useState } from "react";
81
+ import { useForm, useWatch } from "react-hook-form";
82
+ import { useTranslation } from "react-i18next";
83
+ import * as zod from "zod";
84
+ import { jsx, jsxs } from "react/jsx-runtime";
85
+ var CreateRegionSchema = zod.object({
86
+ name: zod.string().min(1),
87
+ currency_code: zod.string().min(2, "Select a currency"),
88
+ automatic_taxes: zod.boolean(),
89
+ is_tax_inclusive: zod.boolean(),
90
+ countries: zod.array(zod.object({ code: zod.string(), name: zod.string() })),
91
+ payment_providers: zod.array(zod.string()).min(1)
92
+ });
93
+ var PREFIX = "cr";
94
+ var PAGE_SIZE = 50;
95
+ var STACKED_MODAL_ID = "countries-modal";
96
+ var CreateRegionForm = ({ currencies: currencies2 }) => {
97
+ const { setIsOpen } = useStackedModal();
98
+ const [rowSelection, setRowSelection] = useState({});
99
+ const { handleSuccess } = useRouteModal();
100
+ const direction = useDocumentDirection();
101
+ const form = useForm({
102
+ defaultValues: {
103
+ name: "",
104
+ currency_code: "",
105
+ automatic_taxes: true,
106
+ is_tax_inclusive: false,
107
+ countries: [],
108
+ payment_providers: []
109
+ },
110
+ resolver: zodResolver(CreateRegionSchema)
111
+ });
112
+ const selectedCountries = useWatch({
113
+ control: form.control,
114
+ name: "countries",
115
+ defaultValue: []
116
+ });
117
+ const { t } = useTranslation();
118
+ const { mutateAsync: createRegion, isPending: isPendingRegion } = useCreateRegion();
119
+ const handleSubmit = form.handleSubmit(async (values) => {
120
+ await createRegion(
121
+ {
122
+ name: values.name,
123
+ countries: values.countries.map((c) => c.code),
124
+ currency_code: values.currency_code,
125
+ payment_providers: values.payment_providers,
126
+ automatic_taxes: values.automatic_taxes,
127
+ is_tax_inclusive: values.is_tax_inclusive
128
+ },
129
+ {
130
+ onSuccess: ({ region }) => {
131
+ toast.success(t("regions.toast.create"));
132
+ handleSuccess(`../${region.id}`);
133
+ },
134
+ onError: (e) => {
135
+ toast.error(e.message);
136
+ }
137
+ }
138
+ );
139
+ });
140
+ const { searchParams, raw } = useCountryTableQuery({
141
+ pageSize: PAGE_SIZE,
142
+ prefix: PREFIX
143
+ });
144
+ const { countries: countries2, count } = useCountries({
145
+ countries: countries.map((c, i) => ({
146
+ display_name: c.display_name,
147
+ name: c.name,
148
+ id: i,
149
+ iso_2: c.iso_2,
150
+ iso_3: c.iso_3,
151
+ num_code: c.num_code,
152
+ region_id: null,
153
+ region: {}
154
+ })),
155
+ ...searchParams
156
+ });
157
+ const columns = useColumns();
158
+ const { table } = useDataTable({
159
+ data: countries2 || [],
160
+ columns,
161
+ count,
162
+ enablePagination: true,
163
+ enableRowSelection: true,
164
+ rowSelection: {
165
+ state: rowSelection,
166
+ updater: setRowSelection
167
+ },
168
+ getRowId: (row) => row.iso_2,
169
+ pageSize: PAGE_SIZE,
170
+ prefix: PREFIX
171
+ });
172
+ const saveCountries = () => {
173
+ const selected = Object.keys(rowSelection).filter(
174
+ (key) => rowSelection[key]
175
+ );
176
+ form.setValue(
177
+ "countries",
178
+ selected.map((key) => ({
179
+ code: key,
180
+ name: countries.find((c) => c.iso_2 === key).display_name
181
+ })),
182
+ { shouldDirty: true, shouldTouch: true }
183
+ );
184
+ setIsOpen(STACKED_MODAL_ID, false);
185
+ };
186
+ const removeCountry = (code) => {
187
+ const update = selectedCountries.filter((c) => c.code !== code);
188
+ const ids = update.map((c) => c.code).reduce((acc, c) => {
189
+ acc[c] = true;
190
+ return acc;
191
+ }, {});
192
+ form.setValue("countries", update, {
193
+ shouldDirty: true,
194
+ shouldTouch: true
195
+ });
196
+ setRowSelection(ids);
197
+ };
198
+ const clearCountries = () => {
199
+ form.setValue("countries", [], { shouldDirty: true, shouldTouch: true });
200
+ setRowSelection({});
201
+ };
202
+ const comboboxProviders = useComboboxData({
203
+ queryFn: (params) => sdk.admin.payments.paymentProviders.query({
204
+ ...params,
205
+ is_enabled: true,
206
+ id: []
207
+ }),
208
+ queryKey: ["payment_providers"],
209
+ getOptions: (data) => data.payment_providers.map((pp) => ({
210
+ label: formatProvider(pp.id),
211
+ value: pp.id
212
+ }))
213
+ });
214
+ return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, "data-testid": "region-create-form", children: /* @__PURE__ */ jsxs(
215
+ KeyboundForm,
216
+ {
217
+ className: "flex h-full flex-col overflow-hidden",
218
+ onSubmit: handleSubmit,
219
+ children: [
220
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, { "data-testid": "region-create-form-header" }),
221
+ /* @__PURE__ */ jsx(
222
+ RouteFocusModal.Body,
223
+ {
224
+ className: "flex overflow-hidden",
225
+ "data-testid": "region-create-form-body",
226
+ children: /* @__PURE__ */ jsx(
227
+ "div",
228
+ {
229
+ className: clx(
230
+ "flex h-full w-full flex-col items-center overflow-y-auto p-16"
231
+ ),
232
+ id: "form-section",
233
+ children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
234
+ /* @__PURE__ */ jsxs("div", { "data-testid": "region-create-form-header-section", children: [
235
+ /* @__PURE__ */ jsx(Heading, { "data-testid": "region-create-form-heading", children: t("regions.createRegion") }),
236
+ /* @__PURE__ */ jsx(
237
+ Text,
238
+ {
239
+ size: "small",
240
+ className: "text-ui-fg-subtle",
241
+ "data-testid": "region-create-form-hint",
242
+ children: t("regions.createRegionHint")
243
+ }
244
+ )
245
+ ] }),
246
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-4", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [
247
+ /* @__PURE__ */ jsx(
248
+ Form.Field,
249
+ {
250
+ control: form.control,
251
+ name: "name",
252
+ render: ({ field }) => {
253
+ return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "region-create-form-name-item", children: [
254
+ /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-name-label", children: t("fields.name") }),
255
+ /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-name-control", children: /* @__PURE__ */ jsx(
256
+ Input,
257
+ {
258
+ ...field,
259
+ "data-testid": "region-create-form-name-input"
260
+ }
261
+ ) }),
262
+ /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-name-error" })
263
+ ] });
264
+ }
265
+ }
266
+ ),
267
+ /* @__PURE__ */ jsx(
268
+ Form.Field,
269
+ {
270
+ control: form.control,
271
+ name: "currency_code",
272
+ render: ({ field: { onChange, ref, ...field } }) => {
273
+ return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "region-create-form-currency-item", children: [
274
+ /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-currency-label", children: t("fields.currency") }),
275
+ /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-currency-control", children: /* @__PURE__ */ jsxs(
276
+ Select,
277
+ {
278
+ dir: direction,
279
+ ...field,
280
+ onValueChange: onChange,
281
+ "data-testid": "region-create-form-currency-select",
282
+ children: [
283
+ /* @__PURE__ */ jsx(
284
+ Select.Trigger,
285
+ {
286
+ ref,
287
+ "data-testid": "region-create-form-currency-select-trigger",
288
+ children: /* @__PURE__ */ jsx(Select.Value, {})
289
+ }
290
+ ),
291
+ /* @__PURE__ */ jsx(Select.Content, { "data-testid": "region-create-form-currency-select-content", children: currencies2.map((currency) => /* @__PURE__ */ jsx(
292
+ Select.Item,
293
+ {
294
+ value: currency.code,
295
+ "data-testid": `region-create-form-currency-select-option-${currency.code}`,
296
+ children: currency.name
297
+ },
298
+ currency.code
299
+ )) })
300
+ ]
301
+ }
302
+ ) }),
303
+ /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-currency-error" })
304
+ ] });
305
+ }
306
+ }
307
+ )
308
+ ] }) }),
309
+ /* @__PURE__ */ jsx(
310
+ Form.Field,
311
+ {
312
+ control: form.control,
313
+ name: "automatic_taxes",
314
+ render: ({ field: { value, onChange, ...field } }) => {
315
+ return /* @__PURE__ */ jsx(Form.Item, { "data-testid": "region-create-form-automatic-taxes-item", children: /* @__PURE__ */ jsxs("div", { children: [
316
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between", children: [
317
+ /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-automatic-taxes-label", children: t("fields.automaticTaxes") }),
318
+ /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-automatic-taxes-control", children: /* @__PURE__ */ jsx(
319
+ Switch,
320
+ {
321
+ dir: "ltr",
322
+ className: "rtl:rotate-180",
323
+ ...field,
324
+ checked: value,
325
+ onCheckedChange: onChange,
326
+ "data-testid": "region-create-form-automatic-taxes-switch"
327
+ }
328
+ ) })
329
+ ] }),
330
+ /* @__PURE__ */ jsx(Form.Hint, { "data-testid": "region-create-form-automatic-taxes-hint", children: t("regions.automaticTaxesHint") }),
331
+ /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-automatic-taxes-error" })
332
+ ] }) });
333
+ }
334
+ }
335
+ ),
336
+ /* @__PURE__ */ jsx(
337
+ Form.Field,
338
+ {
339
+ control: form.control,
340
+ name: "is_tax_inclusive",
341
+ render: ({ field: { value, onChange, ...field } }) => {
342
+ return /* @__PURE__ */ jsx(Form.Item, { "data-testid": "region-create-form-tax-inclusive-item", children: /* @__PURE__ */ jsxs("div", { children: [
343
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between", children: [
344
+ /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-tax-inclusive-label", children: t("fields.taxInclusivePricing") }),
345
+ /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-tax-inclusive-control", children: /* @__PURE__ */ jsx(
346
+ Switch,
347
+ {
348
+ className: "rtl:rotate-180",
349
+ dir: "ltr",
350
+ ...field,
351
+ checked: value,
352
+ onCheckedChange: onChange,
353
+ "data-testid": "region-create-form-tax-inclusive-switch"
354
+ }
355
+ ) })
356
+ ] }),
357
+ /* @__PURE__ */ jsx(Form.Hint, { "data-testid": "region-create-form-tax-inclusive-hint", children: t("regions.taxInclusiveHint") }),
358
+ /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-tax-inclusive-error" })
359
+ ] }) });
360
+ }
361
+ }
362
+ ),
363
+ /* @__PURE__ */ jsx("div", { className: "bg-ui-border-base h-px w-full" }),
364
+ /* @__PURE__ */ jsxs(
365
+ "div",
366
+ {
367
+ className: "flex flex-col gap-y-4",
368
+ "data-testid": "region-create-form-countries-section",
369
+ children: [
370
+ /* @__PURE__ */ jsxs("div", { "data-testid": "region-create-form-countries-header", children: [
371
+ /* @__PURE__ */ jsx(
372
+ Text,
373
+ {
374
+ size: "small",
375
+ leading: "compact",
376
+ weight: "plus",
377
+ "data-testid": "region-create-form-countries-label",
378
+ children: t("fields.countries")
379
+ }
380
+ ),
381
+ /* @__PURE__ */ jsx(
382
+ Text,
383
+ {
384
+ size: "small",
385
+ className: "text-ui-fg-subtle",
386
+ "data-testid": "region-create-form-countries-hint",
387
+ children: t("regions.countriesHint")
388
+ }
389
+ )
390
+ ] }),
391
+ selectedCountries.length > 0 && /* @__PURE__ */ jsxs(
392
+ "div",
393
+ {
394
+ className: "flex flex-wrap gap-2",
395
+ "data-testid": "region-create-form-countries-selected",
396
+ children: [
397
+ selectedCountries.map((country) => /* @__PURE__ */ jsx(
398
+ CountryTag,
399
+ {
400
+ country,
401
+ onRemove: removeCountry
402
+ },
403
+ country.code
404
+ )),
405
+ /* @__PURE__ */ jsx(
406
+ Button,
407
+ {
408
+ variant: "transparent",
409
+ size: "small",
410
+ className: "text-ui-fg-muted hover:text-ui-fg-subtle",
411
+ onClick: clearCountries,
412
+ "data-testid": "region-create-form-countries-clear-all-button",
413
+ children: t("actions.clearAll")
414
+ }
415
+ )
416
+ ]
417
+ }
418
+ ),
419
+ /* @__PURE__ */ jsxs(
420
+ StackedFocusModal,
421
+ {
422
+ id: STACKED_MODAL_ID,
423
+ "data-testid": "region-create-form-countries-modal",
424
+ children: [
425
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
426
+ Button,
427
+ {
428
+ variant: "secondary",
429
+ size: "small",
430
+ "data-testid": "region-create-form-countries-add-button",
431
+ children: t("regions.addCountries")
432
+ }
433
+ ) }) }),
434
+ /* @__PURE__ */ jsx(StackedFocusModal.Content, { "data-testid": "region-create-form-countries-modal-content", children: /* @__PURE__ */ jsxs("div", { className: "flex size-full flex-col overflow-hidden", children: [
435
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, { "data-testid": "region-create-form-countries-modal-header", children: /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: t("regions.addCountries") }) }) }),
436
+ /* @__PURE__ */ jsx(
437
+ StackedFocusModal.Body,
438
+ {
439
+ className: "overflow-hidden",
440
+ "data-testid": "region-create-form-countries-modal-body",
441
+ children: /* @__PURE__ */ jsx(
442
+ _DataTable,
443
+ {
444
+ table,
445
+ columns,
446
+ count,
447
+ pageSize: PAGE_SIZE,
448
+ orderBy: [
449
+ { key: "display_name", label: t("fields.name") },
450
+ { key: "iso_2", label: t("fields.code") }
451
+ ],
452
+ pagination: true,
453
+ search: "autofocus",
454
+ layout: "fill",
455
+ queryObject: raw,
456
+ prefix: PREFIX,
457
+ "data-testid": "region-create-form-countries-modal-table"
458
+ }
459
+ )
460
+ }
461
+ ),
462
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { "data-testid": "region-create-form-countries-modal-footer", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
463
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(
464
+ Button,
465
+ {
466
+ variant: "secondary",
467
+ size: "small",
468
+ "data-testid": "region-create-form-countries-modal-cancel-button",
469
+ children: t("actions.cancel")
470
+ }
471
+ ) }),
472
+ /* @__PURE__ */ jsx(
473
+ Button,
474
+ {
475
+ size: "small",
476
+ type: "button",
477
+ onClick: saveCountries,
478
+ "data-testid": "region-create-form-countries-modal-save-button",
479
+ children: t("actions.save")
480
+ }
481
+ )
482
+ ] }) })
483
+ ] }) })
484
+ ]
485
+ }
486
+ )
487
+ ]
488
+ }
489
+ ),
490
+ /* @__PURE__ */ jsx("div", { className: "bg-ui-border-base h-px w-full" }),
491
+ /* @__PURE__ */ jsxs(
492
+ "div",
493
+ {
494
+ className: "flex flex-col gap-y-4",
495
+ "data-testid": "region-create-form-payment-providers-section",
496
+ children: [
497
+ /* @__PURE__ */ jsxs("div", { "data-testid": "region-create-form-payment-providers-header", children: [
498
+ /* @__PURE__ */ jsx(
499
+ Text,
500
+ {
501
+ size: "small",
502
+ leading: "compact",
503
+ weight: "plus",
504
+ "data-testid": "region-create-form-payment-providers-label",
505
+ children: t("fields.providers")
506
+ }
507
+ ),
508
+ /* @__PURE__ */ jsx(
509
+ Text,
510
+ {
511
+ size: "small",
512
+ className: "text-ui-fg-subtle",
513
+ "data-testid": "region-create-form-payment-providers-hint",
514
+ children: t("regions.providersHint")
515
+ }
516
+ )
517
+ ] }),
518
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: /* @__PURE__ */ jsx(
519
+ Form.Field,
520
+ {
521
+ control: form.control,
522
+ name: "payment_providers",
523
+ render: ({ field }) => {
524
+ return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "region-create-form-payment-providers-item", children: [
525
+ /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-payment-providers-item-label", children: t("fields.paymentProviders") }),
526
+ /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-payment-providers-item-control", children: /* @__PURE__ */ jsx(
527
+ Combobox,
528
+ {
529
+ forceHideInput: true,
530
+ options: comboboxProviders.options,
531
+ fetchNextPage: comboboxProviders.fetchNextPage,
532
+ ...field,
533
+ "data-testid": "region-create-form-payment-providers-combobox"
534
+ }
535
+ ) }),
536
+ /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-payment-providers-item-error" })
537
+ ] });
538
+ }
539
+ }
540
+ ) })
541
+ ]
542
+ }
543
+ )
544
+ ] })
545
+ }
546
+ )
547
+ }
548
+ ),
549
+ /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { "data-testid": "region-create-form-footer", children: [
550
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(
551
+ Button,
552
+ {
553
+ size: "small",
554
+ variant: "secondary",
555
+ "data-testid": "region-create-form-cancel-button",
556
+ children: t("actions.cancel")
557
+ }
558
+ ) }),
559
+ /* @__PURE__ */ jsx(
560
+ Button,
561
+ {
562
+ size: "small",
563
+ type: "submit",
564
+ isLoading: isPendingRegion,
565
+ "data-testid": "region-create-form-save-button",
566
+ children: t("actions.save")
567
+ }
568
+ )
569
+ ] })
570
+ ]
571
+ }
572
+ ) });
573
+ };
574
+ var columnHelper = createColumnHelper();
575
+ var useColumns = () => {
576
+ const base = useCountryTableColumns();
577
+ return useMemo(
578
+ () => [
579
+ columnHelper.display({
580
+ id: "select",
581
+ header: ({ table }) => {
582
+ return /* @__PURE__ */ jsx(
583
+ Checkbox,
584
+ {
585
+ checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
586
+ onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value),
587
+ "data-testid": "region-create-form-countries-modal-select-all-checkbox"
588
+ }
589
+ );
590
+ },
591
+ cell: ({ row }) => {
592
+ const isPreselected = !row.getCanSelect();
593
+ return /* @__PURE__ */ jsx(
594
+ Checkbox,
595
+ {
596
+ checked: row.getIsSelected() || isPreselected,
597
+ disabled: isPreselected,
598
+ onCheckedChange: (value) => row.toggleSelected(!!value),
599
+ onClick: (e) => {
600
+ e.stopPropagation();
601
+ },
602
+ "data-testid": `region-create-form-countries-modal-select-checkbox-${row.original.iso_2}`
603
+ }
604
+ );
605
+ }
606
+ }),
607
+ ...base
608
+ ],
609
+ [base]
610
+ );
611
+ };
612
+ var CountryTag = ({
613
+ country,
614
+ onRemove
615
+ }) => {
616
+ return /* @__PURE__ */ jsxs(
617
+ "div",
618
+ {
619
+ className: "bg-ui-bg-field shadow-borders-base transition-fg hover:bg-ui-bg-field-hover flex h-7 items-center overflow-hidden rounded-md",
620
+ "data-testid": `region-create-form-country-tag-${country.code}`,
621
+ children: [
622
+ /* @__PURE__ */ jsx(
623
+ "div",
624
+ {
625
+ className: "txt-compact-small-plus flex h-full select-none items-center justify-center px-2 py-0.5",
626
+ "data-testid": `region-create-form-country-tag-${country.code}-name`,
627
+ children: country.name
628
+ }
629
+ ),
630
+ /* @__PURE__ */ jsx(
631
+ "button",
632
+ {
633
+ type: "button",
634
+ onClick: () => onRemove(country.code),
635
+ className: "focus-visible:bg-ui-bg-field-hover transition-fg hover:bg-ui-bg-field-hover flex h-full w-7 items-center justify-center border-l outline-none",
636
+ "data-testid": `region-create-form-country-tag-${country.code}-remove-button`,
637
+ children: /* @__PURE__ */ jsx(XMarkMini, { className: "text-ui-fg-muted" })
638
+ }
639
+ )
640
+ ]
641
+ }
642
+ );
643
+ };
644
+
645
+ // src/pages/regions/region-create/region-create.tsx
646
+ import { jsx as jsx2 } from "react/jsx-runtime";
647
+ var RegionCreate = () => {
648
+ const { store, isPending: isLoading, isError, error } = useStore();
649
+ const storeCurrencies = (store?.supported_currencies ?? []).map(
650
+ (c) => currencies[c.currency_code.toUpperCase()]
651
+ );
652
+ if (isError) {
653
+ throw error;
654
+ }
655
+ return /* @__PURE__ */ jsx2(RouteFocusModal, { "data-testid": "region-create-modal", children: !isLoading && store && /* @__PURE__ */ jsx2(CreateRegionForm, { currencies: storeCurrencies }) });
656
+ };
657
+ export {
658
+ RegionCreate as Component
659
+ };
@@ -80,7 +80,11 @@ var EditRegionForm = ({
80
80
  });
81
81
  const comboboxProviders = useComboboxData({
82
82
  queryKey: ["payment_providers"],
83
- queryFn: (params) => sdk.admin.payment.listPaymentProviders({ ...params, is_enabled: true }),
83
+ queryFn: (params) => sdk.admin.payments.paymentProviders.query({
84
+ ...params,
85
+ is_enabled: true,
86
+ id: []
87
+ }),
84
88
  getOptions: (data) => data.payment_providers.map((pp) => ({
85
89
  label: formatProvider(pp.id),
86
90
  value: pp.id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/admin",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mercurjs/mercur",
@@ -1,508 +0,0 @@
1
- import {
2
- useCountries,
3
- useCountryTableColumns,
4
- useCountryTableQuery
5
- } from "./chunk-TUJIAA5O.js";
6
- import {
7
- formatProvider
8
- } from "./chunk-VW56KWO2.js";
9
- import {
10
- countries
11
- } from "./chunk-JRTZWK77.js";
12
- import "./chunk-FQERBIVS.js";
13
- import {
14
- _DataTable,
15
- useDataTable
16
- } from "./chunk-ULJ3OMWU.js";
17
- import "./chunk-YBZWO4ZV.js";
18
- import "./chunk-KAZ5BYTQ.js";
19
- import "./chunk-3EF54XFY.js";
20
- import {
21
- currencies
22
- } from "./chunk-IQPN4PZJ.js";
23
- import {
24
- useComboboxData
25
- } from "./chunk-AEFDAU3Y.js";
26
- import {
27
- Combobox
28
- } from "./chunk-AW77UWCZ.js";
29
- import "./chunk-TKGWSUEI.js";
30
- import {
31
- KeyboundForm
32
- } from "./chunk-U2ZFCAPX.js";
33
- import "./chunk-INNFZYX2.js";
34
- import {
35
- useDocumentDirection
36
- } from "./chunk-Y7QKP6QU.js";
37
- import "./chunk-KBYZLKI4.js";
38
- import "./chunk-YWWUOGJA.js";
39
- import "./chunk-THHRRYRS.js";
40
- import "./chunk-UZWFZMOX.js";
41
- import "./chunk-XQNVC4Q7.js";
42
- import {
43
- RouteFocusModal,
44
- StackedFocusModal,
45
- useRouteModal,
46
- useStackedModal
47
- } from "./chunk-OV7R2AH5.js";
48
- import {
49
- Form
50
- } from "./chunk-3QSRE5LS.js";
51
- import {
52
- useCreateRegion
53
- } from "./chunk-W5UPPL3W.js";
54
- import {
55
- useStore
56
- } from "./chunk-LC6TM5OT.js";
57
- import "./chunk-7SJC6BWZ.js";
58
- import "./chunk-RHKRREUU.js";
59
- import "./chunk-ZA2KFUFR.js";
60
- import {
61
- sdk
62
- } from "./chunk-RIN4CBRB.js";
63
- import "./chunk-NBMM2TZK.js";
64
-
65
- // src/pages/regions/region-create/components/create-region-form/create-region-form.tsx
66
- import { zodResolver } from "@hookform/resolvers/zod";
67
- import { XMarkMini } from "@medusajs/icons";
68
- import {
69
- Button,
70
- Checkbox,
71
- Heading,
72
- Input,
73
- Select,
74
- Switch,
75
- Text,
76
- clx,
77
- toast
78
- } from "@medusajs/ui";
79
- import { createColumnHelper } from "@tanstack/react-table";
80
- import { useMemo, useState } from "react";
81
- import { useForm, useWatch } from "react-hook-form";
82
- import { useTranslation } from "react-i18next";
83
- import * as zod from "zod";
84
- import { jsx, jsxs } from "react/jsx-runtime";
85
- var CreateRegionSchema = zod.object({
86
- name: zod.string().min(1),
87
- currency_code: zod.string().min(2, "Select a currency"),
88
- automatic_taxes: zod.boolean(),
89
- is_tax_inclusive: zod.boolean(),
90
- countries: zod.array(zod.object({ code: zod.string(), name: zod.string() })),
91
- payment_providers: zod.array(zod.string()).min(1)
92
- });
93
- var PREFIX = "cr";
94
- var PAGE_SIZE = 50;
95
- var STACKED_MODAL_ID = "countries-modal";
96
- var CreateRegionForm = ({ currencies: currencies2 }) => {
97
- const { setIsOpen } = useStackedModal();
98
- const [rowSelection, setRowSelection] = useState({});
99
- const { handleSuccess } = useRouteModal();
100
- const direction = useDocumentDirection();
101
- const form = useForm({
102
- defaultValues: {
103
- name: "",
104
- currency_code: "",
105
- automatic_taxes: true,
106
- is_tax_inclusive: false,
107
- countries: [],
108
- payment_providers: []
109
- },
110
- resolver: zodResolver(CreateRegionSchema)
111
- });
112
- const selectedCountries = useWatch({
113
- control: form.control,
114
- name: "countries",
115
- defaultValue: []
116
- });
117
- const { t } = useTranslation();
118
- const { mutateAsync: createRegion, isPending: isPendingRegion } = useCreateRegion();
119
- const handleSubmit = form.handleSubmit(async (values) => {
120
- await createRegion(
121
- {
122
- name: values.name,
123
- countries: values.countries.map((c) => c.code),
124
- currency_code: values.currency_code,
125
- payment_providers: values.payment_providers,
126
- automatic_taxes: values.automatic_taxes,
127
- is_tax_inclusive: values.is_tax_inclusive
128
- },
129
- {
130
- onSuccess: ({ region }) => {
131
- toast.success(t("regions.toast.create"));
132
- handleSuccess(`../${region.id}`);
133
- },
134
- onError: (e) => {
135
- toast.error(e.message);
136
- }
137
- }
138
- );
139
- });
140
- const { searchParams, raw } = useCountryTableQuery({
141
- pageSize: PAGE_SIZE,
142
- prefix: PREFIX
143
- });
144
- const { countries: countries2, count } = useCountries({
145
- countries: countries.map((c, i) => ({
146
- display_name: c.display_name,
147
- name: c.name,
148
- id: i,
149
- iso_2: c.iso_2,
150
- iso_3: c.iso_3,
151
- num_code: c.num_code,
152
- region_id: null,
153
- region: {}
154
- })),
155
- ...searchParams
156
- });
157
- const columns = useColumns();
158
- const { table } = useDataTable({
159
- data: countries2 || [],
160
- columns,
161
- count,
162
- enablePagination: true,
163
- enableRowSelection: true,
164
- rowSelection: {
165
- state: rowSelection,
166
- updater: setRowSelection
167
- },
168
- getRowId: (row) => row.iso_2,
169
- pageSize: PAGE_SIZE,
170
- prefix: PREFIX
171
- });
172
- const saveCountries = () => {
173
- const selected = Object.keys(rowSelection).filter(
174
- (key) => rowSelection[key]
175
- );
176
- form.setValue(
177
- "countries",
178
- selected.map((key) => ({
179
- code: key,
180
- name: countries.find((c) => c.iso_2 === key).display_name
181
- })),
182
- { shouldDirty: true, shouldTouch: true }
183
- );
184
- setIsOpen(STACKED_MODAL_ID, false);
185
- };
186
- const removeCountry = (code) => {
187
- const update = selectedCountries.filter((c) => c.code !== code);
188
- const ids = update.map((c) => c.code).reduce((acc, c) => {
189
- acc[c] = true;
190
- return acc;
191
- }, {});
192
- form.setValue("countries", update, { shouldDirty: true, shouldTouch: true });
193
- setRowSelection(ids);
194
- };
195
- const clearCountries = () => {
196
- form.setValue("countries", [], { shouldDirty: true, shouldTouch: true });
197
- setRowSelection({});
198
- };
199
- const comboboxProviders = useComboboxData({
200
- queryFn: (params) => sdk.admin.payment.listPaymentProviders({ ...params, is_enabled: true }),
201
- queryKey: ["payment_providers"],
202
- getOptions: (data) => data.payment_providers.map((pp) => ({
203
- label: formatProvider(pp.id),
204
- value: pp.id
205
- }))
206
- });
207
- return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, "data-testid": "region-create-form", children: /* @__PURE__ */ jsxs(
208
- KeyboundForm,
209
- {
210
- className: "flex h-full flex-col overflow-hidden",
211
- onSubmit: handleSubmit,
212
- children: [
213
- /* @__PURE__ */ jsx(RouteFocusModal.Header, { "data-testid": "region-create-form-header" }),
214
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex overflow-hidden", "data-testid": "region-create-form-body", children: /* @__PURE__ */ jsx(
215
- "div",
216
- {
217
- className: clx(
218
- "flex h-full w-full flex-col items-center overflow-y-auto p-16"
219
- ),
220
- id: "form-section",
221
- children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
222
- /* @__PURE__ */ jsxs("div", { "data-testid": "region-create-form-header-section", children: [
223
- /* @__PURE__ */ jsx(Heading, { "data-testid": "region-create-form-heading", children: t("regions.createRegion") }),
224
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "region-create-form-hint", children: t("regions.createRegionHint") })
225
- ] }),
226
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-4", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [
227
- /* @__PURE__ */ jsx(
228
- Form.Field,
229
- {
230
- control: form.control,
231
- name: "name",
232
- render: ({ field }) => {
233
- return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "region-create-form-name-item", children: [
234
- /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-name-label", children: t("fields.name") }),
235
- /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-name-control", children: /* @__PURE__ */ jsx(Input, { ...field, "data-testid": "region-create-form-name-input" }) }),
236
- /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-name-error" })
237
- ] });
238
- }
239
- }
240
- ),
241
- /* @__PURE__ */ jsx(
242
- Form.Field,
243
- {
244
- control: form.control,
245
- name: "currency_code",
246
- render: ({ field: { onChange, ref, ...field } }) => {
247
- return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "region-create-form-currency-item", children: [
248
- /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-currency-label", children: t("fields.currency") }),
249
- /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-currency-control", children: /* @__PURE__ */ jsxs(
250
- Select,
251
- {
252
- dir: direction,
253
- ...field,
254
- onValueChange: onChange,
255
- "data-testid": "region-create-form-currency-select",
256
- children: [
257
- /* @__PURE__ */ jsx(Select.Trigger, { ref, "data-testid": "region-create-form-currency-select-trigger", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
258
- /* @__PURE__ */ jsx(Select.Content, { "data-testid": "region-create-form-currency-select-content", children: currencies2.map((currency) => /* @__PURE__ */ jsx(
259
- Select.Item,
260
- {
261
- value: currency.code,
262
- "data-testid": `region-create-form-currency-select-option-${currency.code}`,
263
- children: currency.name
264
- },
265
- currency.code
266
- )) })
267
- ]
268
- }
269
- ) }),
270
- /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-currency-error" })
271
- ] });
272
- }
273
- }
274
- )
275
- ] }) }),
276
- /* @__PURE__ */ jsx(
277
- Form.Field,
278
- {
279
- control: form.control,
280
- name: "automatic_taxes",
281
- render: ({ field: { value, onChange, ...field } }) => {
282
- return /* @__PURE__ */ jsx(Form.Item, { "data-testid": "region-create-form-automatic-taxes-item", children: /* @__PURE__ */ jsxs("div", { children: [
283
- /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between", children: [
284
- /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-automatic-taxes-label", children: t("fields.automaticTaxes") }),
285
- /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-automatic-taxes-control", children: /* @__PURE__ */ jsx(
286
- Switch,
287
- {
288
- dir: "ltr",
289
- className: "rtl:rotate-180",
290
- ...field,
291
- checked: value,
292
- onCheckedChange: onChange,
293
- "data-testid": "region-create-form-automatic-taxes-switch"
294
- }
295
- ) })
296
- ] }),
297
- /* @__PURE__ */ jsx(Form.Hint, { "data-testid": "region-create-form-automatic-taxes-hint", children: t("regions.automaticTaxesHint") }),
298
- /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-automatic-taxes-error" })
299
- ] }) });
300
- }
301
- }
302
- ),
303
- /* @__PURE__ */ jsx(
304
- Form.Field,
305
- {
306
- control: form.control,
307
- name: "is_tax_inclusive",
308
- render: ({ field: { value, onChange, ...field } }) => {
309
- return /* @__PURE__ */ jsx(Form.Item, { "data-testid": "region-create-form-tax-inclusive-item", children: /* @__PURE__ */ jsxs("div", { children: [
310
- /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between", children: [
311
- /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-tax-inclusive-label", children: t("fields.taxInclusivePricing") }),
312
- /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-tax-inclusive-control", children: /* @__PURE__ */ jsx(
313
- Switch,
314
- {
315
- className: "rtl:rotate-180",
316
- dir: "ltr",
317
- ...field,
318
- checked: value,
319
- onCheckedChange: onChange,
320
- "data-testid": "region-create-form-tax-inclusive-switch"
321
- }
322
- ) })
323
- ] }),
324
- /* @__PURE__ */ jsx(Form.Hint, { "data-testid": "region-create-form-tax-inclusive-hint", children: t("regions.taxInclusiveHint") }),
325
- /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-tax-inclusive-error" })
326
- ] }) });
327
- }
328
- }
329
- ),
330
- /* @__PURE__ */ jsx("div", { className: "bg-ui-border-base h-px w-full" }),
331
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", "data-testid": "region-create-form-countries-section", children: [
332
- /* @__PURE__ */ jsxs("div", { "data-testid": "region-create-form-countries-header", children: [
333
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", "data-testid": "region-create-form-countries-label", children: t("fields.countries") }),
334
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "region-create-form-countries-hint", children: t("regions.countriesHint") })
335
- ] }),
336
- selectedCountries.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", "data-testid": "region-create-form-countries-selected", children: [
337
- selectedCountries.map((country) => /* @__PURE__ */ jsx(
338
- CountryTag,
339
- {
340
- country,
341
- onRemove: removeCountry
342
- },
343
- country.code
344
- )),
345
- /* @__PURE__ */ jsx(
346
- Button,
347
- {
348
- variant: "transparent",
349
- size: "small",
350
- className: "text-ui-fg-muted hover:text-ui-fg-subtle",
351
- onClick: clearCountries,
352
- "data-testid": "region-create-form-countries-clear-all-button",
353
- children: t("actions.clearAll")
354
- }
355
- )
356
- ] }),
357
- /* @__PURE__ */ jsxs(StackedFocusModal, { id: STACKED_MODAL_ID, "data-testid": "region-create-form-countries-modal", children: [
358
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", "data-testid": "region-create-form-countries-add-button", children: t("regions.addCountries") }) }) }),
359
- /* @__PURE__ */ jsx(StackedFocusModal.Content, { "data-testid": "region-create-form-countries-modal-content", children: /* @__PURE__ */ jsxs("div", { className: "flex size-full flex-col overflow-hidden", children: [
360
- /* @__PURE__ */ jsx(StackedFocusModal.Header, { "data-testid": "region-create-form-countries-modal-header", children: /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: t("regions.addCountries") }) }) }),
361
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "overflow-hidden", "data-testid": "region-create-form-countries-modal-body", children: /* @__PURE__ */ jsx(
362
- _DataTable,
363
- {
364
- table,
365
- columns,
366
- count,
367
- pageSize: PAGE_SIZE,
368
- orderBy: [
369
- { key: "display_name", label: t("fields.name") },
370
- { key: "iso_2", label: t("fields.code") }
371
- ],
372
- pagination: true,
373
- search: "autofocus",
374
- layout: "fill",
375
- queryObject: raw,
376
- prefix: PREFIX,
377
- "data-testid": "region-create-form-countries-modal-table"
378
- }
379
- ) }),
380
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { "data-testid": "region-create-form-countries-modal-footer", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
381
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", "data-testid": "region-create-form-countries-modal-cancel-button", children: t("actions.cancel") }) }),
382
- /* @__PURE__ */ jsx(
383
- Button,
384
- {
385
- size: "small",
386
- type: "button",
387
- onClick: saveCountries,
388
- "data-testid": "region-create-form-countries-modal-save-button",
389
- children: t("actions.save")
390
- }
391
- )
392
- ] }) })
393
- ] }) })
394
- ] })
395
- ] }),
396
- /* @__PURE__ */ jsx("div", { className: "bg-ui-border-base h-px w-full" }),
397
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", "data-testid": "region-create-form-payment-providers-section", children: [
398
- /* @__PURE__ */ jsxs("div", { "data-testid": "region-create-form-payment-providers-header", children: [
399
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", "data-testid": "region-create-form-payment-providers-label", children: t("fields.providers") }),
400
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "region-create-form-payment-providers-hint", children: t("regions.providersHint") })
401
- ] }),
402
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: /* @__PURE__ */ jsx(
403
- Form.Field,
404
- {
405
- control: form.control,
406
- name: "payment_providers",
407
- render: ({ field }) => {
408
- return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "region-create-form-payment-providers-item", children: [
409
- /* @__PURE__ */ jsx(Form.Label, { "data-testid": "region-create-form-payment-providers-item-label", children: t("fields.paymentProviders") }),
410
- /* @__PURE__ */ jsx(Form.Control, { "data-testid": "region-create-form-payment-providers-item-control", children: /* @__PURE__ */ jsx(
411
- Combobox,
412
- {
413
- forceHideInput: true,
414
- options: comboboxProviders.options,
415
- fetchNextPage: comboboxProviders.fetchNextPage,
416
- ...field,
417
- "data-testid": "region-create-form-payment-providers-combobox"
418
- }
419
- ) }),
420
- /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "region-create-form-payment-providers-item-error" })
421
- ] });
422
- }
423
- }
424
- ) })
425
- ] })
426
- ] })
427
- }
428
- ) }),
429
- /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { "data-testid": "region-create-form-footer", children: [
430
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", "data-testid": "region-create-form-cancel-button", children: t("actions.cancel") }) }),
431
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPendingRegion, "data-testid": "region-create-form-save-button", children: t("actions.save") })
432
- ] })
433
- ]
434
- }
435
- ) });
436
- };
437
- var columnHelper = createColumnHelper();
438
- var useColumns = () => {
439
- const base = useCountryTableColumns();
440
- return useMemo(
441
- () => [
442
- columnHelper.display({
443
- id: "select",
444
- header: ({ table }) => {
445
- return /* @__PURE__ */ jsx(
446
- Checkbox,
447
- {
448
- checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
449
- onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value),
450
- "data-testid": "region-create-form-countries-modal-select-all-checkbox"
451
- }
452
- );
453
- },
454
- cell: ({ row }) => {
455
- const isPreselected = !row.getCanSelect();
456
- return /* @__PURE__ */ jsx(
457
- Checkbox,
458
- {
459
- checked: row.getIsSelected() || isPreselected,
460
- disabled: isPreselected,
461
- onCheckedChange: (value) => row.toggleSelected(!!value),
462
- onClick: (e) => {
463
- e.stopPropagation();
464
- },
465
- "data-testid": `region-create-form-countries-modal-select-checkbox-${row.original.iso_2}`
466
- }
467
- );
468
- }
469
- }),
470
- ...base
471
- ],
472
- [base]
473
- );
474
- };
475
- var CountryTag = ({
476
- country,
477
- onRemove
478
- }) => {
479
- return /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-field shadow-borders-base transition-fg hover:bg-ui-bg-field-hover flex h-7 items-center overflow-hidden rounded-md", "data-testid": `region-create-form-country-tag-${country.code}`, children: [
480
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus flex h-full select-none items-center justify-center px-2 py-0.5", "data-testid": `region-create-form-country-tag-${country.code}-name`, children: country.name }),
481
- /* @__PURE__ */ jsx(
482
- "button",
483
- {
484
- type: "button",
485
- onClick: () => onRemove(country.code),
486
- className: "focus-visible:bg-ui-bg-field-hover transition-fg hover:bg-ui-bg-field-hover flex h-full w-7 items-center justify-center border-l outline-none",
487
- "data-testid": `region-create-form-country-tag-${country.code}-remove-button`,
488
- children: /* @__PURE__ */ jsx(XMarkMini, { className: "text-ui-fg-muted" })
489
- }
490
- )
491
- ] });
492
- };
493
-
494
- // src/pages/regions/region-create/region-create.tsx
495
- import { jsx as jsx2 } from "react/jsx-runtime";
496
- var RegionCreate = () => {
497
- const { store, isPending: isLoading, isError, error } = useStore();
498
- const storeCurrencies = (store?.supported_currencies ?? []).map(
499
- (c) => currencies[c.currency_code.toUpperCase()]
500
- );
501
- if (isError) {
502
- throw error;
503
- }
504
- return /* @__PURE__ */ jsx2(RouteFocusModal, { "data-testid": "region-create-modal", children: !isLoading && store && /* @__PURE__ */ jsx2(CreateRegionForm, { currencies: storeCurrencies }) });
505
- };
506
- export {
507
- RegionCreate as Component
508
- };