@medusajs/draft-order 2.12.4-preview-20251218120153 → 2.12.4-preview-20251218150207

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