@medusajs/draft-order 2.11.2-preview-20251026090153 → 2.11.2-preview-20251026120206

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