@medusajs/draft-order 2.12.0-preview-20251103150145 → 3.0.0-snapshot-20251104004624

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