@medusajs/draft-order 2.11.3-preview-20251103120146 → 2.12.0-preview-20251103150145

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.
@@ -11452,6 +11452,315 @@ function getPromotionIds(items, shippingMethods) {
11452
11452
  }
11453
11453
  return Array.from(promotionIds);
11454
11454
  }
11455
+ const SalesChannel = () => {
11456
+ const { id } = reactRouterDom.useParams();
11457
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11458
+ id,
11459
+ {
11460
+ fields: "+sales_channel_id"
11461
+ },
11462
+ {
11463
+ enabled: !!id
11464
+ }
11465
+ );
11466
+ if (isError) {
11467
+ throw error;
11468
+ }
11469
+ const ISrEADY = !!draft_order && !isPending;
11470
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11471
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11474
+ ] }),
11475
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11476
+ ] });
11477
+ };
11478
+ const SalesChannelForm = ({ order }) => {
11479
+ const form = reactHookForm.useForm({
11480
+ defaultValues: {
11481
+ sales_channel_id: order.sales_channel_id || ""
11482
+ },
11483
+ resolver: zod.zodResolver(schema$2)
11484
+ });
11485
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
+ const { handleSuccess } = useRouteModal();
11487
+ const onSubmit = form.handleSubmit(async (data) => {
11488
+ await mutateAsync(
11489
+ {
11490
+ sales_channel_id: data.sales_channel_id
11491
+ },
11492
+ {
11493
+ onSuccess: () => {
11494
+ ui.toast.success("Sales channel updated");
11495
+ handleSuccess();
11496
+ },
11497
+ onError: (error) => {
11498
+ ui.toast.error(error.message);
11499
+ }
11500
+ }
11501
+ );
11502
+ });
11503
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11504
+ KeyboundForm,
11505
+ {
11506
+ className: "flex flex-1 flex-col overflow-hidden",
11507
+ onSubmit,
11508
+ children: [
11509
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11511
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11512
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11513
+ ] }) })
11514
+ ]
11515
+ }
11516
+ ) });
11517
+ };
11518
+ const SalesChannelField = ({ control, order }) => {
11519
+ const salesChannels = useComboboxData({
11520
+ queryFn: async (params) => {
11521
+ return await sdk.admin.salesChannel.list(params);
11522
+ },
11523
+ queryKey: ["sales-channels"],
11524
+ getOptions: (data) => {
11525
+ return data.sales_channels.map((salesChannel) => ({
11526
+ label: salesChannel.name,
11527
+ value: salesChannel.id
11528
+ }));
11529
+ },
11530
+ defaultValue: order.sales_channel_id || void 0
11531
+ });
11532
+ return /* @__PURE__ */ jsxRuntime.jsx(
11533
+ Form$2.Field,
11534
+ {
11535
+ control,
11536
+ name: "sales_channel_id",
11537
+ render: ({ field }) => {
11538
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11539
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11541
+ Combobox,
11542
+ {
11543
+ options: salesChannels.options,
11544
+ fetchNextPage: salesChannels.fetchNextPage,
11545
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11546
+ searchValue: salesChannels.searchValue,
11547
+ onSearchValueChange: salesChannels.onSearchValueChange,
11548
+ placeholder: "Select sales channel",
11549
+ ...field
11550
+ }
11551
+ ) }),
11552
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11553
+ ] });
11554
+ }
11555
+ }
11556
+ );
11557
+ };
11558
+ const schema$2 = objectType({
11559
+ sales_channel_id: stringType().min(1)
11560
+ });
11561
+ const ShippingAddress = () => {
11562
+ const { id } = reactRouterDom.useParams();
11563
+ const { order, isPending, isError, error } = useOrder(id, {
11564
+ fields: "+shipping_address"
11565
+ });
11566
+ if (isError) {
11567
+ throw error;
11568
+ }
11569
+ const isReady = !isPending && !!order;
11570
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11571
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11572
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11573
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11574
+ ] }),
11575
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11576
+ ] });
11577
+ };
11578
+ const ShippingAddressForm = ({ order }) => {
11579
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11580
+ const form = reactHookForm.useForm({
11581
+ defaultValues: {
11582
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11583
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11584
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11585
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11586
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11587
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11588
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11589
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11590
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11591
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11592
+ },
11593
+ resolver: zod.zodResolver(schema$1)
11594
+ });
11595
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11596
+ const { handleSuccess } = useRouteModal();
11597
+ const onSubmit = form.handleSubmit(async (data) => {
11598
+ await mutateAsync(
11599
+ {
11600
+ shipping_address: {
11601
+ first_name: data.first_name,
11602
+ last_name: data.last_name,
11603
+ company: data.company,
11604
+ address_1: data.address_1,
11605
+ address_2: data.address_2,
11606
+ city: data.city,
11607
+ province: data.province,
11608
+ country_code: data.country_code,
11609
+ postal_code: data.postal_code,
11610
+ phone: data.phone
11611
+ }
11612
+ },
11613
+ {
11614
+ onSuccess: () => {
11615
+ handleSuccess();
11616
+ },
11617
+ onError: (error) => {
11618
+ ui.toast.error(error.message);
11619
+ }
11620
+ }
11621
+ );
11622
+ });
11623
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11624
+ KeyboundForm,
11625
+ {
11626
+ className: "flex flex-1 flex-col overflow-hidden",
11627
+ onSubmit,
11628
+ children: [
11629
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11630
+ /* @__PURE__ */ jsxRuntime.jsx(
11631
+ Form$2.Field,
11632
+ {
11633
+ control: form.control,
11634
+ name: "country_code",
11635
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11636
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11639
+ ] })
11640
+ }
11641
+ ),
11642
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11643
+ /* @__PURE__ */ jsxRuntime.jsx(
11644
+ Form$2.Field,
11645
+ {
11646
+ control: form.control,
11647
+ name: "first_name",
11648
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11652
+ ] })
11653
+ }
11654
+ ),
11655
+ /* @__PURE__ */ jsxRuntime.jsx(
11656
+ Form$2.Field,
11657
+ {
11658
+ control: form.control,
11659
+ name: "last_name",
11660
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11664
+ ] })
11665
+ }
11666
+ )
11667
+ ] }),
11668
+ /* @__PURE__ */ jsxRuntime.jsx(
11669
+ Form$2.Field,
11670
+ {
11671
+ control: form.control,
11672
+ name: "company",
11673
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11674
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11677
+ ] })
11678
+ }
11679
+ ),
11680
+ /* @__PURE__ */ jsxRuntime.jsx(
11681
+ Form$2.Field,
11682
+ {
11683
+ control: form.control,
11684
+ name: "address_1",
11685
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11686
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11689
+ ] })
11690
+ }
11691
+ ),
11692
+ /* @__PURE__ */ jsxRuntime.jsx(
11693
+ Form$2.Field,
11694
+ {
11695
+ control: form.control,
11696
+ name: "address_2",
11697
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11701
+ ] })
11702
+ }
11703
+ ),
11704
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11705
+ /* @__PURE__ */ jsxRuntime.jsx(
11706
+ Form$2.Field,
11707
+ {
11708
+ control: form.control,
11709
+ name: "postal_code",
11710
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11711
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11714
+ ] })
11715
+ }
11716
+ ),
11717
+ /* @__PURE__ */ jsxRuntime.jsx(
11718
+ Form$2.Field,
11719
+ {
11720
+ control: form.control,
11721
+ name: "city",
11722
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11723
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11726
+ ] })
11727
+ }
11728
+ )
11729
+ ] }),
11730
+ /* @__PURE__ */ jsxRuntime.jsx(
11731
+ Form$2.Field,
11732
+ {
11733
+ control: form.control,
11734
+ name: "province",
11735
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11736
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11739
+ ] })
11740
+ }
11741
+ ),
11742
+ /* @__PURE__ */ jsxRuntime.jsx(
11743
+ Form$2.Field,
11744
+ {
11745
+ control: form.control,
11746
+ name: "phone",
11747
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11748
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11751
+ ] })
11752
+ }
11753
+ )
11754
+ ] }) }),
11755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11756
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11757
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11758
+ ] }) })
11759
+ ]
11760
+ }
11761
+ ) });
11762
+ };
11763
+ const schema$1 = addressSchema;
11455
11764
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11456
11765
  const Shipping = () => {
11457
11766
  var _a;
@@ -12202,266 +12511,63 @@ const ShippingOptionField = ({
12202
12511
  render: ({ field }) => {
12203
12512
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12204
12513
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12205
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12206
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12207
- ] }),
12208
- /* @__PURE__ */ jsxRuntime.jsx(
12209
- ConditionalTooltip,
12210
- {
12211
- content: tooltipContent,
12212
- showTooltip: !locationId || !shippingProfileId,
12213
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12214
- Combobox,
12215
- {
12216
- options: shippingOptions.options,
12217
- fetchNextPage: shippingOptions.fetchNextPage,
12218
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12219
- searchValue: shippingOptions.searchValue,
12220
- onSearchValueChange: shippingOptions.onSearchValueChange,
12221
- placeholder: "Select shipping option",
12222
- ...field,
12223
- disabled: !locationId || !shippingProfileId
12224
- }
12225
- ) }) })
12226
- }
12227
- )
12228
- ] }) });
12229
- }
12230
- }
12231
- );
12232
- };
12233
- const CustomAmountField = ({
12234
- control,
12235
- currencyCode
12236
- }) => {
12237
- return /* @__PURE__ */ jsxRuntime.jsx(
12238
- Form$2.Field,
12239
- {
12240
- control,
12241
- name: "custom_amount",
12242
- render: ({ field: { onChange, ...field } }) => {
12243
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12244
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12245
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12246
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12247
- ] }),
12248
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12249
- ui.CurrencyInput,
12250
- {
12251
- ...field,
12252
- onValueChange: (value) => onChange(value),
12253
- symbol: getNativeSymbol(currencyCode),
12254
- code: currencyCode
12255
- }
12256
- ) })
12257
- ] });
12258
- }
12259
- }
12260
- );
12261
- };
12262
- const ShippingAddress = () => {
12263
- const { id } = reactRouterDom.useParams();
12264
- const { order, isPending, isError, error } = useOrder(id, {
12265
- fields: "+shipping_address"
12266
- });
12267
- if (isError) {
12268
- throw error;
12269
- }
12270
- const isReady = !isPending && !!order;
12271
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12272
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12273
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12274
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12275
- ] }),
12276
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12277
- ] });
12278
- };
12279
- const ShippingAddressForm = ({ order }) => {
12280
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12281
- const form = reactHookForm.useForm({
12282
- defaultValues: {
12283
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12284
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12285
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12286
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12287
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12288
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12289
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12290
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12291
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12292
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12293
- },
12294
- resolver: zod.zodResolver(schema$2)
12295
- });
12296
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12297
- const { handleSuccess } = useRouteModal();
12298
- const onSubmit = form.handleSubmit(async (data) => {
12299
- await mutateAsync(
12300
- {
12301
- shipping_address: {
12302
- first_name: data.first_name,
12303
- last_name: data.last_name,
12304
- company: data.company,
12305
- address_1: data.address_1,
12306
- address_2: data.address_2,
12307
- city: data.city,
12308
- province: data.province,
12309
- country_code: data.country_code,
12310
- postal_code: data.postal_code,
12311
- phone: data.phone
12312
- }
12313
- },
12314
- {
12315
- onSuccess: () => {
12316
- handleSuccess();
12317
- },
12318
- onError: (error) => {
12319
- ui.toast.error(error.message);
12320
- }
12321
- }
12322
- );
12323
- });
12324
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12325
- KeyboundForm,
12326
- {
12327
- className: "flex flex-1 flex-col overflow-hidden",
12328
- onSubmit,
12329
- children: [
12330
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12331
- /* @__PURE__ */ jsxRuntime.jsx(
12332
- Form$2.Field,
12333
- {
12334
- control: form.control,
12335
- name: "country_code",
12336
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12337
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12338
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12340
- ] })
12341
- }
12342
- ),
12343
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12344
- /* @__PURE__ */ jsxRuntime.jsx(
12345
- Form$2.Field,
12346
- {
12347
- control: form.control,
12348
- name: "first_name",
12349
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12353
- ] })
12354
- }
12355
- ),
12356
- /* @__PURE__ */ jsxRuntime.jsx(
12357
- Form$2.Field,
12358
- {
12359
- control: form.control,
12360
- name: "last_name",
12361
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12362
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12365
- ] })
12366
- }
12367
- )
12514
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12515
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12368
12516
  ] }),
12369
12517
  /* @__PURE__ */ jsxRuntime.jsx(
12370
- Form$2.Field,
12371
- {
12372
- control: form.control,
12373
- name: "company",
12374
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12375
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12376
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12378
- ] })
12379
- }
12380
- ),
12381
- /* @__PURE__ */ jsxRuntime.jsx(
12382
- Form$2.Field,
12383
- {
12384
- control: form.control,
12385
- name: "address_1",
12386
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12387
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12388
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12389
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12390
- ] })
12391
- }
12392
- ),
12393
- /* @__PURE__ */ jsxRuntime.jsx(
12394
- Form$2.Field,
12518
+ ConditionalTooltip,
12395
12519
  {
12396
- control: form.control,
12397
- name: "address_2",
12398
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12399
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12400
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12401
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12402
- ] })
12520
+ content: tooltipContent,
12521
+ showTooltip: !locationId || !shippingProfileId,
12522
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12523
+ Combobox,
12524
+ {
12525
+ options: shippingOptions.options,
12526
+ fetchNextPage: shippingOptions.fetchNextPage,
12527
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12528
+ searchValue: shippingOptions.searchValue,
12529
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12530
+ placeholder: "Select shipping option",
12531
+ ...field,
12532
+ disabled: !locationId || !shippingProfileId
12533
+ }
12534
+ ) }) })
12403
12535
  }
12404
- ),
12405
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12406
- /* @__PURE__ */ jsxRuntime.jsx(
12407
- Form$2.Field,
12408
- {
12409
- control: form.control,
12410
- name: "postal_code",
12411
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12412
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12413
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12414
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12415
- ] })
12416
- }
12417
- ),
12418
- /* @__PURE__ */ jsxRuntime.jsx(
12419
- Form$2.Field,
12420
- {
12421
- control: form.control,
12422
- name: "city",
12423
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12424
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12425
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12426
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12427
- ] })
12428
- }
12429
- )
12536
+ )
12537
+ ] }) });
12538
+ }
12539
+ }
12540
+ );
12541
+ };
12542
+ const CustomAmountField = ({
12543
+ control,
12544
+ currencyCode
12545
+ }) => {
12546
+ return /* @__PURE__ */ jsxRuntime.jsx(
12547
+ Form$2.Field,
12548
+ {
12549
+ control,
12550
+ name: "custom_amount",
12551
+ render: ({ field: { onChange, ...field } }) => {
12552
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12553
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12430
12556
  ] }),
12431
- /* @__PURE__ */ jsxRuntime.jsx(
12432
- Form$2.Field,
12433
- {
12434
- control: form.control,
12435
- name: "province",
12436
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12437
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12438
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12440
- ] })
12441
- }
12442
- ),
12443
- /* @__PURE__ */ jsxRuntime.jsx(
12444
- Form$2.Field,
12557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12558
+ ui.CurrencyInput,
12445
12559
  {
12446
- control: form.control,
12447
- name: "phone",
12448
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12451
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12452
- ] })
12560
+ ...field,
12561
+ onValueChange: (value) => onChange(value),
12562
+ symbol: getNativeSymbol(currencyCode),
12563
+ code: currencyCode
12453
12564
  }
12454
- )
12455
- ] }) }),
12456
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12457
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12458
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12459
- ] }) })
12460
- ]
12565
+ ) })
12566
+ ] });
12567
+ }
12461
12568
  }
12462
- ) });
12569
+ );
12463
12570
  };
12464
- const schema$2 = addressSchema;
12465
12571
  const TransferOwnership = () => {
12466
12572
  const { id } = reactRouterDom.useParams();
12467
12573
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12485,7 +12591,7 @@ const TransferOwnershipForm = ({ order }) => {
12485
12591
  defaultValues: {
12486
12592
  customer_id: order.customer_id || ""
12487
12593
  },
12488
- resolver: zod.zodResolver(schema$1)
12594
+ resolver: zod.zodResolver(schema)
12489
12595
  });
12490
12596
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12491
12597
  const { handleSuccess } = useRouteModal();
@@ -12935,114 +13041,8 @@ const Illustration = () => {
12935
13041
  }
12936
13042
  );
12937
13043
  };
12938
- const schema$1 = objectType({
12939
- customer_id: stringType().min(1)
12940
- });
12941
- const SalesChannel = () => {
12942
- const { id } = reactRouterDom.useParams();
12943
- const { draft_order, isPending, isError, error } = useDraftOrder(
12944
- id,
12945
- {
12946
- fields: "+sales_channel_id"
12947
- },
12948
- {
12949
- enabled: !!id
12950
- }
12951
- );
12952
- if (isError) {
12953
- throw error;
12954
- }
12955
- const ISrEADY = !!draft_order && !isPending;
12956
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12957
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12958
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12960
- ] }),
12961
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12962
- ] });
12963
- };
12964
- const SalesChannelForm = ({ order }) => {
12965
- const form = reactHookForm.useForm({
12966
- defaultValues: {
12967
- sales_channel_id: order.sales_channel_id || ""
12968
- },
12969
- resolver: zod.zodResolver(schema)
12970
- });
12971
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12972
- const { handleSuccess } = useRouteModal();
12973
- const onSubmit = form.handleSubmit(async (data) => {
12974
- await mutateAsync(
12975
- {
12976
- sales_channel_id: data.sales_channel_id
12977
- },
12978
- {
12979
- onSuccess: () => {
12980
- ui.toast.success("Sales channel updated");
12981
- handleSuccess();
12982
- },
12983
- onError: (error) => {
12984
- ui.toast.error(error.message);
12985
- }
12986
- }
12987
- );
12988
- });
12989
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12990
- KeyboundForm,
12991
- {
12992
- className: "flex flex-1 flex-col overflow-hidden",
12993
- onSubmit,
12994
- children: [
12995
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12996
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12997
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12998
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12999
- ] }) })
13000
- ]
13001
- }
13002
- ) });
13003
- };
13004
- const SalesChannelField = ({ control, order }) => {
13005
- const salesChannels = useComboboxData({
13006
- queryFn: async (params) => {
13007
- return await sdk.admin.salesChannel.list(params);
13008
- },
13009
- queryKey: ["sales-channels"],
13010
- getOptions: (data) => {
13011
- return data.sales_channels.map((salesChannel) => ({
13012
- label: salesChannel.name,
13013
- value: salesChannel.id
13014
- }));
13015
- },
13016
- defaultValue: order.sales_channel_id || void 0
13017
- });
13018
- return /* @__PURE__ */ jsxRuntime.jsx(
13019
- Form$2.Field,
13020
- {
13021
- control,
13022
- name: "sales_channel_id",
13023
- render: ({ field }) => {
13024
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13027
- Combobox,
13028
- {
13029
- options: salesChannels.options,
13030
- fetchNextPage: salesChannels.fetchNextPage,
13031
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13032
- searchValue: salesChannels.searchValue,
13033
- onSearchValueChange: salesChannels.onSearchValueChange,
13034
- placeholder: "Select sales channel",
13035
- ...field
13036
- }
13037
- ) }),
13038
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13039
- ] });
13040
- }
13041
- }
13042
- );
13043
- };
13044
13044
  const schema = objectType({
13045
- sales_channel_id: stringType().min(1)
13045
+ customer_id: stringType().min(1)
13046
13046
  });
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
@@ -13089,20 +13089,20 @@ const routeModule = {
13089
13089
  path: "/draft-orders/:id/promotions"
13090
13090
  },
13091
13091
  {
13092
- Component: Shipping,
13093
- path: "/draft-orders/:id/shipping"
13092
+ Component: SalesChannel,
13093
+ path: "/draft-orders/:id/sales-channel"
13094
13094
  },
13095
13095
  {
13096
13096
  Component: ShippingAddress,
13097
13097
  path: "/draft-orders/:id/shipping-address"
13098
13098
  },
13099
13099
  {
13100
- Component: TransferOwnership,
13101
- path: "/draft-orders/:id/transfer-ownership"
13100
+ Component: Shipping,
13101
+ path: "/draft-orders/:id/shipping"
13102
13102
  },
13103
13103
  {
13104
- Component: SalesChannel,
13105
- path: "/draft-orders/:id/sales-channel"
13104
+ Component: TransferOwnership,
13105
+ path: "/draft-orders/:id/transfer-ownership"
13106
13106
  }
13107
13107
  ]
13108
13108
  }