@medusajs/draft-order 2.10.2-preview-20250902060151 → 2.10.2-preview-20250902091941

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