@medusajs/draft-order 2.11.3-preview-20251103120146 → 2.11.3-snapshot-20251103115905

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.
@@ -4654,9 +4654,6 @@ ZodReadonly.create = (type, params) => {
4654
4654
  ...processCreateParams(params)
4655
4655
  });
4656
4656
  };
4657
- ({
4658
- object: ZodObject.lazycreate
4659
- });
4660
4657
  var ZodFirstPartyTypeKind;
4661
4658
  (function(ZodFirstPartyTypeKind2) {
4662
4659
  ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
@@ -4703,7 +4700,6 @@ const anyType = ZodAny.create;
4703
4700
  ZodNever.create;
4704
4701
  const arrayType = ZodArray.create;
4705
4702
  const objectType = ZodObject.create;
4706
- ZodObject.strictCreate;
4707
4703
  const unionType = ZodUnion.create;
4708
4704
  ZodIntersection.create;
4709
4705
  ZodTuple.create;
@@ -9762,27 +9758,6 @@ const BillingAddressForm = ({ order }) => {
9762
9758
  ) });
9763
9759
  };
9764
9760
  const schema$5 = addressSchema;
9765
- const CustomItems = () => {
9766
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9768
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9769
- ] });
9770
- };
9771
- const CustomItemsForm = () => {
9772
- const form = reactHookForm.useForm({
9773
- resolver: zod.zodResolver(schema$4)
9774
- });
9775
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9778
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9779
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9780
- ] }) })
9781
- ] }) });
9782
- };
9783
- const schema$4 = objectType({
9784
- email: stringType().email()
9785
- });
9786
9761
  const Email = () => {
9787
9762
  const { id } = reactRouterDom.useParams();
9788
9763
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9805,7 +9780,7 @@ const EmailForm = ({ order }) => {
9805
9780
  defaultValues: {
9806
9781
  email: order.email ?? ""
9807
9782
  },
9808
- resolver: zod.zodResolver(schema$3)
9783
+ resolver: zod.zodResolver(schema$4)
9809
9784
  });
9810
9785
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9811
9786
  const { handleSuccess } = useRouteModal();
@@ -9848,6 +9823,27 @@ const EmailForm = ({ order }) => {
9848
9823
  }
9849
9824
  ) });
9850
9825
  };
9826
+ const schema$4 = objectType({
9827
+ email: stringType().email()
9828
+ });
9829
+ const CustomItems = () => {
9830
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9831
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9832
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9833
+ ] });
9834
+ };
9835
+ const CustomItemsForm = () => {
9836
+ const form = reactHookForm.useForm({
9837
+ resolver: zod.zodResolver(schema$3)
9838
+ });
9839
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9840
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9841
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9842
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9843
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9844
+ ] }) })
9845
+ ] }) });
9846
+ };
9851
9847
  const schema$3 = objectType({
9852
9848
  email: stringType().email()
9853
9849
  });
@@ -11452,1016 +11448,1122 @@ function getPromotionIds(items, shippingMethods) {
11452
11448
  }
11453
11449
  return Array.from(promotionIds);
11454
11450
  }
11455
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11456
- const Shipping = () => {
11457
- var _a;
11451
+ const SalesChannel = () => {
11458
11452
  const { id } = reactRouterDom.useParams();
11459
- const { order, isPending, isError, error } = useOrder(id, {
11460
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11461
- });
11462
- const {
11463
- order: preview,
11464
- isPending: isPreviewPending,
11465
- isError: isPreviewError,
11466
- error: previewError
11467
- } = useOrderPreview(id);
11468
- useInitiateOrderEdit({ preview });
11469
- const { onCancel } = useCancelOrderEdit({ preview });
11470
- if (isError) {
11471
- throw error;
11472
- }
11473
- if (isPreviewError) {
11474
- throw previewError;
11475
- }
11476
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11477
- const isReady = preview && !isPreviewPending && order && !isPending;
11478
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11479
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11480
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11481
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11482
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11483
- ] }) }) }),
11484
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11485
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11486
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11487
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11488
- ] }) });
11489
- };
11490
- const ShippingForm = ({ preview, order }) => {
11491
- var _a;
11492
- const { setIsOpen } = useStackedModal();
11493
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11494
- const [data, setData] = React.useState(null);
11495
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11496
- const { shipping_options } = useShippingOptions(
11453
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11454
+ id,
11497
11455
  {
11498
- id: appliedShippingOptionIds,
11499
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11456
+ fields: "+sales_channel_id"
11500
11457
  },
11501
11458
  {
11502
- enabled: appliedShippingOptionIds.length > 0
11459
+ enabled: !!id
11503
11460
  }
11504
11461
  );
11505
- const uniqueShippingProfiles = React.useMemo(() => {
11506
- const profiles = /* @__PURE__ */ new Map();
11507
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11508
- profiles.set(profile.id, profile);
11509
- });
11510
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11511
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11512
- });
11513
- return Array.from(profiles.values());
11514
- }, [order.items, shipping_options]);
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);
11515
11482
  const { handleSuccess } = useRouteModal();
11516
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11517
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11518
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11519
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11520
- const onSubmit = async () => {
11521
- setIsSubmitting(true);
11522
- let requestSucceeded = false;
11523
- await requestOrderEdit(void 0, {
11524
- onError: (e) => {
11525
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11526
- },
11527
- onSuccess: () => {
11528
- requestSucceeded = true;
11529
- }
11530
- });
11531
- if (!requestSucceeded) {
11532
- setIsSubmitting(false);
11533
- return;
11534
- }
11535
- await confirmOrderEdit(void 0, {
11536
- onError: (e) => {
11537
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11538
- },
11539
- onSuccess: () => {
11540
- handleSuccess();
11483
+ const onSubmit = form.handleSubmit(async (data) => {
11484
+ await mutateAsync(
11485
+ {
11486
+ sales_channel_id: data.sales_channel_id
11541
11487
  },
11542
- onSettled: () => {
11543
- setIsSubmitting(false);
11544
- }
11545
- });
11546
- };
11547
- const onKeydown = React.useCallback(
11548
- (e) => {
11549
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11550
- if (data || isSubmitting) {
11551
- return;
11488
+ {
11489
+ onSuccess: () => {
11490
+ ui.toast.success("Sales channel updated");
11491
+ handleSuccess();
11492
+ },
11493
+ onError: (error) => {
11494
+ ui.toast.error(error.message);
11552
11495
  }
11553
- onSubmit();
11554
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);
11555
11518
  },
11556
- [data, isSubmitting, onSubmit]
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
+ }
11557
11552
  );
11558
- React.useEffect(() => {
11559
- document.addEventListener("keydown", onKeydown);
11560
- return () => {
11561
- document.removeEventListener("keydown", onKeydown);
11562
- };
11563
- }, [onKeydown]);
11564
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11565
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11566
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11567
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11568
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11569
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11570
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11571
- ] }),
11572
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11573
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11574
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11575
- /* @__PURE__ */ jsxRuntime.jsx(
11576
- ui.Text,
11577
- {
11578
- size: "xsmall",
11579
- weight: "plus",
11580
- className: "text-ui-fg-muted",
11581
- children: "Shipping profile"
11582
- }
11583
- ),
11584
- /* @__PURE__ */ jsxRuntime.jsx(
11585
- ui.Text,
11586
- {
11587
- size: "xsmall",
11588
- weight: "plus",
11589
- className: "text-ui-fg-muted",
11590
- children: "Action"
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
+ ] })
11591
11661
  }
11592
11662
  )
11593
11663
  ] }),
11594
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11595
- var _a2, _b, _c, _d, _e, _f, _g;
11596
- const items = getItemsWithShippingProfile(
11597
- profile.id,
11598
- order.items
11599
- );
11600
- const hasItems = items.length > 0;
11601
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11602
- (option) => option.shipping_profile_id === profile.id
11603
- );
11604
- const shippingMethod = preview.shipping_methods.find(
11605
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11606
- );
11607
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11608
- (action) => action.action === "SHIPPING_ADD"
11609
- );
11610
- return /* @__PURE__ */ jsxRuntime.jsxs(
11611
- radixUi.Accordion.Item,
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,
11612
11703
  {
11613
- value: profile.id,
11614
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11615
- children: [
11616
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11617
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11618
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11619
- ui.IconButton,
11620
- {
11621
- size: "2xsmall",
11622
- variant: "transparent",
11623
- className: "group/trigger",
11624
- disabled: !hasItems,
11625
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11626
- }
11627
- ) }),
11628
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11629
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11630
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(
11632
- ui.Text,
11633
- {
11634
- size: "small",
11635
- weight: "plus",
11636
- leading: "compact",
11637
- children: profile.name
11638
- }
11639
- ),
11640
- /* @__PURE__ */ jsxRuntime.jsxs(
11641
- ui.Text,
11642
- {
11643
- size: "small",
11644
- leading: "compact",
11645
- className: "text-ui-fg-subtle",
11646
- children: [
11647
- items.length,
11648
- " ",
11649
- pluralize(items.length, "items", "item")
11650
- ]
11651
- }
11652
- )
11653
- ] })
11654
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11655
- /* @__PURE__ */ jsxRuntime.jsx(
11656
- ui.Tooltip,
11657
- {
11658
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11659
- var _a3, _b2, _c2;
11660
- return /* @__PURE__ */ jsxRuntime.jsx(
11661
- "li",
11662
- {
11663
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11664
- },
11665
- item.id
11666
- );
11667
- }) }),
11668
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11669
- ui.Badge,
11670
- {
11671
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11672
- size: "xsmall",
11673
- children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11675
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11676
- items.reduce(
11677
- (acc, item) => acc + item.quantity,
11678
- 0
11679
- ),
11680
- "x",
11681
- " ",
11682
- pluralize(items.length, "items", "item")
11683
- ] })
11684
- ]
11685
- }
11686
- )
11687
- }
11688
- ),
11689
- /* @__PURE__ */ jsxRuntime.jsx(
11690
- ui.Tooltip,
11691
- {
11692
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11693
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11694
- ui.Badge,
11695
- {
11696
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11697
- size: "xsmall",
11698
- children: [
11699
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11700
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11701
- ]
11702
- }
11703
- )
11704
- }
11705
- ),
11706
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11707
- ui.Badge,
11708
- {
11709
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11710
- size: "xsmall",
11711
- children: [
11712
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11713
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11714
- ]
11715
- }
11716
- ) })
11717
- ] })
11718
- ] }),
11719
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11720
- ActionMenu,
11721
- {
11722
- groups: [
11723
- {
11724
- actions: [
11725
- hasItems ? {
11726
- label: "Edit shipping option",
11727
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11728
- onClick: () => {
11729
- setIsOpen(
11730
- STACKED_FOCUS_MODAL_ID,
11731
- true
11732
- );
11733
- setData({
11734
- shippingProfileId: profile.id,
11735
- shippingOption,
11736
- shippingMethod
11737
- });
11738
- }
11739
- } : void 0,
11740
- {
11741
- label: "Remove shipping option",
11742
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11743
- onClick: () => {
11744
- if (shippingMethod) {
11745
- if (addShippingMethodAction) {
11746
- removeActionShippingMethod(
11747
- addShippingMethodAction.id
11748
- );
11749
- } else {
11750
- removeShippingMethod(
11751
- shippingMethod.id
11752
- );
11753
- }
11754
- }
11755
- }
11756
- }
11757
- ].filter(Boolean)
11758
- }
11759
- ]
11760
- }
11761
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11762
- StackedModalTrigger,
11763
- {
11764
- shippingProfileId: profile.id,
11765
- shippingOption,
11766
- shippingMethod,
11767
- setData,
11768
- children: "Add shipping option"
11769
- }
11770
- )
11771
- ] }),
11772
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11773
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11774
- items.map((item, idx) => {
11775
- var _a3, _b2, _c2, _d2, _e2;
11776
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11777
- /* @__PURE__ */ jsxRuntime.jsxs(
11778
- "div",
11779
- {
11780
- className: "flex items-center gap-x-3 px-3",
11781
- children: [
11782
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11783
- ui.Divider,
11784
- {
11785
- variant: "dashed",
11786
- orientation: "vertical"
11787
- }
11788
- ) }),
11789
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
11790
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11791
- ui.Text,
11792
- {
11793
- size: "small",
11794
- leading: "compact",
11795
- className: "text-ui-fg-subtle",
11796
- children: [
11797
- item.quantity,
11798
- "x"
11799
- ]
11800
- }
11801
- ) }),
11802
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11803
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11804
- /* @__PURE__ */ jsxRuntime.jsxs(
11805
- ui.Text,
11806
- {
11807
- size: "small",
11808
- leading: "compact",
11809
- weight: "plus",
11810
- children: [
11811
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11812
- " (",
11813
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11814
- ")"
11815
- ]
11816
- }
11817
- ),
11818
- /* @__PURE__ */ jsxRuntime.jsx(
11819
- ui.Text,
11820
- {
11821
- size: "small",
11822
- leading: "compact",
11823
- className: "text-ui-fg-subtle",
11824
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11825
- }
11826
- )
11827
- ] })
11828
- ] })
11829
- ]
11830
- },
11831
- item.id
11832
- ),
11833
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11834
- ] }, item.id);
11835
- })
11836
- ] })
11837
- ]
11838
- },
11839
- profile.id
11840
- );
11841
- }) })
11842
- ] }) })
11843
- ] }) }),
11844
- /* @__PURE__ */ jsxRuntime.jsx(
11845
- StackedFocusModal,
11846
- {
11847
- id: STACKED_FOCUS_MODAL_ID,
11848
- onOpenChangeCallback: (open) => {
11849
- if (!open) {
11850
- setData(null);
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
+ ] })
11851
11736
  }
11852
- return open;
11853
- },
11854
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11855
- }
11856
- )
11857
- ] }),
11858
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11859
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11860
- /* @__PURE__ */ jsxRuntime.jsx(
11861
- ui.Button,
11862
- {
11863
- size: "small",
11864
- type: "button",
11865
- isLoading: isSubmitting,
11866
- onClick: onSubmit,
11867
- children: "Save"
11868
- }
11869
- )
11870
- ] }) })
11871
- ] });
11872
- };
11873
- const StackedModalTrigger = ({
11874
- shippingProfileId,
11875
- shippingOption,
11876
- shippingMethod,
11877
- setData,
11878
- children
11879
- }) => {
11880
- const { setIsOpen, getIsOpen } = useStackedModal();
11881
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11882
- const onToggle = () => {
11883
- if (isOpen) {
11884
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11885
- setData(null);
11886
- } else {
11887
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11888
- setData({
11889
- shippingProfileId,
11890
- shippingOption,
11891
- shippingMethod
11892
- });
11893
- }
11894
- };
11895
- return /* @__PURE__ */ jsxRuntime.jsx(
11896
- ui.Button,
11897
- {
11898
- size: "small",
11899
- variant: "secondary",
11900
- onClick: onToggle,
11901
- className: "text-ui-fg-primary shrink-0",
11902
- children
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
+ ]
11903
11756
  }
11904
- );
11757
+ ) });
11905
11758
  };
11906
- const ShippingProfileForm = ({
11907
- data,
11908
- order,
11909
- preview
11910
- }) => {
11911
- var _a, _b, _c, _d, _e, _f;
11912
- const { setIsOpen } = useStackedModal();
11913
- const form = reactHookForm.useForm({
11914
- resolver: zod.zodResolver(shippingMethodSchema),
11915
- defaultValues: {
11916
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11917
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11918
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11919
- }
11759
+ const schema$1 = addressSchema;
11760
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11761
+ const Shipping = () => {
11762
+ var _a;
11763
+ const { id } = reactRouterDom.useParams();
11764
+ const { order, isPending, isError, error } = useOrder(id, {
11765
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11920
11766
  });
11921
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11922
11767
  const {
11923
- mutateAsync: updateShippingMethod,
11924
- isPending: isUpdatingShippingMethod
11925
- } = useDraftOrderUpdateShippingMethod(order.id);
11926
- const onSubmit = form.handleSubmit(async (values) => {
11927
- if (isEqual__default.default(values, form.formState.defaultValues)) {
11928
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11929
- return;
11768
+ order: preview,
11769
+ isPending: isPreviewPending,
11770
+ isError: isPreviewError,
11771
+ error: previewError
11772
+ } = useOrderPreview(id);
11773
+ useInitiateOrderEdit({ preview });
11774
+ const { onCancel } = useCancelOrderEdit({ preview });
11775
+ if (isError) {
11776
+ throw error;
11777
+ }
11778
+ if (isPreviewError) {
11779
+ throw previewError;
11780
+ }
11781
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11782
+ const isReady = preview && !isPreviewPending && order && !isPending;
11783
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11784
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11785
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11786
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11787
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11788
+ ] }) }) }),
11789
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11790
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11791
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11792
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11793
+ ] }) });
11794
+ };
11795
+ const ShippingForm = ({ preview, order }) => {
11796
+ var _a;
11797
+ const { setIsOpen } = useStackedModal();
11798
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11799
+ const [data, setData] = React.useState(null);
11800
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11801
+ const { shipping_options } = useShippingOptions(
11802
+ {
11803
+ id: appliedShippingOptionIds,
11804
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11805
+ },
11806
+ {
11807
+ enabled: appliedShippingOptionIds.length > 0
11930
11808
  }
11931
- if (data.shippingMethod) {
11932
- await updateShippingMethod(
11933
- {
11934
- method_id: data.shippingMethod.id,
11935
- shipping_option_id: values.shipping_option_id,
11936
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11937
- },
11938
- {
11939
- onError: (e) => {
11940
- ui.toast.error(e.message);
11941
- },
11942
- onSuccess: () => {
11943
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11944
- }
11945
- }
11946
- );
11809
+ );
11810
+ const uniqueShippingProfiles = React.useMemo(() => {
11811
+ const profiles = /* @__PURE__ */ new Map();
11812
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11813
+ profiles.set(profile.id, profile);
11814
+ });
11815
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11816
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11817
+ });
11818
+ return Array.from(profiles.values());
11819
+ }, [order.items, shipping_options]);
11820
+ const { handleSuccess } = useRouteModal();
11821
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11822
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11823
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11824
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11825
+ const onSubmit = async () => {
11826
+ setIsSubmitting(true);
11827
+ let requestSucceeded = false;
11828
+ await requestOrderEdit(void 0, {
11829
+ onError: (e) => {
11830
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11831
+ },
11832
+ onSuccess: () => {
11833
+ requestSucceeded = true;
11834
+ }
11835
+ });
11836
+ if (!requestSucceeded) {
11837
+ setIsSubmitting(false);
11947
11838
  return;
11948
11839
  }
11949
- await addShippingMethod(
11950
- {
11951
- shipping_option_id: values.shipping_option_id,
11952
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11840
+ await confirmOrderEdit(void 0, {
11841
+ onError: (e) => {
11842
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11953
11843
  },
11954
- {
11955
- onError: (e) => {
11956
- ui.toast.error(e.message);
11957
- },
11958
- onSuccess: () => {
11959
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11844
+ onSuccess: () => {
11845
+ handleSuccess();
11846
+ },
11847
+ onSettled: () => {
11848
+ setIsSubmitting(false);
11849
+ }
11850
+ });
11851
+ };
11852
+ const onKeydown = React.useCallback(
11853
+ (e) => {
11854
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11855
+ if (data || isSubmitting) {
11856
+ return;
11960
11857
  }
11858
+ onSubmit();
11961
11859
  }
11962
- );
11963
- });
11964
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11965
- KeyboundForm,
11966
- {
11967
- className: "flex h-full flex-col overflow-hidden",
11968
- onSubmit,
11969
- children: [
11970
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11971
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11973
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11974
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11975
- ] }),
11976
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11977
- /* @__PURE__ */ jsxRuntime.jsx(
11978
- LocationField,
11979
- {
11980
- control: form.control,
11981
- setValue: form.setValue
11982
- }
11983
- ),
11984
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11985
- /* @__PURE__ */ jsxRuntime.jsx(
11986
- ShippingOptionField,
11987
- {
11988
- shippingProfileId: data.shippingProfileId,
11989
- preview,
11990
- control: form.control
11991
- }
11992
- ),
11993
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11994
- /* @__PURE__ */ jsxRuntime.jsx(
11995
- CustomAmountField,
11996
- {
11997
- control: form.control,
11998
- currencyCode: order.currency_code
11999
- }
12000
- ),
12001
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12002
- /* @__PURE__ */ jsxRuntime.jsx(
12003
- ItemsPreview,
12004
- {
12005
- order,
12006
- shippingProfileId: data.shippingProfileId
12007
- }
12008
- )
12009
- ] }) }) }),
12010
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12011
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12012
- /* @__PURE__ */ jsxRuntime.jsx(
12013
- ui.Button,
12014
- {
12015
- size: "small",
12016
- type: "submit",
12017
- isLoading: isPending || isUpdatingShippingMethod,
12018
- children: data.shippingMethod ? "Update" : "Add"
12019
- }
12020
- )
12021
- ] }) })
12022
- ]
12023
- }
12024
- ) }) });
12025
- };
12026
- const shippingMethodSchema = objectType({
12027
- location_id: stringType(),
12028
- shipping_option_id: stringType(),
12029
- custom_amount: unionType([numberType(), stringType()]).optional()
12030
- });
12031
- const ItemsPreview = ({ order, shippingProfileId }) => {
12032
- const matches = order.items.filter(
12033
- (item) => {
12034
- var _a, _b, _c;
12035
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12036
- }
11860
+ },
11861
+ [data, isSubmitting, onSubmit]
12037
11862
  );
12038
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12039
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12040
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12041
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12042
- ] }) }),
12043
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12044
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12045
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12046
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12047
- ] }),
12048
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12049
- "div",
12050
- {
12051
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12052
- children: [
12053
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12054
- /* @__PURE__ */ jsxRuntime.jsx(
12055
- Thumbnail,
12056
- {
12057
- thumbnail: item.thumbnail,
12058
- alt: item.product_title ?? void 0
12059
- }
12060
- ),
12061
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12062
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12063
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12064
- /* @__PURE__ */ jsxRuntime.jsxs(
12065
- ui.Text,
12066
- {
12067
- size: "small",
12068
- leading: "compact",
12069
- className: "text-ui-fg-subtle",
12070
- children: [
12071
- "(",
12072
- item.variant_title,
12073
- ")"
12074
- ]
12075
- }
12076
- )
12077
- ] }),
12078
- /* @__PURE__ */ jsxRuntime.jsx(
12079
- ui.Text,
12080
- {
12081
- size: "small",
12082
- leading: "compact",
12083
- className: "text-ui-fg-subtle",
12084
- children: item.variant_sku
12085
- }
12086
- )
12087
- ] })
12088
- ] }),
12089
- /* @__PURE__ */ jsxRuntime.jsxs(
11863
+ React.useEffect(() => {
11864
+ document.addEventListener("keydown", onKeydown);
11865
+ return () => {
11866
+ document.removeEventListener("keydown", onKeydown);
11867
+ };
11868
+ }, [onKeydown]);
11869
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11870
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11871
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11872
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11873
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11874
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11875
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11876
+ ] }),
11877
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11878
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11879
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11880
+ /* @__PURE__ */ jsxRuntime.jsx(
12090
11881
  ui.Text,
12091
11882
  {
12092
- size: "small",
12093
- leading: "compact",
12094
- className: "text-ui-fg-subtle",
12095
- children: [
12096
- item.quantity,
12097
- "x"
12098
- ]
11883
+ size: "xsmall",
11884
+ weight: "plus",
11885
+ className: "text-ui-fg-muted",
11886
+ children: "Shipping profile"
11887
+ }
11888
+ ),
11889
+ /* @__PURE__ */ jsxRuntime.jsx(
11890
+ ui.Text,
11891
+ {
11892
+ size: "xsmall",
11893
+ weight: "plus",
11894
+ className: "text-ui-fg-muted",
11895
+ children: "Action"
12099
11896
  }
12100
11897
  )
12101
- ]
12102
- },
12103
- item.id
12104
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12105
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12106
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12107
- 'No items found for "',
12108
- query,
12109
- '".'
12110
- ] })
12111
- ] }) })
12112
- ] })
12113
- ] });
12114
- };
12115
- const LocationField = ({ control, setValue }) => {
12116
- const locations = useComboboxData({
12117
- queryKey: ["locations"],
12118
- queryFn: async (params) => {
12119
- return await sdk.admin.stockLocation.list(params);
12120
- },
12121
- getOptions: (data) => {
12122
- return data.stock_locations.map((location) => ({
12123
- label: location.name,
12124
- value: location.id
12125
- }));
12126
- }
12127
- });
12128
- return /* @__PURE__ */ jsxRuntime.jsx(
12129
- Form$2.Field,
12130
- {
12131
- control,
12132
- name: "location_id",
12133
- render: ({ field: { onChange, ...field } }) => {
12134
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12135
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12136
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12137
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12138
11898
  ] }),
12139
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12140
- Combobox,
12141
- {
12142
- options: locations.options,
12143
- fetchNextPage: locations.fetchNextPage,
12144
- isFetchingNextPage: locations.isFetchingNextPage,
12145
- searchValue: locations.searchValue,
12146
- onSearchValueChange: locations.onSearchValueChange,
12147
- placeholder: "Select location",
12148
- onChange: (value) => {
12149
- setValue("shipping_option_id", "", {
12150
- shouldDirty: true,
12151
- shouldTouch: true
12152
- });
12153
- onChange(value);
11899
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11900
+ var _a2, _b, _c, _d, _e, _f, _g;
11901
+ const items = getItemsWithShippingProfile(
11902
+ profile.id,
11903
+ order.items
11904
+ );
11905
+ const hasItems = items.length > 0;
11906
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11907
+ (option) => option.shipping_profile_id === profile.id
11908
+ );
11909
+ const shippingMethod = preview.shipping_methods.find(
11910
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11911
+ );
11912
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11913
+ (action) => action.action === "SHIPPING_ADD"
11914
+ );
11915
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11916
+ radixUi.Accordion.Item,
11917
+ {
11918
+ value: profile.id,
11919
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11920
+ children: [
11921
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11922
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11923
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11924
+ ui.IconButton,
11925
+ {
11926
+ size: "2xsmall",
11927
+ variant: "transparent",
11928
+ className: "group/trigger",
11929
+ disabled: !hasItems,
11930
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11931
+ }
11932
+ ) }),
11933
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11934
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11935
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
11936
+ /* @__PURE__ */ jsxRuntime.jsx(
11937
+ ui.Text,
11938
+ {
11939
+ size: "small",
11940
+ weight: "plus",
11941
+ leading: "compact",
11942
+ children: profile.name
11943
+ }
11944
+ ),
11945
+ /* @__PURE__ */ jsxRuntime.jsxs(
11946
+ ui.Text,
11947
+ {
11948
+ size: "small",
11949
+ leading: "compact",
11950
+ className: "text-ui-fg-subtle",
11951
+ children: [
11952
+ items.length,
11953
+ " ",
11954
+ pluralize(items.length, "items", "item")
11955
+ ]
11956
+ }
11957
+ )
11958
+ ] })
11959
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11960
+ /* @__PURE__ */ jsxRuntime.jsx(
11961
+ ui.Tooltip,
11962
+ {
11963
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11964
+ var _a3, _b2, _c2;
11965
+ return /* @__PURE__ */ jsxRuntime.jsx(
11966
+ "li",
11967
+ {
11968
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11969
+ },
11970
+ item.id
11971
+ );
11972
+ }) }),
11973
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11974
+ ui.Badge,
11975
+ {
11976
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11977
+ size: "xsmall",
11978
+ children: [
11979
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11980
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11981
+ items.reduce(
11982
+ (acc, item) => acc + item.quantity,
11983
+ 0
11984
+ ),
11985
+ "x",
11986
+ " ",
11987
+ pluralize(items.length, "items", "item")
11988
+ ] })
11989
+ ]
11990
+ }
11991
+ )
11992
+ }
11993
+ ),
11994
+ /* @__PURE__ */ jsxRuntime.jsx(
11995
+ ui.Tooltip,
11996
+ {
11997
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11998
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11999
+ ui.Badge,
12000
+ {
12001
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12002
+ size: "xsmall",
12003
+ children: [
12004
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12005
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12006
+ ]
12007
+ }
12008
+ )
12009
+ }
12010
+ ),
12011
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12012
+ ui.Badge,
12013
+ {
12014
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12015
+ size: "xsmall",
12016
+ children: [
12017
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12018
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12019
+ ]
12020
+ }
12021
+ ) })
12022
+ ] })
12023
+ ] }),
12024
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12025
+ ActionMenu,
12026
+ {
12027
+ groups: [
12028
+ {
12029
+ actions: [
12030
+ hasItems ? {
12031
+ label: "Edit shipping option",
12032
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12033
+ onClick: () => {
12034
+ setIsOpen(
12035
+ STACKED_FOCUS_MODAL_ID,
12036
+ true
12037
+ );
12038
+ setData({
12039
+ shippingProfileId: profile.id,
12040
+ shippingOption,
12041
+ shippingMethod
12042
+ });
12043
+ }
12044
+ } : void 0,
12045
+ {
12046
+ label: "Remove shipping option",
12047
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12048
+ onClick: () => {
12049
+ if (shippingMethod) {
12050
+ if (addShippingMethodAction) {
12051
+ removeActionShippingMethod(
12052
+ addShippingMethodAction.id
12053
+ );
12054
+ } else {
12055
+ removeShippingMethod(
12056
+ shippingMethod.id
12057
+ );
12058
+ }
12059
+ }
12060
+ }
12061
+ }
12062
+ ].filter(Boolean)
12063
+ }
12064
+ ]
12065
+ }
12066
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12067
+ StackedModalTrigger,
12068
+ {
12069
+ shippingProfileId: profile.id,
12070
+ shippingOption,
12071
+ shippingMethod,
12072
+ setData,
12073
+ children: "Add shipping option"
12074
+ }
12075
+ )
12076
+ ] }),
12077
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12078
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12079
+ items.map((item, idx) => {
12080
+ var _a3, _b2, _c2, _d2, _e2;
12081
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12082
+ /* @__PURE__ */ jsxRuntime.jsxs(
12083
+ "div",
12084
+ {
12085
+ className: "flex items-center gap-x-3 px-3",
12086
+ children: [
12087
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12088
+ ui.Divider,
12089
+ {
12090
+ variant: "dashed",
12091
+ orientation: "vertical"
12092
+ }
12093
+ ) }),
12094
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12095
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12096
+ ui.Text,
12097
+ {
12098
+ size: "small",
12099
+ leading: "compact",
12100
+ className: "text-ui-fg-subtle",
12101
+ children: [
12102
+ item.quantity,
12103
+ "x"
12104
+ ]
12105
+ }
12106
+ ) }),
12107
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12108
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12109
+ /* @__PURE__ */ jsxRuntime.jsxs(
12110
+ ui.Text,
12111
+ {
12112
+ size: "small",
12113
+ leading: "compact",
12114
+ weight: "plus",
12115
+ children: [
12116
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12117
+ " (",
12118
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12119
+ ")"
12120
+ ]
12121
+ }
12122
+ ),
12123
+ /* @__PURE__ */ jsxRuntime.jsx(
12124
+ ui.Text,
12125
+ {
12126
+ size: "small",
12127
+ leading: "compact",
12128
+ className: "text-ui-fg-subtle",
12129
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12130
+ }
12131
+ )
12132
+ ] })
12133
+ ] })
12134
+ ]
12135
+ },
12136
+ item.id
12137
+ ),
12138
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12139
+ ] }, item.id);
12140
+ })
12141
+ ] })
12142
+ ]
12154
12143
  },
12155
- ...field
12144
+ profile.id
12145
+ );
12146
+ }) })
12147
+ ] }) })
12148
+ ] }) }),
12149
+ /* @__PURE__ */ jsxRuntime.jsx(
12150
+ StackedFocusModal,
12151
+ {
12152
+ id: STACKED_FOCUS_MODAL_ID,
12153
+ onOpenChangeCallback: (open) => {
12154
+ if (!open) {
12155
+ setData(null);
12156
12156
  }
12157
- ) })
12158
- ] }) });
12159
- }
12160
- }
12161
- );
12157
+ return open;
12158
+ },
12159
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12160
+ }
12161
+ )
12162
+ ] }),
12163
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12164
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12165
+ /* @__PURE__ */ jsxRuntime.jsx(
12166
+ ui.Button,
12167
+ {
12168
+ size: "small",
12169
+ type: "button",
12170
+ isLoading: isSubmitting,
12171
+ onClick: onSubmit,
12172
+ children: "Save"
12173
+ }
12174
+ )
12175
+ ] }) })
12176
+ ] });
12162
12177
  };
12163
- const ShippingOptionField = ({
12178
+ const StackedModalTrigger = ({
12164
12179
  shippingProfileId,
12165
- preview,
12166
- control
12180
+ shippingOption,
12181
+ shippingMethod,
12182
+ setData,
12183
+ children
12167
12184
  }) => {
12168
- var _a;
12169
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12170
- const shippingOptions = useComboboxData({
12171
- queryKey: ["shipping_options", locationId, shippingProfileId],
12172
- queryFn: async (params) => {
12173
- return await sdk.admin.shippingOption.list({
12174
- ...params,
12175
- stock_location_id: locationId,
12176
- shipping_profile_id: shippingProfileId
12185
+ const { setIsOpen, getIsOpen } = useStackedModal();
12186
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12187
+ const onToggle = () => {
12188
+ if (isOpen) {
12189
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12190
+ setData(null);
12191
+ } else {
12192
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12193
+ setData({
12194
+ shippingProfileId,
12195
+ shippingOption,
12196
+ shippingMethod
12177
12197
  });
12178
- },
12179
- getOptions: (data) => {
12180
- return data.shipping_options.map((option) => {
12181
- var _a2;
12182
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12183
- (r) => r.attribute === "is_return" && r.value === "true"
12184
- )) {
12185
- return void 0;
12186
- }
12187
- return {
12188
- label: option.name,
12189
- value: option.id
12190
- };
12191
- }).filter(Boolean);
12192
- },
12193
- enabled: !!locationId && !!shippingProfileId,
12194
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12195
- });
12196
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12197
- return /* @__PURE__ */ jsxRuntime.jsx(
12198
- Form$2.Field,
12199
- {
12200
- control,
12201
- name: "shipping_option_id",
12202
- render: ({ field }) => {
12203
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12204
- /* @__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
12198
  }
12231
- );
12232
- };
12233
- const CustomAmountField = ({
12234
- control,
12235
- currencyCode
12236
- }) => {
12199
+ };
12237
12200
  return /* @__PURE__ */ jsxRuntime.jsx(
12238
- Form$2.Field,
12201
+ ui.Button,
12239
12202
  {
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
- }
12203
+ size: "small",
12204
+ variant: "secondary",
12205
+ onClick: onToggle,
12206
+ className: "text-ui-fg-primary shrink-0",
12207
+ children
12259
12208
  }
12260
12209
  );
12261
12210
  };
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;
12211
+ const ShippingProfileForm = ({
12212
+ data,
12213
+ order,
12214
+ preview
12215
+ }) => {
12216
+ var _a, _b, _c, _d, _e, _f;
12217
+ const { setIsOpen } = useStackedModal();
12281
12218
  const form = reactHookForm.useForm({
12219
+ resolver: zod.zodResolver(shippingMethodSchema),
12282
12220
  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)
12221
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12222
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12223
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12224
+ }
12295
12225
  });
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
12226
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12227
+ const {
12228
+ mutateAsync: updateShippingMethod,
12229
+ isPending: isUpdatingShippingMethod
12230
+ } = useDraftOrderUpdateShippingMethod(order.id);
12231
+ const onSubmit = form.handleSubmit(async (values) => {
12232
+ if (isEqual__default.default(values, form.formState.defaultValues)) {
12233
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12234
+ return;
12235
+ }
12236
+ if (data.shippingMethod) {
12237
+ await updateShippingMethod(
12238
+ {
12239
+ method_id: data.shippingMethod.id,
12240
+ shipping_option_id: values.shipping_option_id,
12241
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12242
+ },
12243
+ {
12244
+ onError: (e) => {
12245
+ ui.toast.error(e.message);
12246
+ },
12247
+ onSuccess: () => {
12248
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12249
+ }
12312
12250
  }
12251
+ );
12252
+ return;
12253
+ }
12254
+ await addShippingMethod(
12255
+ {
12256
+ shipping_option_id: values.shipping_option_id,
12257
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12313
12258
  },
12314
12259
  {
12315
- onSuccess: () => {
12316
- handleSuccess();
12260
+ onError: (e) => {
12261
+ ui.toast.error(e.message);
12317
12262
  },
12318
- onError: (error) => {
12319
- ui.toast.error(error.message);
12263
+ onSuccess: () => {
12264
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12320
12265
  }
12321
12266
  }
12322
12267
  );
12323
12268
  });
12324
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12269
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12325
12270
  KeyboundForm,
12326
12271
  {
12327
- className: "flex flex-1 flex-col overflow-hidden",
12272
+ className: "flex h-full flex-col overflow-hidden",
12328
12273
  onSubmit,
12329
12274
  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: [
12275
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12276
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12277
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12278
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12279
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12280
+ ] }),
12281
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12331
12282
  /* @__PURE__ */ jsxRuntime.jsx(
12332
- Form$2.Field,
12283
+ LocationField,
12333
12284
  {
12334
12285
  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
- ] })
12286
+ setValue: form.setValue
12341
12287
  }
12342
12288
  ),
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
- )
12368
- ] }),
12289
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12369
12290
  /* @__PURE__ */ jsxRuntime.jsx(
12370
- Form$2.Field,
12291
+ ShippingOptionField,
12371
12292
  {
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
- ] })
12293
+ shippingProfileId: data.shippingProfileId,
12294
+ preview,
12295
+ control: form.control
12379
12296
  }
12380
12297
  ),
12298
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12381
12299
  /* @__PURE__ */ jsxRuntime.jsx(
12382
- Form$2.Field,
12300
+ CustomAmountField,
12383
12301
  {
12384
12302
  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
- ] })
12303
+ currencyCode: order.currency_code
12391
12304
  }
12392
12305
  ),
12306
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12393
12307
  /* @__PURE__ */ jsxRuntime.jsx(
12394
- Form$2.Field,
12308
+ ItemsPreview,
12395
12309
  {
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
- ] })
12310
+ order,
12311
+ shippingProfileId: data.shippingProfileId
12403
12312
  }
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,
12313
+ )
12314
+ ] }) }) }),
12315
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12316
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12317
+ /* @__PURE__ */ jsxRuntime.jsx(
12318
+ ui.Button,
12319
+ {
12320
+ size: "small",
12321
+ type: "submit",
12322
+ isLoading: isPending || isUpdatingShippingMethod,
12323
+ children: data.shippingMethod ? "Update" : "Add"
12324
+ }
12325
+ )
12326
+ ] }) })
12327
+ ]
12328
+ }
12329
+ ) }) });
12330
+ };
12331
+ const shippingMethodSchema = objectType({
12332
+ location_id: stringType(),
12333
+ shipping_option_id: stringType(),
12334
+ custom_amount: unionType([numberType(), stringType()]).optional()
12335
+ });
12336
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12337
+ const matches = order.items.filter(
12338
+ (item) => {
12339
+ var _a, _b, _c;
12340
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12341
+ }
12342
+ );
12343
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12344
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12345
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12346
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12347
+ ] }) }),
12348
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12349
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12350
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12351
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12352
+ ] }),
12353
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12354
+ "div",
12355
+ {
12356
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12357
+ children: [
12358
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12359
+ /* @__PURE__ */ jsxRuntime.jsx(
12360
+ Thumbnail,
12361
+ {
12362
+ thumbnail: item.thumbnail,
12363
+ alt: item.product_title ?? void 0
12364
+ }
12365
+ ),
12366
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12367
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12368
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12369
+ /* @__PURE__ */ jsxRuntime.jsxs(
12370
+ ui.Text,
12371
+ {
12372
+ size: "small",
12373
+ leading: "compact",
12374
+ className: "text-ui-fg-subtle",
12375
+ children: [
12376
+ "(",
12377
+ item.variant_title,
12378
+ ")"
12379
+ ]
12380
+ }
12381
+ )
12382
+ ] }),
12383
+ /* @__PURE__ */ jsxRuntime.jsx(
12384
+ ui.Text,
12385
+ {
12386
+ size: "small",
12387
+ leading: "compact",
12388
+ className: "text-ui-fg-subtle",
12389
+ children: item.variant_sku
12390
+ }
12391
+ )
12392
+ ] })
12393
+ ] }),
12394
+ /* @__PURE__ */ jsxRuntime.jsxs(
12395
+ ui.Text,
12420
12396
  {
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
- ] })
12397
+ size: "small",
12398
+ leading: "compact",
12399
+ className: "text-ui-fg-subtle",
12400
+ children: [
12401
+ item.quantity,
12402
+ "x"
12403
+ ]
12428
12404
  }
12429
12405
  )
12406
+ ]
12407
+ },
12408
+ item.id
12409
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12410
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12411
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12412
+ 'No items found for "',
12413
+ query,
12414
+ '".'
12415
+ ] })
12416
+ ] }) })
12417
+ ] })
12418
+ ] });
12419
+ };
12420
+ const LocationField = ({ control, setValue }) => {
12421
+ const locations = useComboboxData({
12422
+ queryKey: ["locations"],
12423
+ queryFn: async (params) => {
12424
+ return await sdk.admin.stockLocation.list(params);
12425
+ },
12426
+ getOptions: (data) => {
12427
+ return data.stock_locations.map((location) => ({
12428
+ label: location.name,
12429
+ value: location.id
12430
+ }));
12431
+ }
12432
+ });
12433
+ return /* @__PURE__ */ jsxRuntime.jsx(
12434
+ Form$2.Field,
12435
+ {
12436
+ control,
12437
+ name: "location_id",
12438
+ render: ({ field: { onChange, ...field } }) => {
12439
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12440
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12441
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12442
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12443
+ ] }),
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12445
+ Combobox,
12446
+ {
12447
+ options: locations.options,
12448
+ fetchNextPage: locations.fetchNextPage,
12449
+ isFetchingNextPage: locations.isFetchingNextPage,
12450
+ searchValue: locations.searchValue,
12451
+ onSearchValueChange: locations.onSearchValueChange,
12452
+ placeholder: "Select location",
12453
+ onChange: (value) => {
12454
+ setValue("shipping_option_id", "", {
12455
+ shouldDirty: true,
12456
+ shouldTouch: true
12457
+ });
12458
+ onChange(value);
12459
+ },
12460
+ ...field
12461
+ }
12462
+ ) })
12463
+ ] }) });
12464
+ }
12465
+ }
12466
+ );
12467
+ };
12468
+ const ShippingOptionField = ({
12469
+ shippingProfileId,
12470
+ preview,
12471
+ control
12472
+ }) => {
12473
+ var _a;
12474
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12475
+ const shippingOptions = useComboboxData({
12476
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12477
+ queryFn: async (params) => {
12478
+ return await sdk.admin.shippingOption.list({
12479
+ ...params,
12480
+ stock_location_id: locationId,
12481
+ shipping_profile_id: shippingProfileId
12482
+ });
12483
+ },
12484
+ getOptions: (data) => {
12485
+ return data.shipping_options.map((option) => {
12486
+ var _a2;
12487
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12488
+ (r) => r.attribute === "is_return" && r.value === "true"
12489
+ )) {
12490
+ return void 0;
12491
+ }
12492
+ return {
12493
+ label: option.name,
12494
+ value: option.id
12495
+ };
12496
+ }).filter(Boolean);
12497
+ },
12498
+ enabled: !!locationId && !!shippingProfileId,
12499
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12500
+ });
12501
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12502
+ return /* @__PURE__ */ jsxRuntime.jsx(
12503
+ Form$2.Field,
12504
+ {
12505
+ control,
12506
+ name: "shipping_option_id",
12507
+ render: ({ field }) => {
12508
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12509
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12510
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12511
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12430
12512
  ] }),
12431
12513
  /* @__PURE__ */ jsxRuntime.jsx(
12432
- Form$2.Field,
12514
+ ConditionalTooltip,
12433
12515
  {
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
- ] })
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
+ ) }) })
12441
12531
  }
12442
- ),
12443
- /* @__PURE__ */ jsxRuntime.jsx(
12444
- Form$2.Field,
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." })
12552
+ ] }),
12553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12554
+ ui.CurrencyInput,
12445
12555
  {
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
- ] })
12556
+ ...field,
12557
+ onValueChange: (value) => onChange(value),
12558
+ symbol: getNativeSymbol(currencyCode),
12559
+ code: currencyCode
12453
12560
  }
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
- ]
12561
+ ) })
12562
+ ] });
12563
+ }
12461
12564
  }
12462
- ) });
12565
+ );
12463
12566
  };
12464
- const schema$2 = addressSchema;
12465
12567
  const TransferOwnership = () => {
12466
12568
  const { id } = reactRouterDom.useParams();
12467
12569
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12485,7 +12587,7 @@ const TransferOwnershipForm = ({ order }) => {
12485
12587
  defaultValues: {
12486
12588
  customer_id: order.customer_id || ""
12487
12589
  },
12488
- resolver: zod.zodResolver(schema$1)
12590
+ resolver: zod.zodResolver(schema)
12489
12591
  });
12490
12592
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12491
12593
  const { handleSuccess } = useRouteModal();
@@ -12935,114 +13037,8 @@ const Illustration = () => {
12935
13037
  }
12936
13038
  );
12937
13039
  };
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
13040
  const schema = objectType({
13045
- sales_channel_id: stringType().min(1)
13041
+ customer_id: stringType().min(1)
13046
13042
  });
13047
13043
  const widgetModule = { widgets: [] };
13048
13044
  const routeModule = {
@@ -13068,14 +13064,14 @@ const routeModule = {
13068
13064
  Component: BillingAddress,
13069
13065
  path: "/draft-orders/:id/billing-address"
13070
13066
  },
13071
- {
13072
- Component: CustomItems,
13073
- path: "/draft-orders/:id/custom-items"
13074
- },
13075
13067
  {
13076
13068
  Component: Email,
13077
13069
  path: "/draft-orders/:id/email"
13078
13070
  },
13071
+ {
13072
+ Component: CustomItems,
13073
+ path: "/draft-orders/:id/custom-items"
13074
+ },
13079
13075
  {
13080
13076
  Component: Items,
13081
13077
  path: "/draft-orders/:id/items"
@@ -13089,20 +13085,20 @@ const routeModule = {
13089
13085
  path: "/draft-orders/:id/promotions"
13090
13086
  },
13091
13087
  {
13092
- Component: Shipping,
13093
- path: "/draft-orders/:id/shipping"
13088
+ Component: SalesChannel,
13089
+ path: "/draft-orders/:id/sales-channel"
13094
13090
  },
13095
13091
  {
13096
13092
  Component: ShippingAddress,
13097
13093
  path: "/draft-orders/:id/shipping-address"
13098
13094
  },
13099
13095
  {
13100
- Component: TransferOwnership,
13101
- path: "/draft-orders/:id/transfer-ownership"
13096
+ Component: Shipping,
13097
+ path: "/draft-orders/:id/shipping"
13102
13098
  },
13103
13099
  {
13104
- Component: SalesChannel,
13105
- path: "/draft-orders/:id/sales-channel"
13100
+ Component: TransferOwnership,
13101
+ path: "/draft-orders/:id/transfer-ownership"
13106
13102
  }
13107
13103
  ]
13108
13104
  }