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