@medusajs/draft-order 2.11.0-preview-20251017180154 → 2.11.0-preview-20251017210155

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.
@@ -9763,27 +9763,6 @@ const BillingAddressForm = ({ order }) => {
9763
9763
  ) });
9764
9764
  };
9765
9765
  const schema$5 = addressSchema;
9766
- const CustomItems = () => {
9767
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
- ] });
9771
- };
9772
- const CustomItemsForm = () => {
9773
- const form = reactHookForm.useForm({
9774
- resolver: zod.zodResolver(schema$4)
9775
- });
9776
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
- ] }) })
9782
- ] }) });
9783
- };
9784
- const schema$4 = objectType({
9785
- email: stringType().email()
9786
- });
9787
9766
  const Email = () => {
9788
9767
  const { id } = reactRouterDom.useParams();
9789
9768
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9806,7 +9785,7 @@ const EmailForm = ({ order }) => {
9806
9785
  defaultValues: {
9807
9786
  email: order.email ?? ""
9808
9787
  },
9809
- resolver: zod.zodResolver(schema$3)
9788
+ resolver: zod.zodResolver(schema$4)
9810
9789
  });
9811
9790
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
9791
  const { handleSuccess } = useRouteModal();
@@ -9849,7 +9828,7 @@ const EmailForm = ({ order }) => {
9849
9828
  }
9850
9829
  ) });
9851
9830
  };
9852
- const schema$3 = objectType({
9831
+ const schema$4 = objectType({
9853
9832
  email: stringType().email()
9854
9833
  });
9855
9834
  const NumberInput = React.forwardRef(
@@ -11481,7 +11460,7 @@ const SalesChannelForm = ({ order }) => {
11481
11460
  defaultValues: {
11482
11461
  sales_channel_id: order.sales_channel_id || ""
11483
11462
  },
11484
- resolver: zod.zodResolver(schema$2)
11463
+ resolver: zod.zodResolver(schema$3)
11485
11464
  });
11486
11465
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11487
11466
  const { handleSuccess } = useRouteModal();
@@ -11556,824 +11535,145 @@ const SalesChannelField = ({ control, order }) => {
11556
11535
  }
11557
11536
  );
11558
11537
  };
11559
- const schema$2 = objectType({
11538
+ const schema$3 = objectType({
11560
11539
  sales_channel_id: stringType().min(1)
11561
11540
  });
11562
- const ShippingAddress = () => {
11541
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11542
+ const Shipping = () => {
11543
+ var _a;
11563
11544
  const { id } = reactRouterDom.useParams();
11564
11545
  const { order, isPending, isError, error } = useOrder(id, {
11565
- fields: "+shipping_address"
11546
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11566
11547
  });
11548
+ const {
11549
+ order: preview,
11550
+ isPending: isPreviewPending,
11551
+ isError: isPreviewError,
11552
+ error: previewError
11553
+ } = useOrderPreview(id);
11554
+ useInitiateOrderEdit({ preview });
11555
+ const { onCancel } = useCancelOrderEdit({ preview });
11567
11556
  if (isError) {
11568
11557
  throw error;
11569
11558
  }
11570
- const isReady = !isPending && !!order;
11571
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11572
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11573
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11574
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11575
- ] }),
11576
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11577
- ] });
11559
+ if (isPreviewError) {
11560
+ throw previewError;
11561
+ }
11562
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11563
+ const isReady = preview && !isPreviewPending && order && !isPending;
11564
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11565
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11566
+ /* @__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 py-16 px-6", children: [
11567
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11568
+ /* @__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." }) })
11569
+ ] }) }) }),
11570
+ /* @__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" }) }) })
11571
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11572
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11573
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11574
+ ] }) });
11578
11575
  };
11579
- const ShippingAddressForm = ({ order }) => {
11580
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11581
- const form = reactHookForm.useForm({
11582
- defaultValues: {
11583
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11584
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11585
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11586
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11587
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11588
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11589
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11590
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11591
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11592
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11576
+ const ShippingForm = ({ preview, order }) => {
11577
+ var _a;
11578
+ const { setIsOpen } = useStackedModal();
11579
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11580
+ const [data, setData] = React.useState(null);
11581
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11582
+ const { shipping_options } = useShippingOptions(
11583
+ {
11584
+ id: appliedShippingOptionIds,
11585
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11593
11586
  },
11594
- resolver: zod.zodResolver(schema$1)
11595
- });
11596
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11587
+ {
11588
+ enabled: appliedShippingOptionIds.length > 0
11589
+ }
11590
+ );
11591
+ const uniqueShippingProfiles = React.useMemo(() => {
11592
+ const profiles = /* @__PURE__ */ new Map();
11593
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11594
+ profiles.set(profile.id, profile);
11595
+ });
11596
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11597
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11598
+ });
11599
+ return Array.from(profiles.values());
11600
+ }, [order.items, shipping_options]);
11597
11601
  const { handleSuccess } = useRouteModal();
11598
- const onSubmit = form.handleSubmit(async (data) => {
11599
- await mutateAsync(
11600
- {
11601
- shipping_address: {
11602
- first_name: data.first_name,
11603
- last_name: data.last_name,
11604
- company: data.company,
11605
- address_1: data.address_1,
11606
- address_2: data.address_2,
11607
- city: data.city,
11608
- province: data.province,
11609
- country_code: data.country_code,
11610
- postal_code: data.postal_code,
11611
- phone: data.phone
11612
- }
11602
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11603
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11604
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11605
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11606
+ const onSubmit = async () => {
11607
+ setIsSubmitting(true);
11608
+ let requestSucceeded = false;
11609
+ await requestOrderEdit(void 0, {
11610
+ onError: (e) => {
11611
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11613
11612
  },
11614
- {
11615
- onSuccess: () => {
11616
- handleSuccess();
11617
- },
11618
- onError: (error) => {
11619
- ui.toast.error(error.message);
11613
+ onSuccess: () => {
11614
+ requestSucceeded = true;
11615
+ }
11616
+ });
11617
+ if (!requestSucceeded) {
11618
+ setIsSubmitting(false);
11619
+ return;
11620
+ }
11621
+ await confirmOrderEdit(void 0, {
11622
+ onError: (e) => {
11623
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11624
+ },
11625
+ onSuccess: () => {
11626
+ handleSuccess();
11627
+ },
11628
+ onSettled: () => {
11629
+ setIsSubmitting(false);
11630
+ }
11631
+ });
11632
+ };
11633
+ const onKeydown = React.useCallback(
11634
+ (e) => {
11635
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11636
+ if (data || isSubmitting) {
11637
+ return;
11620
11638
  }
11639
+ onSubmit();
11621
11640
  }
11622
- );
11623
- });
11624
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11625
- KeyboundForm,
11626
- {
11627
- className: "flex flex-1 flex-col overflow-hidden",
11628
- onSubmit,
11629
- children: [
11630
- /* @__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: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(
11632
- Form$2.Field,
11633
- {
11634
- control: form.control,
11635
- name: "country_code",
11636
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11640
- ] })
11641
- }
11642
- ),
11643
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11641
+ },
11642
+ [data, isSubmitting, onSubmit]
11643
+ );
11644
+ React.useEffect(() => {
11645
+ document.addEventListener("keydown", onKeydown);
11646
+ return () => {
11647
+ document.removeEventListener("keydown", onKeydown);
11648
+ };
11649
+ }, [onKeydown]);
11650
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11651
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11652
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11653
+ /* @__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 py-16 px-6", children: [
11654
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11655
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11656
+ /* @__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." }) })
11657
+ ] }),
11658
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11659
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11660
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11644
11661
  /* @__PURE__ */ jsxRuntime.jsx(
11645
- Form$2.Field,
11662
+ ui.Text,
11646
11663
  {
11647
- control: form.control,
11648
- name: "first_name",
11649
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11653
- ] })
11664
+ size: "xsmall",
11665
+ weight: "plus",
11666
+ className: "text-ui-fg-muted",
11667
+ children: "Shipping profile"
11654
11668
  }
11655
11669
  ),
11656
11670
  /* @__PURE__ */ jsxRuntime.jsx(
11657
- Form$2.Field,
11671
+ ui.Text,
11658
11672
  {
11659
- control: form.control,
11660
- name: "last_name",
11661
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11665
- ] })
11666
- }
11667
- )
11668
- ] }),
11669
- /* @__PURE__ */ jsxRuntime.jsx(
11670
- Form$2.Field,
11671
- {
11672
- control: form.control,
11673
- name: "company",
11674
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11678
- ] })
11679
- }
11680
- ),
11681
- /* @__PURE__ */ jsxRuntime.jsx(
11682
- Form$2.Field,
11683
- {
11684
- control: form.control,
11685
- name: "address_1",
11686
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11690
- ] })
11691
- }
11692
- ),
11693
- /* @__PURE__ */ jsxRuntime.jsx(
11694
- Form$2.Field,
11695
- {
11696
- control: form.control,
11697
- name: "address_2",
11698
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11702
- ] })
11703
- }
11704
- ),
11705
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11706
- /* @__PURE__ */ jsxRuntime.jsx(
11707
- Form$2.Field,
11708
- {
11709
- control: form.control,
11710
- name: "postal_code",
11711
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11715
- ] })
11716
- }
11717
- ),
11718
- /* @__PURE__ */ jsxRuntime.jsx(
11719
- Form$2.Field,
11720
- {
11721
- control: form.control,
11722
- name: "city",
11723
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11727
- ] })
11728
- }
11729
- )
11730
- ] }),
11731
- /* @__PURE__ */ jsxRuntime.jsx(
11732
- Form$2.Field,
11733
- {
11734
- control: form.control,
11735
- name: "province",
11736
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11740
- ] })
11741
- }
11742
- ),
11743
- /* @__PURE__ */ jsxRuntime.jsx(
11744
- Form$2.Field,
11745
- {
11746
- control: form.control,
11747
- name: "phone",
11748
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11752
- ] })
11753
- }
11754
- )
11755
- ] }) }),
11756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11758
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11759
- ] }) })
11760
- ]
11761
- }
11762
- ) });
11763
- };
11764
- const schema$1 = addressSchema;
11765
- const TransferOwnership = () => {
11766
- const { id } = reactRouterDom.useParams();
11767
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11768
- fields: "id,customer_id,customer.*"
11769
- });
11770
- if (isError) {
11771
- throw error;
11772
- }
11773
- const isReady = !isPending && !!draft_order;
11774
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11775
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11776
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11778
- ] }),
11779
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11780
- ] });
11781
- };
11782
- const TransferOwnershipForm = ({ order }) => {
11783
- var _a, _b;
11784
- const form = reactHookForm.useForm({
11785
- defaultValues: {
11786
- customer_id: order.customer_id || ""
11787
- },
11788
- resolver: zod.zodResolver(schema)
11789
- });
11790
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11791
- const { handleSuccess } = useRouteModal();
11792
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11793
- const currentCustomer = order.customer ? {
11794
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11795
- value: order.customer.id
11796
- } : null;
11797
- const onSubmit = form.handleSubmit(async (data) => {
11798
- await mutateAsync(
11799
- { customer_id: data.customer_id },
11800
- {
11801
- onSuccess: () => {
11802
- ui.toast.success("Customer updated");
11803
- handleSuccess();
11804
- },
11805
- onError: (error) => {
11806
- ui.toast.error(error.message);
11807
- }
11808
- }
11809
- );
11810
- });
11811
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11812
- KeyboundForm,
11813
- {
11814
- className: "flex flex-1 flex-col overflow-hidden",
11815
- onSubmit,
11816
- children: [
11817
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11818
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11819
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11820
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11821
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11822
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11823
- ] }),
11824
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11825
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11826
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11827
- ] })
11828
- ] }),
11829
- /* @__PURE__ */ jsxRuntime.jsx(
11830
- CustomerField,
11831
- {
11832
- control: form.control,
11833
- currentCustomerId: order.customer_id
11834
- }
11835
- )
11836
- ] }),
11837
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11838
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11839
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11840
- ] }) })
11841
- ]
11842
- }
11843
- ) });
11844
- };
11845
- const CustomerField = ({ control, currentCustomerId }) => {
11846
- const customers = useComboboxData({
11847
- queryFn: async (params) => {
11848
- return await sdk.admin.customer.list({
11849
- ...params,
11850
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11851
- });
11852
- },
11853
- queryKey: ["customers"],
11854
- getOptions: (data) => {
11855
- return data.customers.map((customer) => {
11856
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11857
- return {
11858
- label: name ? `${name} (${customer.email})` : customer.email,
11859
- value: customer.id
11860
- };
11861
- });
11862
- }
11863
- });
11864
- return /* @__PURE__ */ jsxRuntime.jsx(
11865
- Form$2.Field,
11866
- {
11867
- name: "customer_id",
11868
- control,
11869
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11870
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11871
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11872
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11873
- ] }),
11874
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11875
- Combobox,
11876
- {
11877
- options: customers.options,
11878
- fetchNextPage: customers.fetchNextPage,
11879
- isFetchingNextPage: customers.isFetchingNextPage,
11880
- searchValue: customers.searchValue,
11881
- onSearchValueChange: customers.onSearchValueChange,
11882
- placeholder: "Select customer",
11883
- ...field
11884
- }
11885
- ) }),
11886
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11887
- ] })
11888
- }
11889
- );
11890
- };
11891
- const Illustration = () => {
11892
- return /* @__PURE__ */ jsxRuntime.jsxs(
11893
- "svg",
11894
- {
11895
- width: "280",
11896
- height: "180",
11897
- viewBox: "0 0 280 180",
11898
- fill: "none",
11899
- xmlns: "http://www.w3.org/2000/svg",
11900
- children: [
11901
- /* @__PURE__ */ jsxRuntime.jsx(
11902
- "rect",
11903
- {
11904
- x: "0.00428286",
11905
- y: "-0.742904",
11906
- width: "33.5",
11907
- height: "65.5",
11908
- rx: "6.75",
11909
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11910
- fill: "#D4D4D8",
11911
- stroke: "#52525B",
11912
- strokeWidth: "1.5"
11913
- }
11914
- ),
11915
- /* @__PURE__ */ jsxRuntime.jsx(
11916
- "rect",
11917
- {
11918
- x: "0.00428286",
11919
- y: "-0.742904",
11920
- width: "33.5",
11921
- height: "65.5",
11922
- rx: "6.75",
11923
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11924
- fill: "white",
11925
- stroke: "#52525B",
11926
- strokeWidth: "1.5"
11927
- }
11928
- ),
11929
- /* @__PURE__ */ jsxRuntime.jsx(
11930
- "path",
11931
- {
11932
- d: "M180.579 107.142L179.126 107.959",
11933
- stroke: "#52525B",
11934
- strokeWidth: "1.5",
11935
- strokeLinecap: "round",
11936
- strokeLinejoin: "round"
11937
- }
11938
- ),
11939
- /* @__PURE__ */ jsxRuntime.jsx(
11940
- "path",
11941
- {
11942
- opacity: "0.88",
11943
- d: "M182.305 109.546L180.257 109.534",
11944
- stroke: "#52525B",
11945
- strokeWidth: "1.5",
11946
- strokeLinecap: "round",
11947
- strokeLinejoin: "round"
11948
- }
11949
- ),
11950
- /* @__PURE__ */ jsxRuntime.jsx(
11951
- "path",
11952
- {
11953
- opacity: "0.75",
11954
- d: "M180.551 111.93L179.108 111.096",
11955
- stroke: "#52525B",
11956
- strokeWidth: "1.5",
11957
- strokeLinecap: "round",
11958
- strokeLinejoin: "round"
11959
- }
11960
- ),
11961
- /* @__PURE__ */ jsxRuntime.jsx(
11962
- "path",
11963
- {
11964
- opacity: "0.63",
11965
- d: "M176.347 112.897L176.354 111.73",
11966
- stroke: "#52525B",
11967
- strokeWidth: "1.5",
11968
- strokeLinecap: "round",
11969
- strokeLinejoin: "round"
11970
- }
11971
- ),
11972
- /* @__PURE__ */ jsxRuntime.jsx(
11973
- "path",
11974
- {
11975
- opacity: "0.5",
11976
- d: "M172.153 111.881L173.606 111.064",
11977
- stroke: "#52525B",
11978
- strokeWidth: "1.5",
11979
- strokeLinecap: "round",
11980
- strokeLinejoin: "round"
11981
- }
11982
- ),
11983
- /* @__PURE__ */ jsxRuntime.jsx(
11984
- "path",
11985
- {
11986
- opacity: "0.38",
11987
- d: "M170.428 109.478L172.476 109.489",
11988
- stroke: "#52525B",
11989
- strokeWidth: "1.5",
11990
- strokeLinecap: "round",
11991
- strokeLinejoin: "round"
11992
- }
11993
- ),
11994
- /* @__PURE__ */ jsxRuntime.jsx(
11995
- "path",
11996
- {
11997
- opacity: "0.25",
11998
- d: "M172.181 107.094L173.624 107.928",
11999
- stroke: "#52525B",
12000
- strokeWidth: "1.5",
12001
- strokeLinecap: "round",
12002
- strokeLinejoin: "round"
12003
- }
12004
- ),
12005
- /* @__PURE__ */ jsxRuntime.jsx(
12006
- "path",
12007
- {
12008
- opacity: "0.13",
12009
- d: "M176.386 106.126L176.379 107.294",
12010
- stroke: "#52525B",
12011
- strokeWidth: "1.5",
12012
- strokeLinecap: "round",
12013
- strokeLinejoin: "round"
12014
- }
12015
- ),
12016
- /* @__PURE__ */ jsxRuntime.jsx(
12017
- "rect",
12018
- {
12019
- width: "12",
12020
- height: "3",
12021
- rx: "1.5",
12022
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12023
- fill: "#D4D4D8"
12024
- }
12025
- ),
12026
- /* @__PURE__ */ jsxRuntime.jsx(
12027
- "rect",
12028
- {
12029
- x: "0.00428286",
12030
- y: "-0.742904",
12031
- width: "33.5",
12032
- height: "65.5",
12033
- rx: "6.75",
12034
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12035
- fill: "#D4D4D8",
12036
- stroke: "#52525B",
12037
- strokeWidth: "1.5"
12038
- }
12039
- ),
12040
- /* @__PURE__ */ jsxRuntime.jsx(
12041
- "rect",
12042
- {
12043
- x: "0.00428286",
12044
- y: "-0.742904",
12045
- width: "33.5",
12046
- height: "65.5",
12047
- rx: "6.75",
12048
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12049
- fill: "white",
12050
- stroke: "#52525B",
12051
- strokeWidth: "1.5"
12052
- }
12053
- ),
12054
- /* @__PURE__ */ jsxRuntime.jsx(
12055
- "rect",
12056
- {
12057
- width: "12",
12058
- height: "3",
12059
- rx: "1.5",
12060
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12061
- fill: "#D4D4D8"
12062
- }
12063
- ),
12064
- /* @__PURE__ */ jsxRuntime.jsx(
12065
- "rect",
12066
- {
12067
- width: "17",
12068
- height: "3",
12069
- rx: "1.5",
12070
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12071
- fill: "#D4D4D8"
12072
- }
12073
- ),
12074
- /* @__PURE__ */ jsxRuntime.jsx(
12075
- "rect",
12076
- {
12077
- width: "12",
12078
- height: "3",
12079
- rx: "1.5",
12080
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12081
- fill: "#D4D4D8"
12082
- }
12083
- ),
12084
- /* @__PURE__ */ jsxRuntime.jsx(
12085
- "path",
12086
- {
12087
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12088
- fill: "#A1A1AA"
12089
- }
12090
- ),
12091
- /* @__PURE__ */ jsxRuntime.jsx(
12092
- "rect",
12093
- {
12094
- width: "17",
12095
- height: "3",
12096
- rx: "1.5",
12097
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12098
- fill: "#A1A1AA"
12099
- }
12100
- ),
12101
- /* @__PURE__ */ jsxRuntime.jsx(
12102
- "rect",
12103
- {
12104
- width: "12",
12105
- height: "3",
12106
- rx: "1.5",
12107
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12108
- fill: "#A1A1AA"
12109
- }
12110
- ),
12111
- /* @__PURE__ */ jsxRuntime.jsx(
12112
- "path",
12113
- {
12114
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12115
- fill: "#52525B"
12116
- }
12117
- ),
12118
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12119
- "path",
12120
- {
12121
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12122
- stroke: "#A1A1AA",
12123
- strokeWidth: "1.5",
12124
- strokeLinecap: "round",
12125
- strokeLinejoin: "round"
12126
- }
12127
- ) }),
12128
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12129
- "path",
12130
- {
12131
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12132
- stroke: "#A1A1AA",
12133
- strokeWidth: "1.5",
12134
- strokeLinecap: "round",
12135
- strokeLinejoin: "round"
12136
- }
12137
- ) }),
12138
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12139
- "path",
12140
- {
12141
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12142
- stroke: "#A1A1AA",
12143
- strokeWidth: "1.5",
12144
- strokeLinecap: "round",
12145
- strokeLinejoin: "round"
12146
- }
12147
- ) }),
12148
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12149
- "path",
12150
- {
12151
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12152
- stroke: "#A1A1AA",
12153
- strokeWidth: "1.5",
12154
- strokeLinecap: "round",
12155
- strokeLinejoin: "round"
12156
- }
12157
- ) }),
12158
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12159
- "path",
12160
- {
12161
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12162
- stroke: "#A1A1AA",
12163
- strokeWidth: "1.5",
12164
- strokeLinecap: "round",
12165
- strokeLinejoin: "round"
12166
- }
12167
- ) }),
12168
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12169
- "path",
12170
- {
12171
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12172
- stroke: "#A1A1AA",
12173
- strokeWidth: "1.5",
12174
- strokeLinecap: "round",
12175
- strokeLinejoin: "round"
12176
- }
12177
- ) }),
12178
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12179
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12180
- "rect",
12181
- {
12182
- width: "12",
12183
- height: "12",
12184
- fill: "white",
12185
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12186
- }
12187
- ) }),
12188
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12189
- "rect",
12190
- {
12191
- width: "12",
12192
- height: "12",
12193
- fill: "white",
12194
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12195
- }
12196
- ) }),
12197
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12198
- "rect",
12199
- {
12200
- width: "12",
12201
- height: "12",
12202
- fill: "white",
12203
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12204
- }
12205
- ) }),
12206
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12207
- "rect",
12208
- {
12209
- width: "12",
12210
- height: "12",
12211
- fill: "white",
12212
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12213
- }
12214
- ) }),
12215
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12216
- "rect",
12217
- {
12218
- width: "12",
12219
- height: "12",
12220
- fill: "white",
12221
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12222
- }
12223
- ) }),
12224
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12225
- "rect",
12226
- {
12227
- width: "12",
12228
- height: "12",
12229
- fill: "white",
12230
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12231
- }
12232
- ) })
12233
- ] })
12234
- ]
12235
- }
12236
- );
12237
- };
12238
- const schema = objectType({
12239
- customer_id: stringType().min(1)
12240
- });
12241
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12242
- const Shipping = () => {
12243
- var _a;
12244
- const { id } = reactRouterDom.useParams();
12245
- const { order, isPending, isError, error } = useOrder(id, {
12246
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12247
- });
12248
- const {
12249
- order: preview,
12250
- isPending: isPreviewPending,
12251
- isError: isPreviewError,
12252
- error: previewError
12253
- } = useOrderPreview(id);
12254
- useInitiateOrderEdit({ preview });
12255
- const { onCancel } = useCancelOrderEdit({ preview });
12256
- if (isError) {
12257
- throw error;
12258
- }
12259
- if (isPreviewError) {
12260
- throw previewError;
12261
- }
12262
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12263
- const isReady = preview && !isPreviewPending && order && !isPending;
12264
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12266
- /* @__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 py-16 px-6", children: [
12267
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12268
- /* @__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." }) })
12269
- ] }) }) }),
12270
- /* @__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" }) }) })
12271
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12272
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12273
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12274
- ] }) });
12275
- };
12276
- const ShippingForm = ({ preview, order }) => {
12277
- var _a;
12278
- const { setIsOpen } = useStackedModal();
12279
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12280
- const [data, setData] = React.useState(null);
12281
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12282
- const { shipping_options } = useShippingOptions(
12283
- {
12284
- id: appliedShippingOptionIds,
12285
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12286
- },
12287
- {
12288
- enabled: appliedShippingOptionIds.length > 0
12289
- }
12290
- );
12291
- const uniqueShippingProfiles = React.useMemo(() => {
12292
- const profiles = /* @__PURE__ */ new Map();
12293
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12294
- profiles.set(profile.id, profile);
12295
- });
12296
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12297
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12298
- });
12299
- return Array.from(profiles.values());
12300
- }, [order.items, shipping_options]);
12301
- const { handleSuccess } = useRouteModal();
12302
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12303
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12304
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12305
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12306
- const onSubmit = async () => {
12307
- setIsSubmitting(true);
12308
- let requestSucceeded = false;
12309
- await requestOrderEdit(void 0, {
12310
- onError: (e) => {
12311
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12312
- },
12313
- onSuccess: () => {
12314
- requestSucceeded = true;
12315
- }
12316
- });
12317
- if (!requestSucceeded) {
12318
- setIsSubmitting(false);
12319
- return;
12320
- }
12321
- await confirmOrderEdit(void 0, {
12322
- onError: (e) => {
12323
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12324
- },
12325
- onSuccess: () => {
12326
- handleSuccess();
12327
- },
12328
- onSettled: () => {
12329
- setIsSubmitting(false);
12330
- }
12331
- });
12332
- };
12333
- const onKeydown = React.useCallback(
12334
- (e) => {
12335
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12336
- if (data || isSubmitting) {
12337
- return;
12338
- }
12339
- onSubmit();
12340
- }
12341
- },
12342
- [data, isSubmitting, onSubmit]
12343
- );
12344
- React.useEffect(() => {
12345
- document.addEventListener("keydown", onKeydown);
12346
- return () => {
12347
- document.removeEventListener("keydown", onKeydown);
12348
- };
12349
- }, [onKeydown]);
12350
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12351
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12352
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12353
- /* @__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 py-16 px-6", children: [
12354
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12355
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12356
- /* @__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." }) })
12357
- ] }),
12358
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12359
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
12360
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12361
- /* @__PURE__ */ jsxRuntime.jsx(
12362
- ui.Text,
12363
- {
12364
- size: "xsmall",
12365
- weight: "plus",
12366
- className: "text-ui-fg-muted",
12367
- children: "Shipping profile"
12368
- }
12369
- ),
12370
- /* @__PURE__ */ jsxRuntime.jsx(
12371
- ui.Text,
12372
- {
12373
- size: "xsmall",
12374
- weight: "plus",
12375
- className: "text-ui-fg-muted",
12376
- children: "Action"
11673
+ size: "xsmall",
11674
+ weight: "plus",
11675
+ className: "text-ui-fg-muted",
11676
+ children: "Action"
12377
11677
  }
12378
11678
  )
12379
11679
  ] }),
@@ -12635,416 +11935,1116 @@ const ShippingForm = ({ preview, order }) => {
12635
11935
  if (!open) {
12636
11936
  setData(null);
12637
11937
  }
12638
- return open;
12639
- },
12640
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12641
- }
12642
- )
12643
- ] }),
12644
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12645
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12646
- /* @__PURE__ */ jsxRuntime.jsx(
12647
- ui.Button,
11938
+ return open;
11939
+ },
11940
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11941
+ }
11942
+ )
11943
+ ] }),
11944
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11945
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11946
+ /* @__PURE__ */ jsxRuntime.jsx(
11947
+ ui.Button,
11948
+ {
11949
+ size: "small",
11950
+ type: "button",
11951
+ isLoading: isSubmitting,
11952
+ onClick: onSubmit,
11953
+ children: "Save"
11954
+ }
11955
+ )
11956
+ ] }) })
11957
+ ] });
11958
+ };
11959
+ const StackedModalTrigger = ({
11960
+ shippingProfileId,
11961
+ shippingOption,
11962
+ shippingMethod,
11963
+ setData,
11964
+ children
11965
+ }) => {
11966
+ const { setIsOpen, getIsOpen } = useStackedModal();
11967
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11968
+ const onToggle = () => {
11969
+ if (isOpen) {
11970
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11971
+ setData(null);
11972
+ } else {
11973
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11974
+ setData({
11975
+ shippingProfileId,
11976
+ shippingOption,
11977
+ shippingMethod
11978
+ });
11979
+ }
11980
+ };
11981
+ return /* @__PURE__ */ jsxRuntime.jsx(
11982
+ ui.Button,
11983
+ {
11984
+ size: "small",
11985
+ variant: "secondary",
11986
+ onClick: onToggle,
11987
+ className: "text-ui-fg-primary shrink-0",
11988
+ children
11989
+ }
11990
+ );
11991
+ };
11992
+ const ShippingProfileForm = ({
11993
+ data,
11994
+ order,
11995
+ preview
11996
+ }) => {
11997
+ var _a, _b, _c, _d, _e, _f;
11998
+ const { setIsOpen } = useStackedModal();
11999
+ const form = reactHookForm.useForm({
12000
+ resolver: zod.zodResolver(shippingMethodSchema),
12001
+ defaultValues: {
12002
+ 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,
12003
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12004
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12005
+ }
12006
+ });
12007
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12008
+ const {
12009
+ mutateAsync: updateShippingMethod,
12010
+ isPending: isUpdatingShippingMethod
12011
+ } = useDraftOrderUpdateShippingMethod(order.id);
12012
+ const onSubmit = form.handleSubmit(async (values) => {
12013
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12014
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12015
+ return;
12016
+ }
12017
+ if (data.shippingMethod) {
12018
+ await updateShippingMethod(
12019
+ {
12020
+ method_id: data.shippingMethod.id,
12021
+ shipping_option_id: values.shipping_option_id,
12022
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12023
+ },
12024
+ {
12025
+ onError: (e) => {
12026
+ ui.toast.error(e.message);
12027
+ },
12028
+ onSuccess: () => {
12029
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12030
+ }
12031
+ }
12032
+ );
12033
+ return;
12034
+ }
12035
+ await addShippingMethod(
12036
+ {
12037
+ shipping_option_id: values.shipping_option_id,
12038
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12039
+ },
12040
+ {
12041
+ onError: (e) => {
12042
+ ui.toast.error(e.message);
12043
+ },
12044
+ onSuccess: () => {
12045
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12046
+ }
12047
+ }
12048
+ );
12049
+ });
12050
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12051
+ KeyboundForm,
12052
+ {
12053
+ className: "flex h-full flex-col overflow-hidden",
12054
+ onSubmit,
12055
+ children: [
12056
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12057
+ /* @__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 py-16 px-6", children: [
12058
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12059
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12060
+ /* @__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." }) })
12061
+ ] }),
12062
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12063
+ /* @__PURE__ */ jsxRuntime.jsx(
12064
+ LocationField,
12065
+ {
12066
+ control: form.control,
12067
+ setValue: form.setValue
12068
+ }
12069
+ ),
12070
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12071
+ /* @__PURE__ */ jsxRuntime.jsx(
12072
+ ShippingOptionField,
12073
+ {
12074
+ shippingProfileId: data.shippingProfileId,
12075
+ preview,
12076
+ control: form.control
12077
+ }
12078
+ ),
12079
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12080
+ /* @__PURE__ */ jsxRuntime.jsx(
12081
+ CustomAmountField,
12082
+ {
12083
+ control: form.control,
12084
+ currencyCode: order.currency_code
12085
+ }
12086
+ ),
12087
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12088
+ /* @__PURE__ */ jsxRuntime.jsx(
12089
+ ItemsPreview,
12090
+ {
12091
+ order,
12092
+ shippingProfileId: data.shippingProfileId
12093
+ }
12094
+ )
12095
+ ] }) }) }),
12096
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12097
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12098
+ /* @__PURE__ */ jsxRuntime.jsx(
12099
+ ui.Button,
12100
+ {
12101
+ size: "small",
12102
+ type: "submit",
12103
+ isLoading: isPending || isUpdatingShippingMethod,
12104
+ children: data.shippingMethod ? "Update" : "Add"
12105
+ }
12106
+ )
12107
+ ] }) })
12108
+ ]
12109
+ }
12110
+ ) }) });
12111
+ };
12112
+ const shippingMethodSchema = objectType({
12113
+ location_id: stringType(),
12114
+ shipping_option_id: stringType(),
12115
+ custom_amount: unionType([numberType(), stringType()]).optional()
12116
+ });
12117
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12118
+ const matches = order.items.filter(
12119
+ (item) => {
12120
+ var _a, _b, _c;
12121
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12122
+ }
12123
+ );
12124
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12125
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12126
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12127
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12128
+ ] }) }),
12129
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12130
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12131
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12132
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12133
+ ] }),
12134
+ /* @__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(
12135
+ "div",
12648
12136
  {
12649
- size: "small",
12650
- type: "button",
12651
- isLoading: isSubmitting,
12652
- onClick: onSubmit,
12653
- children: "Save"
12654
- }
12655
- )
12656
- ] }) })
12137
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12138
+ children: [
12139
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12140
+ /* @__PURE__ */ jsxRuntime.jsx(
12141
+ Thumbnail,
12142
+ {
12143
+ thumbnail: item.thumbnail,
12144
+ alt: item.product_title ?? void 0
12145
+ }
12146
+ ),
12147
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12148
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12149
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12150
+ /* @__PURE__ */ jsxRuntime.jsxs(
12151
+ ui.Text,
12152
+ {
12153
+ size: "small",
12154
+ leading: "compact",
12155
+ className: "text-ui-fg-subtle",
12156
+ children: [
12157
+ "(",
12158
+ item.variant_title,
12159
+ ")"
12160
+ ]
12161
+ }
12162
+ )
12163
+ ] }),
12164
+ /* @__PURE__ */ jsxRuntime.jsx(
12165
+ ui.Text,
12166
+ {
12167
+ size: "small",
12168
+ leading: "compact",
12169
+ className: "text-ui-fg-subtle",
12170
+ children: item.variant_sku
12171
+ }
12172
+ )
12173
+ ] })
12174
+ ] }),
12175
+ /* @__PURE__ */ jsxRuntime.jsxs(
12176
+ ui.Text,
12177
+ {
12178
+ size: "small",
12179
+ leading: "compact",
12180
+ className: "text-ui-fg-subtle",
12181
+ children: [
12182
+ item.quantity,
12183
+ "x"
12184
+ ]
12185
+ }
12186
+ )
12187
+ ]
12188
+ },
12189
+ item.id
12190
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12191
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12192
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12193
+ 'No items found for "',
12194
+ query,
12195
+ '".'
12196
+ ] })
12197
+ ] }) })
12198
+ ] })
12657
12199
  ] });
12658
12200
  };
12659
- const StackedModalTrigger = ({
12201
+ const LocationField = ({ control, setValue }) => {
12202
+ const locations = useComboboxData({
12203
+ queryKey: ["locations"],
12204
+ queryFn: async (params) => {
12205
+ return await sdk.admin.stockLocation.list(params);
12206
+ },
12207
+ getOptions: (data) => {
12208
+ return data.stock_locations.map((location) => ({
12209
+ label: location.name,
12210
+ value: location.id
12211
+ }));
12212
+ }
12213
+ });
12214
+ return /* @__PURE__ */ jsxRuntime.jsx(
12215
+ Form$2.Field,
12216
+ {
12217
+ control,
12218
+ name: "location_id",
12219
+ render: ({ field: { onChange, ...field } }) => {
12220
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12221
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12222
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12223
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12224
+ ] }),
12225
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12226
+ Combobox,
12227
+ {
12228
+ options: locations.options,
12229
+ fetchNextPage: locations.fetchNextPage,
12230
+ isFetchingNextPage: locations.isFetchingNextPage,
12231
+ searchValue: locations.searchValue,
12232
+ onSearchValueChange: locations.onSearchValueChange,
12233
+ placeholder: "Select location",
12234
+ onChange: (value) => {
12235
+ setValue("shipping_option_id", "", {
12236
+ shouldDirty: true,
12237
+ shouldTouch: true
12238
+ });
12239
+ onChange(value);
12240
+ },
12241
+ ...field
12242
+ }
12243
+ ) })
12244
+ ] }) });
12245
+ }
12246
+ }
12247
+ );
12248
+ };
12249
+ const ShippingOptionField = ({
12660
12250
  shippingProfileId,
12661
- shippingOption,
12662
- shippingMethod,
12663
- setData,
12664
- children
12251
+ preview,
12252
+ control
12665
12253
  }) => {
12666
- const { setIsOpen, getIsOpen } = useStackedModal();
12667
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12668
- const onToggle = () => {
12669
- if (isOpen) {
12670
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12671
- setData(null);
12672
- } else {
12673
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12674
- setData({
12675
- shippingProfileId,
12676
- shippingOption,
12677
- shippingMethod
12254
+ var _a;
12255
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12256
+ const shippingOptions = useComboboxData({
12257
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12258
+ queryFn: async (params) => {
12259
+ return await sdk.admin.shippingOption.list({
12260
+ ...params,
12261
+ stock_location_id: locationId,
12262
+ shipping_profile_id: shippingProfileId
12678
12263
  });
12264
+ },
12265
+ getOptions: (data) => {
12266
+ return data.shipping_options.map((option) => {
12267
+ var _a2;
12268
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12269
+ (r) => r.attribute === "is_return" && r.value === "true"
12270
+ )) {
12271
+ return void 0;
12272
+ }
12273
+ return {
12274
+ label: option.name,
12275
+ value: option.id
12276
+ };
12277
+ }).filter(Boolean);
12278
+ },
12279
+ enabled: !!locationId && !!shippingProfileId,
12280
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12281
+ });
12282
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12283
+ return /* @__PURE__ */ jsxRuntime.jsx(
12284
+ Form$2.Field,
12285
+ {
12286
+ control,
12287
+ name: "shipping_option_id",
12288
+ render: ({ field }) => {
12289
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12290
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12291
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12292
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12293
+ ] }),
12294
+ /* @__PURE__ */ jsxRuntime.jsx(
12295
+ ConditionalTooltip,
12296
+ {
12297
+ content: tooltipContent,
12298
+ showTooltip: !locationId || !shippingProfileId,
12299
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12300
+ Combobox,
12301
+ {
12302
+ options: shippingOptions.options,
12303
+ fetchNextPage: shippingOptions.fetchNextPage,
12304
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12305
+ searchValue: shippingOptions.searchValue,
12306
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12307
+ placeholder: "Select shipping option",
12308
+ ...field,
12309
+ disabled: !locationId || !shippingProfileId
12310
+ }
12311
+ ) }) })
12312
+ }
12313
+ )
12314
+ ] }) });
12315
+ }
12679
12316
  }
12680
- };
12317
+ );
12318
+ };
12319
+ const CustomAmountField = ({
12320
+ control,
12321
+ currencyCode
12322
+ }) => {
12681
12323
  return /* @__PURE__ */ jsxRuntime.jsx(
12682
- ui.Button,
12324
+ Form$2.Field,
12683
12325
  {
12684
- size: "small",
12685
- variant: "secondary",
12686
- onClick: onToggle,
12687
- className: "text-ui-fg-primary shrink-0",
12688
- children
12326
+ control,
12327
+ name: "custom_amount",
12328
+ render: ({ field: { onChange, ...field } }) => {
12329
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12330
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12331
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12332
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12333
+ ] }),
12334
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12335
+ ui.CurrencyInput,
12336
+ {
12337
+ ...field,
12338
+ onValueChange: (value) => onChange(value),
12339
+ symbol: getNativeSymbol(currencyCode),
12340
+ code: currencyCode
12341
+ }
12342
+ ) })
12343
+ ] });
12344
+ }
12689
12345
  }
12690
12346
  );
12691
12347
  };
12692
- const ShippingProfileForm = ({
12693
- data,
12694
- order,
12695
- preview
12696
- }) => {
12697
- var _a, _b, _c, _d, _e, _f;
12698
- const { setIsOpen } = useStackedModal();
12348
+ const ShippingAddress = () => {
12349
+ const { id } = reactRouterDom.useParams();
12350
+ const { order, isPending, isError, error } = useOrder(id, {
12351
+ fields: "+shipping_address"
12352
+ });
12353
+ if (isError) {
12354
+ throw error;
12355
+ }
12356
+ const isReady = !isPending && !!order;
12357
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12358
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12359
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12360
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12361
+ ] }),
12362
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12363
+ ] });
12364
+ };
12365
+ const ShippingAddressForm = ({ order }) => {
12366
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12367
+ const form = reactHookForm.useForm({
12368
+ defaultValues: {
12369
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12370
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12371
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12372
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12373
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12374
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12375
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12376
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12377
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12378
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12379
+ },
12380
+ resolver: zod.zodResolver(schema$2)
12381
+ });
12382
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12383
+ const { handleSuccess } = useRouteModal();
12384
+ const onSubmit = form.handleSubmit(async (data) => {
12385
+ await mutateAsync(
12386
+ {
12387
+ shipping_address: {
12388
+ first_name: data.first_name,
12389
+ last_name: data.last_name,
12390
+ company: data.company,
12391
+ address_1: data.address_1,
12392
+ address_2: data.address_2,
12393
+ city: data.city,
12394
+ province: data.province,
12395
+ country_code: data.country_code,
12396
+ postal_code: data.postal_code,
12397
+ phone: data.phone
12398
+ }
12399
+ },
12400
+ {
12401
+ onSuccess: () => {
12402
+ handleSuccess();
12403
+ },
12404
+ onError: (error) => {
12405
+ ui.toast.error(error.message);
12406
+ }
12407
+ }
12408
+ );
12409
+ });
12410
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12411
+ KeyboundForm,
12412
+ {
12413
+ className: "flex flex-1 flex-col overflow-hidden",
12414
+ onSubmit,
12415
+ children: [
12416
+ /* @__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: [
12417
+ /* @__PURE__ */ jsxRuntime.jsx(
12418
+ Form$2.Field,
12419
+ {
12420
+ control: form.control,
12421
+ name: "country_code",
12422
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12423
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12424
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12425
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12426
+ ] })
12427
+ }
12428
+ ),
12429
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12430
+ /* @__PURE__ */ jsxRuntime.jsx(
12431
+ Form$2.Field,
12432
+ {
12433
+ control: form.control,
12434
+ name: "first_name",
12435
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12436
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12437
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12438
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12439
+ ] })
12440
+ }
12441
+ ),
12442
+ /* @__PURE__ */ jsxRuntime.jsx(
12443
+ Form$2.Field,
12444
+ {
12445
+ control: form.control,
12446
+ name: "last_name",
12447
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12448
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12449
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12450
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12451
+ ] })
12452
+ }
12453
+ )
12454
+ ] }),
12455
+ /* @__PURE__ */ jsxRuntime.jsx(
12456
+ Form$2.Field,
12457
+ {
12458
+ control: form.control,
12459
+ name: "company",
12460
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12461
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12462
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12464
+ ] })
12465
+ }
12466
+ ),
12467
+ /* @__PURE__ */ jsxRuntime.jsx(
12468
+ Form$2.Field,
12469
+ {
12470
+ control: form.control,
12471
+ name: "address_1",
12472
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12473
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12474
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12475
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12476
+ ] })
12477
+ }
12478
+ ),
12479
+ /* @__PURE__ */ jsxRuntime.jsx(
12480
+ Form$2.Field,
12481
+ {
12482
+ control: form.control,
12483
+ name: "address_2",
12484
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12485
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12486
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12487
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12488
+ ] })
12489
+ }
12490
+ ),
12491
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12492
+ /* @__PURE__ */ jsxRuntime.jsx(
12493
+ Form$2.Field,
12494
+ {
12495
+ control: form.control,
12496
+ name: "postal_code",
12497
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12498
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12499
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12500
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12501
+ ] })
12502
+ }
12503
+ ),
12504
+ /* @__PURE__ */ jsxRuntime.jsx(
12505
+ Form$2.Field,
12506
+ {
12507
+ control: form.control,
12508
+ name: "city",
12509
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12510
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12511
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12512
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12513
+ ] })
12514
+ }
12515
+ )
12516
+ ] }),
12517
+ /* @__PURE__ */ jsxRuntime.jsx(
12518
+ Form$2.Field,
12519
+ {
12520
+ control: form.control,
12521
+ name: "province",
12522
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12523
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12524
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12526
+ ] })
12527
+ }
12528
+ ),
12529
+ /* @__PURE__ */ jsxRuntime.jsx(
12530
+ Form$2.Field,
12531
+ {
12532
+ control: form.control,
12533
+ name: "phone",
12534
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12535
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12536
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12537
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12538
+ ] })
12539
+ }
12540
+ )
12541
+ ] }) }),
12542
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12543
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12544
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12545
+ ] }) })
12546
+ ]
12547
+ }
12548
+ ) });
12549
+ };
12550
+ const schema$2 = addressSchema;
12551
+ const TransferOwnership = () => {
12552
+ const { id } = reactRouterDom.useParams();
12553
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12554
+ fields: "id,customer_id,customer.*"
12555
+ });
12556
+ if (isError) {
12557
+ throw error;
12558
+ }
12559
+ const isReady = !isPending && !!draft_order;
12560
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12561
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12562
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12564
+ ] }),
12565
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12566
+ ] });
12567
+ };
12568
+ const TransferOwnershipForm = ({ order }) => {
12569
+ var _a, _b;
12699
12570
  const form = reactHookForm.useForm({
12700
- resolver: zod.zodResolver(shippingMethodSchema),
12701
12571
  defaultValues: {
12702
- 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,
12703
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12704
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12705
- }
12572
+ customer_id: order.customer_id || ""
12573
+ },
12574
+ resolver: zod.zodResolver(schema$1)
12706
12575
  });
12707
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12708
- const {
12709
- mutateAsync: updateShippingMethod,
12710
- isPending: isUpdatingShippingMethod
12711
- } = useDraftOrderUpdateShippingMethod(order.id);
12712
- const onSubmit = form.handleSubmit(async (values) => {
12713
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12714
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12715
- return;
12716
- }
12717
- if (data.shippingMethod) {
12718
- await updateShippingMethod(
12719
- {
12720
- method_id: data.shippingMethod.id,
12721
- shipping_option_id: values.shipping_option_id,
12722
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12723
- },
12724
- {
12725
- onError: (e) => {
12726
- ui.toast.error(e.message);
12727
- },
12728
- onSuccess: () => {
12729
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12730
- }
12731
- }
12732
- );
12733
- return;
12734
- }
12735
- await addShippingMethod(
12736
- {
12737
- shipping_option_id: values.shipping_option_id,
12738
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12739
- },
12576
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12577
+ const { handleSuccess } = useRouteModal();
12578
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12579
+ const currentCustomer = order.customer ? {
12580
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12581
+ value: order.customer.id
12582
+ } : null;
12583
+ const onSubmit = form.handleSubmit(async (data) => {
12584
+ await mutateAsync(
12585
+ { customer_id: data.customer_id },
12740
12586
  {
12741
- onError: (e) => {
12742
- ui.toast.error(e.message);
12743
- },
12744
12587
  onSuccess: () => {
12745
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12588
+ ui.toast.success("Customer updated");
12589
+ handleSuccess();
12590
+ },
12591
+ onError: (error) => {
12592
+ ui.toast.error(error.message);
12746
12593
  }
12747
12594
  }
12748
12595
  );
12749
12596
  });
12750
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12597
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12751
12598
  KeyboundForm,
12752
12599
  {
12753
- className: "flex h-full flex-col overflow-hidden",
12600
+ className: "flex flex-1 flex-col overflow-hidden",
12754
12601
  onSubmit,
12755
12602
  children: [
12756
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12757
- /* @__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 py-16 px-6", children: [
12758
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12759
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12760
- /* @__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." }) })
12603
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12604
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12605
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12606
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12607
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12608
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12609
+ ] }),
12610
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12611
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12612
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12613
+ ] })
12761
12614
  ] }),
12762
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12763
- /* @__PURE__ */ jsxRuntime.jsx(
12764
- LocationField,
12765
- {
12766
- control: form.control,
12767
- setValue: form.setValue
12768
- }
12769
- ),
12770
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12771
- /* @__PURE__ */ jsxRuntime.jsx(
12772
- ShippingOptionField,
12773
- {
12774
- shippingProfileId: data.shippingProfileId,
12775
- preview,
12776
- control: form.control
12777
- }
12778
- ),
12779
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12780
12615
  /* @__PURE__ */ jsxRuntime.jsx(
12781
- CustomAmountField,
12616
+ CustomerField,
12782
12617
  {
12783
12618
  control: form.control,
12784
- currencyCode: order.currency_code
12785
- }
12786
- ),
12787
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12788
- /* @__PURE__ */ jsxRuntime.jsx(
12789
- ItemsPreview,
12790
- {
12791
- order,
12792
- shippingProfileId: data.shippingProfileId
12793
- }
12794
- )
12795
- ] }) }) }),
12796
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12797
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12798
- /* @__PURE__ */ jsxRuntime.jsx(
12799
- ui.Button,
12800
- {
12801
- size: "small",
12802
- type: "submit",
12803
- isLoading: isPending || isUpdatingShippingMethod,
12804
- children: data.shippingMethod ? "Update" : "Add"
12619
+ currentCustomerId: order.customer_id
12805
12620
  }
12806
12621
  )
12622
+ ] }),
12623
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12624
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12625
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12807
12626
  ] }) })
12808
12627
  ]
12809
12628
  }
12810
- ) }) });
12811
- };
12812
- const shippingMethodSchema = objectType({
12813
- location_id: stringType(),
12814
- shipping_option_id: stringType(),
12815
- custom_amount: unionType([numberType(), stringType()]).optional()
12816
- });
12817
- const ItemsPreview = ({ order, shippingProfileId }) => {
12818
- const matches = order.items.filter(
12819
- (item) => {
12820
- var _a, _b, _c;
12821
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12822
- }
12823
- );
12824
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12825
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12826
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12827
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12828
- ] }) }),
12829
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12830
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12831
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12832
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12833
- ] }),
12834
- /* @__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(
12835
- "div",
12836
- {
12837
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12838
- children: [
12839
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12840
- /* @__PURE__ */ jsxRuntime.jsx(
12841
- Thumbnail,
12842
- {
12843
- thumbnail: item.thumbnail,
12844
- alt: item.product_title ?? void 0
12845
- }
12846
- ),
12847
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12848
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12849
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12850
- /* @__PURE__ */ jsxRuntime.jsxs(
12851
- ui.Text,
12852
- {
12853
- size: "small",
12854
- leading: "compact",
12855
- className: "text-ui-fg-subtle",
12856
- children: [
12857
- "(",
12858
- item.variant_title,
12859
- ")"
12860
- ]
12861
- }
12862
- )
12863
- ] }),
12864
- /* @__PURE__ */ jsxRuntime.jsx(
12865
- ui.Text,
12866
- {
12867
- size: "small",
12868
- leading: "compact",
12869
- className: "text-ui-fg-subtle",
12870
- children: item.variant_sku
12871
- }
12872
- )
12873
- ] })
12874
- ] }),
12875
- /* @__PURE__ */ jsxRuntime.jsxs(
12876
- ui.Text,
12877
- {
12878
- size: "small",
12879
- leading: "compact",
12880
- className: "text-ui-fg-subtle",
12881
- children: [
12882
- item.quantity,
12883
- "x"
12884
- ]
12885
- }
12886
- )
12887
- ]
12888
- },
12889
- item.id
12890
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12891
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12892
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12893
- 'No items found for "',
12894
- query,
12895
- '".'
12896
- ] })
12897
- ] }) })
12898
- ] })
12899
- ] });
12629
+ ) });
12900
12630
  };
12901
- const LocationField = ({ control, setValue }) => {
12902
- const locations = useComboboxData({
12903
- queryKey: ["locations"],
12631
+ const CustomerField = ({ control, currentCustomerId }) => {
12632
+ const customers = useComboboxData({
12904
12633
  queryFn: async (params) => {
12905
- return await sdk.admin.stockLocation.list(params);
12634
+ return await sdk.admin.customer.list({
12635
+ ...params,
12636
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12637
+ });
12906
12638
  },
12639
+ queryKey: ["customers"],
12907
12640
  getOptions: (data) => {
12908
- return data.stock_locations.map((location) => ({
12909
- label: location.name,
12910
- value: location.id
12911
- }));
12641
+ return data.customers.map((customer) => {
12642
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12643
+ return {
12644
+ label: name ? `${name} (${customer.email})` : customer.email,
12645
+ value: customer.id
12646
+ };
12647
+ });
12648
+ }
12649
+ });
12650
+ return /* @__PURE__ */ jsxRuntime.jsx(
12651
+ Form$2.Field,
12652
+ {
12653
+ name: "customer_id",
12654
+ control,
12655
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12656
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12657
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12658
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12659
+ ] }),
12660
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12661
+ Combobox,
12662
+ {
12663
+ options: customers.options,
12664
+ fetchNextPage: customers.fetchNextPage,
12665
+ isFetchingNextPage: customers.isFetchingNextPage,
12666
+ searchValue: customers.searchValue,
12667
+ onSearchValueChange: customers.onSearchValueChange,
12668
+ placeholder: "Select customer",
12669
+ ...field
12670
+ }
12671
+ ) }),
12672
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12673
+ ] })
12912
12674
  }
12913
- });
12914
- return /* @__PURE__ */ jsxRuntime.jsx(
12915
- Form$2.Field,
12675
+ );
12676
+ };
12677
+ const Illustration = () => {
12678
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12679
+ "svg",
12916
12680
  {
12917
- control,
12918
- name: "location_id",
12919
- render: ({ field: { onChange, ...field } }) => {
12920
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12921
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12922
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12923
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12924
- ] }),
12925
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12926
- Combobox,
12681
+ width: "280",
12682
+ height: "180",
12683
+ viewBox: "0 0 280 180",
12684
+ fill: "none",
12685
+ xmlns: "http://www.w3.org/2000/svg",
12686
+ children: [
12687
+ /* @__PURE__ */ jsxRuntime.jsx(
12688
+ "rect",
12689
+ {
12690
+ x: "0.00428286",
12691
+ y: "-0.742904",
12692
+ width: "33.5",
12693
+ height: "65.5",
12694
+ rx: "6.75",
12695
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12696
+ fill: "#D4D4D8",
12697
+ stroke: "#52525B",
12698
+ strokeWidth: "1.5"
12699
+ }
12700
+ ),
12701
+ /* @__PURE__ */ jsxRuntime.jsx(
12702
+ "rect",
12703
+ {
12704
+ x: "0.00428286",
12705
+ y: "-0.742904",
12706
+ width: "33.5",
12707
+ height: "65.5",
12708
+ rx: "6.75",
12709
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12710
+ fill: "white",
12711
+ stroke: "#52525B",
12712
+ strokeWidth: "1.5"
12713
+ }
12714
+ ),
12715
+ /* @__PURE__ */ jsxRuntime.jsx(
12716
+ "path",
12717
+ {
12718
+ d: "M180.579 107.142L179.126 107.959",
12719
+ stroke: "#52525B",
12720
+ strokeWidth: "1.5",
12721
+ strokeLinecap: "round",
12722
+ strokeLinejoin: "round"
12723
+ }
12724
+ ),
12725
+ /* @__PURE__ */ jsxRuntime.jsx(
12726
+ "path",
12727
+ {
12728
+ opacity: "0.88",
12729
+ d: "M182.305 109.546L180.257 109.534",
12730
+ stroke: "#52525B",
12731
+ strokeWidth: "1.5",
12732
+ strokeLinecap: "round",
12733
+ strokeLinejoin: "round"
12734
+ }
12735
+ ),
12736
+ /* @__PURE__ */ jsxRuntime.jsx(
12737
+ "path",
12738
+ {
12739
+ opacity: "0.75",
12740
+ d: "M180.551 111.93L179.108 111.096",
12741
+ stroke: "#52525B",
12742
+ strokeWidth: "1.5",
12743
+ strokeLinecap: "round",
12744
+ strokeLinejoin: "round"
12745
+ }
12746
+ ),
12747
+ /* @__PURE__ */ jsxRuntime.jsx(
12748
+ "path",
12749
+ {
12750
+ opacity: "0.63",
12751
+ d: "M176.347 112.897L176.354 111.73",
12752
+ stroke: "#52525B",
12753
+ strokeWidth: "1.5",
12754
+ strokeLinecap: "round",
12755
+ strokeLinejoin: "round"
12756
+ }
12757
+ ),
12758
+ /* @__PURE__ */ jsxRuntime.jsx(
12759
+ "path",
12760
+ {
12761
+ opacity: "0.5",
12762
+ d: "M172.153 111.881L173.606 111.064",
12763
+ stroke: "#52525B",
12764
+ strokeWidth: "1.5",
12765
+ strokeLinecap: "round",
12766
+ strokeLinejoin: "round"
12767
+ }
12768
+ ),
12769
+ /* @__PURE__ */ jsxRuntime.jsx(
12770
+ "path",
12771
+ {
12772
+ opacity: "0.38",
12773
+ d: "M170.428 109.478L172.476 109.489",
12774
+ stroke: "#52525B",
12775
+ strokeWidth: "1.5",
12776
+ strokeLinecap: "round",
12777
+ strokeLinejoin: "round"
12778
+ }
12779
+ ),
12780
+ /* @__PURE__ */ jsxRuntime.jsx(
12781
+ "path",
12782
+ {
12783
+ opacity: "0.25",
12784
+ d: "M172.181 107.094L173.624 107.928",
12785
+ stroke: "#52525B",
12786
+ strokeWidth: "1.5",
12787
+ strokeLinecap: "round",
12788
+ strokeLinejoin: "round"
12789
+ }
12790
+ ),
12791
+ /* @__PURE__ */ jsxRuntime.jsx(
12792
+ "path",
12793
+ {
12794
+ opacity: "0.13",
12795
+ d: "M176.386 106.126L176.379 107.294",
12796
+ stroke: "#52525B",
12797
+ strokeWidth: "1.5",
12798
+ strokeLinecap: "round",
12799
+ strokeLinejoin: "round"
12800
+ }
12801
+ ),
12802
+ /* @__PURE__ */ jsxRuntime.jsx(
12803
+ "rect",
12804
+ {
12805
+ width: "12",
12806
+ height: "3",
12807
+ rx: "1.5",
12808
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12809
+ fill: "#D4D4D8"
12810
+ }
12811
+ ),
12812
+ /* @__PURE__ */ jsxRuntime.jsx(
12813
+ "rect",
12814
+ {
12815
+ x: "0.00428286",
12816
+ y: "-0.742904",
12817
+ width: "33.5",
12818
+ height: "65.5",
12819
+ rx: "6.75",
12820
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12821
+ fill: "#D4D4D8",
12822
+ stroke: "#52525B",
12823
+ strokeWidth: "1.5"
12824
+ }
12825
+ ),
12826
+ /* @__PURE__ */ jsxRuntime.jsx(
12827
+ "rect",
12828
+ {
12829
+ x: "0.00428286",
12830
+ y: "-0.742904",
12831
+ width: "33.5",
12832
+ height: "65.5",
12833
+ rx: "6.75",
12834
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12835
+ fill: "white",
12836
+ stroke: "#52525B",
12837
+ strokeWidth: "1.5"
12838
+ }
12839
+ ),
12840
+ /* @__PURE__ */ jsxRuntime.jsx(
12841
+ "rect",
12842
+ {
12843
+ width: "12",
12844
+ height: "3",
12845
+ rx: "1.5",
12846
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12847
+ fill: "#D4D4D8"
12848
+ }
12849
+ ),
12850
+ /* @__PURE__ */ jsxRuntime.jsx(
12851
+ "rect",
12852
+ {
12853
+ width: "17",
12854
+ height: "3",
12855
+ rx: "1.5",
12856
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12857
+ fill: "#D4D4D8"
12858
+ }
12859
+ ),
12860
+ /* @__PURE__ */ jsxRuntime.jsx(
12861
+ "rect",
12862
+ {
12863
+ width: "12",
12864
+ height: "3",
12865
+ rx: "1.5",
12866
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12867
+ fill: "#D4D4D8"
12868
+ }
12869
+ ),
12870
+ /* @__PURE__ */ jsxRuntime.jsx(
12871
+ "path",
12872
+ {
12873
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12874
+ fill: "#A1A1AA"
12875
+ }
12876
+ ),
12877
+ /* @__PURE__ */ jsxRuntime.jsx(
12878
+ "rect",
12879
+ {
12880
+ width: "17",
12881
+ height: "3",
12882
+ rx: "1.5",
12883
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12884
+ fill: "#A1A1AA"
12885
+ }
12886
+ ),
12887
+ /* @__PURE__ */ jsxRuntime.jsx(
12888
+ "rect",
12889
+ {
12890
+ width: "12",
12891
+ height: "3",
12892
+ rx: "1.5",
12893
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12894
+ fill: "#A1A1AA"
12895
+ }
12896
+ ),
12897
+ /* @__PURE__ */ jsxRuntime.jsx(
12898
+ "path",
12899
+ {
12900
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12901
+ fill: "#52525B"
12902
+ }
12903
+ ),
12904
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12905
+ "path",
12906
+ {
12907
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12908
+ stroke: "#A1A1AA",
12909
+ strokeWidth: "1.5",
12910
+ strokeLinecap: "round",
12911
+ strokeLinejoin: "round"
12912
+ }
12913
+ ) }),
12914
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12915
+ "path",
12916
+ {
12917
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12918
+ stroke: "#A1A1AA",
12919
+ strokeWidth: "1.5",
12920
+ strokeLinecap: "round",
12921
+ strokeLinejoin: "round"
12922
+ }
12923
+ ) }),
12924
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12925
+ "path",
12926
+ {
12927
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12928
+ stroke: "#A1A1AA",
12929
+ strokeWidth: "1.5",
12930
+ strokeLinecap: "round",
12931
+ strokeLinejoin: "round"
12932
+ }
12933
+ ) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12935
+ "path",
12936
+ {
12937
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12938
+ stroke: "#A1A1AA",
12939
+ strokeWidth: "1.5",
12940
+ strokeLinecap: "round",
12941
+ strokeLinejoin: "round"
12942
+ }
12943
+ ) }),
12944
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12945
+ "path",
12946
+ {
12947
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12948
+ stroke: "#A1A1AA",
12949
+ strokeWidth: "1.5",
12950
+ strokeLinecap: "round",
12951
+ strokeLinejoin: "round"
12952
+ }
12953
+ ) }),
12954
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12955
+ "path",
12956
+ {
12957
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12958
+ stroke: "#A1A1AA",
12959
+ strokeWidth: "1.5",
12960
+ strokeLinecap: "round",
12961
+ strokeLinejoin: "round"
12962
+ }
12963
+ ) }),
12964
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12965
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12966
+ "rect",
12927
12967
  {
12928
- options: locations.options,
12929
- fetchNextPage: locations.fetchNextPage,
12930
- isFetchingNextPage: locations.isFetchingNextPage,
12931
- searchValue: locations.searchValue,
12932
- onSearchValueChange: locations.onSearchValueChange,
12933
- placeholder: "Select location",
12934
- onChange: (value) => {
12935
- setValue("shipping_option_id", "", {
12936
- shouldDirty: true,
12937
- shouldTouch: true
12938
- });
12939
- onChange(value);
12940
- },
12941
- ...field
12968
+ width: "12",
12969
+ height: "12",
12970
+ fill: "white",
12971
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12942
12972
  }
12943
- ) })
12944
- ] }) });
12945
- }
12946
- }
12947
- );
12948
- };
12949
- const ShippingOptionField = ({
12950
- shippingProfileId,
12951
- preview,
12952
- control
12953
- }) => {
12954
- var _a;
12955
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12956
- const shippingOptions = useComboboxData({
12957
- queryKey: ["shipping_options", locationId, shippingProfileId],
12958
- queryFn: async (params) => {
12959
- return await sdk.admin.shippingOption.list({
12960
- ...params,
12961
- stock_location_id: locationId,
12962
- shipping_profile_id: shippingProfileId
12963
- });
12964
- },
12965
- getOptions: (data) => {
12966
- return data.shipping_options.map((option) => {
12967
- var _a2;
12968
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12969
- (r) => r.attribute === "is_return" && r.value === "true"
12970
- )) {
12971
- return void 0;
12972
- }
12973
- return {
12974
- label: option.name,
12975
- value: option.id
12976
- };
12977
- }).filter(Boolean);
12978
- },
12979
- enabled: !!locationId && !!shippingProfileId,
12980
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12981
- });
12982
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12983
- return /* @__PURE__ */ jsxRuntime.jsx(
12984
- Form$2.Field,
12985
- {
12986
- control,
12987
- name: "shipping_option_id",
12988
- render: ({ field }) => {
12989
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12990
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12991
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12992
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12993
- ] }),
12994
- /* @__PURE__ */ jsxRuntime.jsx(
12995
- ConditionalTooltip,
12973
+ ) }),
12974
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12975
+ "rect",
12996
12976
  {
12997
- content: tooltipContent,
12998
- showTooltip: !locationId || !shippingProfileId,
12999
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13000
- Combobox,
13001
- {
13002
- options: shippingOptions.options,
13003
- fetchNextPage: shippingOptions.fetchNextPage,
13004
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
13005
- searchValue: shippingOptions.searchValue,
13006
- onSearchValueChange: shippingOptions.onSearchValueChange,
13007
- placeholder: "Select shipping option",
13008
- ...field,
13009
- disabled: !locationId || !shippingProfileId
13010
- }
13011
- ) }) })
12977
+ width: "12",
12978
+ height: "12",
12979
+ fill: "white",
12980
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13012
12981
  }
13013
- )
13014
- ] }) });
13015
- }
13016
- }
13017
- );
13018
- };
13019
- const CustomAmountField = ({
13020
- control,
13021
- currencyCode
13022
- }) => {
13023
- return /* @__PURE__ */ jsxRuntime.jsx(
13024
- Form$2.Field,
13025
- {
13026
- control,
13027
- name: "custom_amount",
13028
- render: ({ field: { onChange, ...field } }) => {
13029
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13030
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
13033
- ] }),
13034
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13035
- ui.CurrencyInput,
12982
+ ) }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12984
+ "rect",
13036
12985
  {
13037
- ...field,
13038
- onValueChange: (value) => onChange(value),
13039
- symbol: getNativeSymbol(currencyCode),
13040
- code: currencyCode
12986
+ width: "12",
12987
+ height: "12",
12988
+ fill: "white",
12989
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12990
+ }
12991
+ ) }),
12992
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12993
+ "rect",
12994
+ {
12995
+ width: "12",
12996
+ height: "12",
12997
+ fill: "white",
12998
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12999
+ }
13000
+ ) }),
13001
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13002
+ "rect",
13003
+ {
13004
+ width: "12",
13005
+ height: "12",
13006
+ fill: "white",
13007
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13008
+ }
13009
+ ) }),
13010
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13011
+ "rect",
13012
+ {
13013
+ width: "12",
13014
+ height: "12",
13015
+ fill: "white",
13016
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13041
13017
  }
13042
13018
  ) })
13043
- ] });
13044
- }
13019
+ ] })
13020
+ ]
13045
13021
  }
13046
13022
  );
13047
13023
  };
13024
+ const schema$1 = objectType({
13025
+ customer_id: stringType().min(1)
13026
+ });
13027
+ const CustomItems = () => {
13028
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13029
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
13030
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
13031
+ ] });
13032
+ };
13033
+ const CustomItemsForm = () => {
13034
+ const form = reactHookForm.useForm({
13035
+ resolver: zod.zodResolver(schema)
13036
+ });
13037
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
13042
+ ] }) })
13043
+ ] }) });
13044
+ };
13045
+ const schema = objectType({
13046
+ email: stringType().email()
13047
+ });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13069,10 +13069,6 @@ const routeModule = {
13069
13069
  Component: BillingAddress,
13070
13070
  path: "/draft-orders/:id/billing-address"
13071
13071
  },
13072
- {
13073
- Component: CustomItems,
13074
- path: "/draft-orders/:id/custom-items"
13075
- },
13076
13072
  {
13077
13073
  Component: Email,
13078
13074
  path: "/draft-orders/:id/email"
@@ -13093,6 +13089,10 @@ const routeModule = {
13093
13089
  Component: SalesChannel,
13094
13090
  path: "/draft-orders/:id/sales-channel"
13095
13091
  },
13092
+ {
13093
+ Component: Shipping,
13094
+ path: "/draft-orders/:id/shipping"
13095
+ },
13096
13096
  {
13097
13097
  Component: ShippingAddress,
13098
13098
  path: "/draft-orders/:id/shipping-address"
@@ -13102,8 +13102,8 @@ const routeModule = {
13102
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
13103
  },
13104
13104
  {
13105
- Component: Shipping,
13106
- path: "/draft-orders/:id/shipping"
13105
+ Component: CustomItems,
13106
+ path: "/draft-orders/:id/custom-items"
13107
13107
  }
13108
13108
  ]
13109
13109
  }