@medusajs/draft-order 2.11.4-preview-20251107032027 → 2.11.4-preview-20251107060138

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