@medusajs/draft-order 2.10.2-snapshot-20250902175701 → 2.10.2-snapshot-20250903073427

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.
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { defineRouteConfig } from "@medusajs/admin-sdk";
3
- import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as DataTable$1, Heading, Text, Button, createDataTableFilterHelper, createDataTableColumnHelper, Container, Badge, Skeleton, Avatar, Label as Label$1, Hint as Hint$1, Prompt, Drawer, FocusModal, toast, Divider, Input, Switch, Copy, Kbd, StatusBadge, usePrompt, Select, CurrencyInput } from "@medusajs/ui";
3
+ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as DataTable$1, Heading, Text, Button, createDataTableFilterHelper, createDataTableColumnHelper, Container, Badge, Skeleton, Avatar, Label as Label$1, Hint as Hint$1, Prompt, Drawer, FocusModal, toast, Divider, Input, Switch, Copy, Kbd, StatusBadge, usePrompt, CurrencyInput, Select } from "@medusajs/ui";
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
@@ -9554,27 +9554,6 @@ const ID = () => {
9554
9554
  /* @__PURE__ */ jsx(Outlet, {})
9555
9555
  ] });
9556
9556
  };
9557
- const CustomItems = () => {
9558
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9559
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9560
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9561
- ] });
9562
- };
9563
- const CustomItemsForm = () => {
9564
- const form = useForm({
9565
- resolver: zodResolver(schema$5)
9566
- });
9567
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9568
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9569
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9570
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9571
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9572
- ] }) })
9573
- ] }) });
9574
- };
9575
- const schema$5 = objectType({
9576
- email: stringType().email()
9577
- });
9578
9557
  const BillingAddress = () => {
9579
9558
  const { id } = useParams();
9580
9559
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9607,7 +9586,7 @@ const BillingAddressForm = ({ order }) => {
9607
9586
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9608
9587
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9609
9588
  },
9610
- resolver: zodResolver(schema$4)
9589
+ resolver: zodResolver(schema$5)
9611
9590
  });
9612
9591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9613
9592
  const { handleSuccess } = useRouteModal();
@@ -9764,73 +9743,26 @@ const BillingAddressForm = ({ order }) => {
9764
9743
  }
9765
9744
  ) });
9766
9745
  };
9767
- const schema$4 = addressSchema;
9768
- const Email = () => {
9769
- const { id } = useParams();
9770
- const { order, isPending, isError, error } = useOrder(id, {
9771
- fields: "+email"
9772
- });
9773
- if (isError) {
9774
- throw error;
9775
- }
9776
- const isReady = !isPending && !!order;
9746
+ const schema$5 = addressSchema;
9747
+ const CustomItems = () => {
9777
9748
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9778
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9779
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9780
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9781
- ] }),
9782
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9749
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9750
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9783
9751
  ] });
9784
9752
  };
9785
- const EmailForm = ({ order }) => {
9753
+ const CustomItemsForm = () => {
9786
9754
  const form = useForm({
9787
- defaultValues: {
9788
- email: order.email ?? ""
9789
- },
9790
- resolver: zodResolver(schema$3)
9791
- });
9792
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
- const { handleSuccess } = useRouteModal();
9794
- const onSubmit = form.handleSubmit(async (data) => {
9795
- await mutateAsync(
9796
- { email: data.email },
9797
- {
9798
- onSuccess: () => {
9799
- handleSuccess();
9800
- },
9801
- onError: (error) => {
9802
- toast.error(error.message);
9803
- }
9804
- }
9805
- );
9755
+ resolver: zodResolver(schema$4)
9806
9756
  });
9807
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9808
- KeyboundForm,
9809
- {
9810
- className: "flex flex-1 flex-col overflow-hidden",
9811
- onSubmit,
9812
- children: [
9813
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9814
- Form$2.Field,
9815
- {
9816
- control: form.control,
9817
- name: "email",
9818
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9819
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9820
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9821
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9822
- ] })
9823
- }
9824
- ) }),
9825
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9826
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9827
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9828
- ] }) })
9829
- ]
9830
- }
9831
- ) });
9757
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9758
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9759
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9760
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9761
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9762
+ ] }) })
9763
+ ] }) });
9832
9764
  };
9833
- const schema$3 = objectType({
9765
+ const schema$4 = objectType({
9834
9766
  email: stringType().email()
9835
9767
  });
9836
9768
  const InlineTip = forwardRef(
@@ -10534,7 +10466,7 @@ const SalesChannelForm = ({ order }) => {
10534
10466
  defaultValues: {
10535
10467
  sales_channel_id: order.sales_channel_id || ""
10536
10468
  },
10537
- resolver: zodResolver(schema$2)
10469
+ resolver: zodResolver(schema$3)
10538
10470
  });
10539
10471
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10540
10472
  const { handleSuccess } = useRouteModal();
@@ -10609,1498 +10541,1566 @@ const SalesChannelField = ({ control, order }) => {
10609
10541
  }
10610
10542
  );
10611
10543
  };
10612
- const schema$2 = objectType({
10544
+ const schema$3 = objectType({
10613
10545
  sales_channel_id: stringType().min(1)
10614
10546
  });
10615
- const ShippingAddress = () => {
10547
+ function convertNumber(value) {
10548
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10549
+ }
10550
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
10551
+ const Shipping = () => {
10552
+ var _a;
10616
10553
  const { id } = useParams();
10617
10554
  const { order, isPending, isError, error } = useOrder(id, {
10618
- fields: "+shipping_address"
10555
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
10619
10556
  });
10557
+ const {
10558
+ order: preview,
10559
+ isPending: isPreviewPending,
10560
+ isError: isPreviewError,
10561
+ error: previewError
10562
+ } = useOrderPreview(id);
10563
+ useInitiateOrderEdit({ preview });
10564
+ const { onCancel } = useCancelOrderEdit({ preview });
10620
10565
  if (isError) {
10621
10566
  throw error;
10622
10567
  }
10623
- const isReady = !isPending && !!order;
10624
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10625
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10626
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
10627
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
10628
- ] }),
10629
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
10630
- ] });
10568
+ if (isPreviewError) {
10569
+ throw previewError;
10570
+ }
10571
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
10572
+ const isReady = preview && !isPreviewPending && order && !isPending;
10573
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
10574
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10575
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
10576
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
10577
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
10578
+ ] }) }) }),
10579
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
10580
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
10581
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
10582
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10583
+ ] }) });
10631
10584
  };
10632
- const ShippingAddressForm = ({ order }) => {
10633
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10634
- const form = useForm({
10635
- defaultValues: {
10636
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
10637
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
10638
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
10639
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
10640
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
10641
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
10642
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
10643
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
10644
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
10645
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
10585
+ const ShippingForm = ({ preview, order }) => {
10586
+ var _a;
10587
+ const { setIsOpen } = useStackedModal();
10588
+ const [isSubmitting, setIsSubmitting] = useState(false);
10589
+ const [data, setData] = useState(null);
10590
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
10591
+ const { shipping_options } = useShippingOptions(
10592
+ {
10593
+ id: appliedShippingOptionIds,
10594
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
10646
10595
  },
10647
- resolver: zodResolver(schema$1)
10648
- });
10649
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10596
+ {
10597
+ enabled: appliedShippingOptionIds.length > 0
10598
+ }
10599
+ );
10600
+ const uniqueShippingProfiles = useMemo(() => {
10601
+ const profiles = /* @__PURE__ */ new Map();
10602
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
10603
+ profiles.set(profile.id, profile);
10604
+ });
10605
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
10606
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
10607
+ });
10608
+ return Array.from(profiles.values());
10609
+ }, [order.items, shipping_options]);
10650
10610
  const { handleSuccess } = useRouteModal();
10651
- const onSubmit = form.handleSubmit(async (data) => {
10652
- await mutateAsync(
10653
- {
10654
- shipping_address: {
10655
- first_name: data.first_name,
10656
- last_name: data.last_name,
10657
- company: data.company,
10658
- address_1: data.address_1,
10659
- address_2: data.address_2,
10660
- city: data.city,
10661
- province: data.province,
10662
- country_code: data.country_code,
10663
- postal_code: data.postal_code,
10664
- phone: data.phone
10665
- }
10611
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10612
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10613
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
10614
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
10615
+ const onSubmit = async () => {
10616
+ setIsSubmitting(true);
10617
+ let requestSucceeded = false;
10618
+ await requestOrderEdit(void 0, {
10619
+ onError: (e) => {
10620
+ toast.error(`Failed to request order edit: ${e.message}`);
10666
10621
  },
10667
- {
10668
- onSuccess: () => {
10669
- handleSuccess();
10670
- },
10671
- onError: (error) => {
10672
- toast.error(error.message);
10622
+ onSuccess: () => {
10623
+ requestSucceeded = true;
10624
+ }
10625
+ });
10626
+ if (!requestSucceeded) {
10627
+ setIsSubmitting(false);
10628
+ return;
10629
+ }
10630
+ await confirmOrderEdit(void 0, {
10631
+ onError: (e) => {
10632
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10633
+ },
10634
+ onSuccess: () => {
10635
+ handleSuccess();
10636
+ },
10637
+ onSettled: () => {
10638
+ setIsSubmitting(false);
10639
+ }
10640
+ });
10641
+ };
10642
+ const onKeydown = useCallback(
10643
+ (e) => {
10644
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10645
+ if (data || isSubmitting) {
10646
+ return;
10673
10647
  }
10648
+ onSubmit();
10674
10649
  }
10675
- );
10676
- });
10677
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10678
- KeyboundForm,
10679
- {
10680
- className: "flex flex-1 flex-col overflow-hidden",
10681
- onSubmit,
10682
- children: [
10683
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
10684
- /* @__PURE__ */ jsx(
10685
- Form$2.Field,
10686
- {
10687
- control: form.control,
10688
- name: "country_code",
10689
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10690
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
10691
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
10692
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10693
- ] })
10694
- }
10695
- ),
10696
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10650
+ },
10651
+ [data, isSubmitting, onSubmit]
10652
+ );
10653
+ useEffect(() => {
10654
+ document.addEventListener("keydown", onKeydown);
10655
+ return () => {
10656
+ document.removeEventListener("keydown", onKeydown);
10657
+ };
10658
+ }, [onKeydown]);
10659
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10660
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10661
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
10662
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
10663
+ /* @__PURE__ */ jsxs("div", { children: [
10664
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
10665
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
10666
+ ] }),
10667
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10668
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
10669
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
10697
10670
  /* @__PURE__ */ jsx(
10698
- Form$2.Field,
10671
+ Text,
10699
10672
  {
10700
- control: form.control,
10701
- name: "first_name",
10702
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10703
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
10704
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10705
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10706
- ] })
10673
+ size: "xsmall",
10674
+ weight: "plus",
10675
+ className: "text-ui-fg-muted",
10676
+ children: "Shipping profile"
10707
10677
  }
10708
10678
  ),
10709
10679
  /* @__PURE__ */ jsx(
10710
- Form$2.Field,
10680
+ Text,
10711
10681
  {
10712
- control: form.control,
10713
- name: "last_name",
10714
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10715
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
10716
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10717
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10718
- ] })
10682
+ size: "xsmall",
10683
+ weight: "plus",
10684
+ className: "text-ui-fg-muted",
10685
+ children: "Action"
10719
10686
  }
10720
10687
  )
10721
10688
  ] }),
10722
- /* @__PURE__ */ jsx(
10723
- Form$2.Field,
10724
- {
10725
- control: form.control,
10726
- name: "company",
10727
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10728
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
10729
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10730
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10731
- ] })
10732
- }
10733
- ),
10734
- /* @__PURE__ */ jsx(
10735
- Form$2.Field,
10736
- {
10737
- control: form.control,
10738
- name: "address_1",
10739
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10740
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
10741
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10742
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10743
- ] })
10744
- }
10745
- ),
10746
- /* @__PURE__ */ jsx(
10747
- Form$2.Field,
10748
- {
10749
- control: form.control,
10750
- name: "address_2",
10751
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10752
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10753
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10754
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10755
- ] })
10756
- }
10757
- ),
10758
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10759
- /* @__PURE__ */ jsx(
10760
- Form$2.Field,
10761
- {
10762
- control: form.control,
10763
- name: "postal_code",
10764
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10765
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
10766
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10767
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10768
- ] })
10769
- }
10770
- ),
10771
- /* @__PURE__ */ jsx(
10772
- Form$2.Field,
10689
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
10690
+ var _a2, _b, _c, _d, _e, _f, _g;
10691
+ const items = getItemsWithShippingProfile(
10692
+ profile.id,
10693
+ order.items
10694
+ );
10695
+ const hasItems = items.length > 0;
10696
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
10697
+ (option) => option.shipping_profile_id === profile.id
10698
+ );
10699
+ const shippingMethod = preview.shipping_methods.find(
10700
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
10701
+ );
10702
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
10703
+ (action) => action.action === "SHIPPING_ADD"
10704
+ );
10705
+ return /* @__PURE__ */ jsxs(
10706
+ Accordion.Item,
10773
10707
  {
10774
- control: form.control,
10775
- name: "city",
10776
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10777
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
10778
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10779
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10780
- ] })
10781
- }
10782
- )
10783
- ] }),
10784
- /* @__PURE__ */ jsx(
10785
- Form$2.Field,
10786
- {
10787
- control: form.control,
10788
- name: "province",
10789
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10790
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10791
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10792
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10793
- ] })
10794
- }
10795
- ),
10796
- /* @__PURE__ */ jsx(
10797
- Form$2.Field,
10798
- {
10799
- control: form.control,
10800
- name: "phone",
10801
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10802
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
10803
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10804
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10805
- ] })
10806
- }
10807
- )
10808
- ] }) }),
10809
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10810
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10811
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10812
- ] }) })
10813
- ]
10814
- }
10815
- ) });
10816
- };
10817
- const schema$1 = addressSchema;
10818
- const TransferOwnership = () => {
10819
- const { id } = useParams();
10820
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
10821
- fields: "id,customer_id,customer.*"
10822
- });
10823
- if (isError) {
10824
- throw error;
10825
- }
10826
- const isReady = !isPending && !!draft_order;
10827
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10828
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10829
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
10830
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
10831
- ] }),
10832
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
10833
- ] });
10834
- };
10835
- const TransferOwnershipForm = ({ order }) => {
10836
- var _a, _b;
10837
- const form = useForm({
10838
- defaultValues: {
10839
- customer_id: order.customer_id || ""
10840
- },
10841
- resolver: zodResolver(schema)
10842
- });
10843
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10844
- const { handleSuccess } = useRouteModal();
10845
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
10846
- const currentCustomer = order.customer ? {
10847
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
10848
- value: order.customer.id
10849
- } : null;
10850
- const onSubmit = form.handleSubmit(async (data) => {
10851
- await mutateAsync(
10852
- { customer_id: data.customer_id },
10853
- {
10854
- onSuccess: () => {
10855
- toast.success("Customer updated");
10856
- handleSuccess();
10857
- },
10858
- onError: (error) => {
10859
- toast.error(error.message);
10860
- }
10861
- }
10862
- );
10863
- });
10864
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10865
- KeyboundForm,
10866
- {
10867
- className: "flex flex-1 flex-col overflow-hidden",
10868
- onSubmit,
10869
- children: [
10870
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
10871
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
10872
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
10873
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10874
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
10875
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
10876
- ] }),
10877
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
10878
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
10879
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
10880
- ] })
10881
- ] }),
10882
- /* @__PURE__ */ jsx(
10883
- CustomerField,
10884
- {
10885
- control: form.control,
10886
- currentCustomerId: order.customer_id
10887
- }
10888
- )
10889
- ] }),
10890
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10891
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
10892
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10893
- ] }) })
10894
- ]
10895
- }
10896
- ) });
10897
- };
10898
- const CustomerField = ({ control, currentCustomerId }) => {
10899
- const customers = useComboboxData({
10900
- queryFn: async (params) => {
10901
- return await sdk.admin.customer.list({
10902
- ...params,
10903
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
10904
- });
10905
- },
10906
- queryKey: ["customers"],
10907
- getOptions: (data) => {
10908
- return data.customers.map((customer) => {
10909
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
10910
- return {
10911
- label: name ? `${name} (${customer.email})` : customer.email,
10912
- value: customer.id
10913
- };
10914
- });
10915
- }
10916
- });
10917
- return /* @__PURE__ */ jsx(
10918
- Form$2.Field,
10919
- {
10920
- name: "customer_id",
10921
- control,
10922
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
10923
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10924
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
10925
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
10926
- ] }),
10927
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10928
- Combobox,
10929
- {
10930
- options: customers.options,
10931
- fetchNextPage: customers.fetchNextPage,
10932
- isFetchingNextPage: customers.isFetchingNextPage,
10933
- searchValue: customers.searchValue,
10934
- onSearchValueChange: customers.onSearchValueChange,
10935
- placeholder: "Select customer",
10936
- ...field
10937
- }
10938
- ) }),
10939
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10940
- ] })
10941
- }
10942
- );
10943
- };
10944
- const Illustration = () => {
10945
- return /* @__PURE__ */ jsxs(
10946
- "svg",
10947
- {
10948
- width: "280",
10949
- height: "180",
10950
- viewBox: "0 0 280 180",
10951
- fill: "none",
10952
- xmlns: "http://www.w3.org/2000/svg",
10953
- children: [
10954
- /* @__PURE__ */ jsx(
10955
- "rect",
10956
- {
10957
- x: "0.00428286",
10958
- y: "-0.742904",
10959
- width: "33.5",
10960
- height: "65.5",
10961
- rx: "6.75",
10962
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
10963
- fill: "#D4D4D8",
10964
- stroke: "#52525B",
10965
- strokeWidth: "1.5"
10966
- }
10967
- ),
10968
- /* @__PURE__ */ jsx(
10969
- "rect",
10970
- {
10971
- x: "0.00428286",
10972
- y: "-0.742904",
10973
- width: "33.5",
10974
- height: "65.5",
10975
- rx: "6.75",
10976
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
10977
- fill: "white",
10978
- stroke: "#52525B",
10979
- strokeWidth: "1.5"
10980
- }
10981
- ),
10982
- /* @__PURE__ */ jsx(
10983
- "path",
10984
- {
10985
- d: "M180.579 107.142L179.126 107.959",
10986
- stroke: "#52525B",
10987
- strokeWidth: "1.5",
10988
- strokeLinecap: "round",
10989
- strokeLinejoin: "round"
10990
- }
10991
- ),
10992
- /* @__PURE__ */ jsx(
10993
- "path",
10994
- {
10995
- opacity: "0.88",
10996
- d: "M182.305 109.546L180.257 109.534",
10997
- stroke: "#52525B",
10998
- strokeWidth: "1.5",
10999
- strokeLinecap: "round",
11000
- strokeLinejoin: "round"
11001
- }
11002
- ),
11003
- /* @__PURE__ */ jsx(
11004
- "path",
11005
- {
11006
- opacity: "0.75",
11007
- d: "M180.551 111.93L179.108 111.096",
11008
- stroke: "#52525B",
11009
- strokeWidth: "1.5",
11010
- strokeLinecap: "round",
11011
- strokeLinejoin: "round"
11012
- }
11013
- ),
11014
- /* @__PURE__ */ jsx(
11015
- "path",
11016
- {
11017
- opacity: "0.63",
11018
- d: "M176.347 112.897L176.354 111.73",
11019
- stroke: "#52525B",
11020
- strokeWidth: "1.5",
11021
- strokeLinecap: "round",
11022
- strokeLinejoin: "round"
11023
- }
11024
- ),
11025
- /* @__PURE__ */ jsx(
11026
- "path",
11027
- {
11028
- opacity: "0.5",
11029
- d: "M172.153 111.881L173.606 111.064",
11030
- stroke: "#52525B",
11031
- strokeWidth: "1.5",
11032
- strokeLinecap: "round",
11033
- strokeLinejoin: "round"
11034
- }
11035
- ),
11036
- /* @__PURE__ */ jsx(
11037
- "path",
11038
- {
11039
- opacity: "0.38",
11040
- d: "M170.428 109.478L172.476 109.489",
11041
- stroke: "#52525B",
11042
- strokeWidth: "1.5",
11043
- strokeLinecap: "round",
11044
- strokeLinejoin: "round"
11045
- }
11046
- ),
11047
- /* @__PURE__ */ jsx(
11048
- "path",
11049
- {
11050
- opacity: "0.25",
11051
- d: "M172.181 107.094L173.624 107.928",
11052
- stroke: "#52525B",
11053
- strokeWidth: "1.5",
11054
- strokeLinecap: "round",
11055
- strokeLinejoin: "round"
11056
- }
11057
- ),
11058
- /* @__PURE__ */ jsx(
11059
- "path",
11060
- {
11061
- opacity: "0.13",
11062
- d: "M176.386 106.126L176.379 107.294",
11063
- stroke: "#52525B",
11064
- strokeWidth: "1.5",
11065
- strokeLinecap: "round",
11066
- strokeLinejoin: "round"
11067
- }
11068
- ),
11069
- /* @__PURE__ */ jsx(
11070
- "rect",
11071
- {
11072
- width: "12",
11073
- height: "3",
11074
- rx: "1.5",
11075
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11076
- fill: "#D4D4D8"
11077
- }
11078
- ),
11079
- /* @__PURE__ */ jsx(
11080
- "rect",
11081
- {
11082
- x: "0.00428286",
11083
- y: "-0.742904",
11084
- width: "33.5",
11085
- height: "65.5",
11086
- rx: "6.75",
11087
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11088
- fill: "#D4D4D8",
11089
- stroke: "#52525B",
11090
- strokeWidth: "1.5"
11091
- }
11092
- ),
11093
- /* @__PURE__ */ jsx(
11094
- "rect",
11095
- {
11096
- x: "0.00428286",
11097
- y: "-0.742904",
11098
- width: "33.5",
11099
- height: "65.5",
11100
- rx: "6.75",
11101
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11102
- fill: "white",
11103
- stroke: "#52525B",
11104
- strokeWidth: "1.5"
11105
- }
11106
- ),
11107
- /* @__PURE__ */ jsx(
11108
- "rect",
11109
- {
11110
- width: "12",
11111
- height: "3",
11112
- rx: "1.5",
11113
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11114
- fill: "#D4D4D8"
11115
- }
11116
- ),
11117
- /* @__PURE__ */ jsx(
11118
- "rect",
11119
- {
11120
- width: "17",
11121
- height: "3",
11122
- rx: "1.5",
11123
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11124
- fill: "#D4D4D8"
11125
- }
11126
- ),
11127
- /* @__PURE__ */ jsx(
11128
- "rect",
11129
- {
11130
- width: "12",
11131
- height: "3",
11132
- rx: "1.5",
11133
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11134
- fill: "#D4D4D8"
11135
- }
11136
- ),
11137
- /* @__PURE__ */ jsx(
11138
- "path",
11139
- {
11140
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11141
- fill: "#A1A1AA"
11142
- }
11143
- ),
11144
- /* @__PURE__ */ jsx(
11145
- "rect",
11146
- {
11147
- width: "17",
11148
- height: "3",
11149
- rx: "1.5",
11150
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11151
- fill: "#A1A1AA"
11152
- }
11153
- ),
11154
- /* @__PURE__ */ jsx(
11155
- "rect",
11156
- {
11157
- width: "12",
11158
- height: "3",
11159
- rx: "1.5",
11160
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11161
- fill: "#A1A1AA"
11162
- }
11163
- ),
11164
- /* @__PURE__ */ jsx(
11165
- "path",
11166
- {
11167
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11168
- fill: "#52525B"
11169
- }
11170
- ),
11171
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
11172
- "path",
11173
- {
11174
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11175
- stroke: "#A1A1AA",
11176
- strokeWidth: "1.5",
11177
- strokeLinecap: "round",
11178
- strokeLinejoin: "round"
11179
- }
11180
- ) }),
11181
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
11182
- "path",
11183
- {
11184
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11185
- stroke: "#A1A1AA",
11186
- strokeWidth: "1.5",
11187
- strokeLinecap: "round",
11188
- strokeLinejoin: "round"
11189
- }
11190
- ) }),
11191
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
11192
- "path",
11193
- {
11194
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11195
- stroke: "#A1A1AA",
11196
- strokeWidth: "1.5",
11197
- strokeLinecap: "round",
11198
- strokeLinejoin: "round"
11199
- }
11200
- ) }),
11201
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
11202
- "path",
11203
- {
11204
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11205
- stroke: "#A1A1AA",
11206
- strokeWidth: "1.5",
11207
- strokeLinecap: "round",
11208
- strokeLinejoin: "round"
11209
- }
11210
- ) }),
11211
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
11212
- "path",
11213
- {
11214
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11215
- stroke: "#A1A1AA",
11216
- strokeWidth: "1.5",
11217
- strokeLinecap: "round",
11218
- strokeLinejoin: "round"
11219
- }
11220
- ) }),
11221
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
11222
- "path",
11223
- {
11224
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11225
- stroke: "#A1A1AA",
11226
- strokeWidth: "1.5",
11227
- strokeLinecap: "round",
11228
- strokeLinejoin: "round"
11229
- }
11230
- ) }),
11231
- /* @__PURE__ */ jsxs("defs", { children: [
11232
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
11233
- "rect",
11234
- {
11235
- width: "12",
11236
- height: "12",
11237
- fill: "white",
11238
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
10708
+ value: profile.id,
10709
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
10710
+ children: [
10711
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
10712
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
10713
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
10714
+ IconButton,
10715
+ {
10716
+ size: "2xsmall",
10717
+ variant: "transparent",
10718
+ className: "group/trigger",
10719
+ disabled: !hasItems,
10720
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
10721
+ }
10722
+ ) }),
10723
+ !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10724
+ /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
10725
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
10726
+ /* @__PURE__ */ jsx(
10727
+ Text,
10728
+ {
10729
+ size: "small",
10730
+ weight: "plus",
10731
+ leading: "compact",
10732
+ children: profile.name
10733
+ }
10734
+ ),
10735
+ /* @__PURE__ */ jsxs(
10736
+ Text,
10737
+ {
10738
+ size: "small",
10739
+ leading: "compact",
10740
+ className: "text-ui-fg-subtle",
10741
+ children: [
10742
+ items.length,
10743
+ " ",
10744
+ pluralize(items.length, "items", "item")
10745
+ ]
10746
+ }
10747
+ )
10748
+ ] })
10749
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
10750
+ /* @__PURE__ */ jsx(
10751
+ Tooltip,
10752
+ {
10753
+ content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
10754
+ var _a3, _b2, _c2;
10755
+ return /* @__PURE__ */ jsx(
10756
+ "li",
10757
+ {
10758
+ 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})`
10759
+ },
10760
+ item.id
10761
+ );
10762
+ }) }),
10763
+ children: /* @__PURE__ */ jsxs(
10764
+ Badge,
10765
+ {
10766
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
10767
+ size: "xsmall",
10768
+ children: [
10769
+ /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
10770
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
10771
+ items.reduce(
10772
+ (acc, item) => acc + item.quantity,
10773
+ 0
10774
+ ),
10775
+ "x",
10776
+ " ",
10777
+ pluralize(items.length, "items", "item")
10778
+ ] })
10779
+ ]
10780
+ }
10781
+ )
10782
+ }
10783
+ ),
10784
+ /* @__PURE__ */ jsx(
10785
+ Tooltip,
10786
+ {
10787
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
10788
+ children: /* @__PURE__ */ jsxs(
10789
+ Badge,
10790
+ {
10791
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
10792
+ size: "xsmall",
10793
+ children: [
10794
+ /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
10795
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
10796
+ ]
10797
+ }
10798
+ )
10799
+ }
10800
+ ),
10801
+ /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
10802
+ Badge,
10803
+ {
10804
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
10805
+ size: "xsmall",
10806
+ children: [
10807
+ /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
10808
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
10809
+ ]
10810
+ }
10811
+ ) })
10812
+ ] })
10813
+ ] }),
10814
+ shippingOption ? /* @__PURE__ */ jsx(
10815
+ ActionMenu,
10816
+ {
10817
+ groups: [
10818
+ {
10819
+ actions: [
10820
+ hasItems ? {
10821
+ label: "Edit shipping option",
10822
+ icon: /* @__PURE__ */ jsx(Channels, {}),
10823
+ onClick: () => {
10824
+ setIsOpen(
10825
+ STACKED_FOCUS_MODAL_ID,
10826
+ true
10827
+ );
10828
+ setData({
10829
+ shippingProfileId: profile.id,
10830
+ shippingOption,
10831
+ shippingMethod
10832
+ });
10833
+ }
10834
+ } : void 0,
10835
+ {
10836
+ label: "Remove shipping option",
10837
+ icon: /* @__PURE__ */ jsx(Trash, {}),
10838
+ onClick: () => {
10839
+ if (shippingMethod) {
10840
+ if (addShippingMethodAction) {
10841
+ removeActionShippingMethod(
10842
+ addShippingMethodAction.id
10843
+ );
10844
+ } else {
10845
+ removeShippingMethod(
10846
+ shippingMethod.id
10847
+ );
10848
+ }
10849
+ }
10850
+ }
10851
+ }
10852
+ ].filter(Boolean)
10853
+ }
10854
+ ]
10855
+ }
10856
+ ) : /* @__PURE__ */ jsx(
10857
+ StackedModalTrigger$1,
10858
+ {
10859
+ shippingProfileId: profile.id,
10860
+ shippingOption,
10861
+ shippingMethod,
10862
+ setData,
10863
+ children: "Add shipping option"
10864
+ }
10865
+ )
10866
+ ] }),
10867
+ /* @__PURE__ */ jsxs(Accordion.Content, { children: [
10868
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10869
+ items.map((item, idx) => {
10870
+ var _a3, _b2, _c2, _d2, _e2;
10871
+ return /* @__PURE__ */ jsxs("div", { children: [
10872
+ /* @__PURE__ */ jsxs(
10873
+ "div",
10874
+ {
10875
+ className: "px-3 flex items-center gap-x-3",
10876
+ children: [
10877
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
10878
+ Divider,
10879
+ {
10880
+ variant: "dashed",
10881
+ orientation: "vertical"
10882
+ }
10883
+ ) }),
10884
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
10885
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
10886
+ Text,
10887
+ {
10888
+ size: "small",
10889
+ leading: "compact",
10890
+ className: "text-ui-fg-subtle",
10891
+ children: [
10892
+ item.quantity,
10893
+ "x"
10894
+ ]
10895
+ }
10896
+ ) }),
10897
+ /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
10898
+ /* @__PURE__ */ jsxs("div", { children: [
10899
+ /* @__PURE__ */ jsxs(
10900
+ Text,
10901
+ {
10902
+ size: "small",
10903
+ leading: "compact",
10904
+ weight: "plus",
10905
+ children: [
10906
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
10907
+ " (",
10908
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
10909
+ ")"
10910
+ ]
10911
+ }
10912
+ ),
10913
+ /* @__PURE__ */ jsx(
10914
+ Text,
10915
+ {
10916
+ size: "small",
10917
+ leading: "compact",
10918
+ className: "text-ui-fg-subtle",
10919
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
10920
+ }
10921
+ )
10922
+ ] })
10923
+ ] })
10924
+ ]
10925
+ },
10926
+ item.id
10927
+ ),
10928
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
10929
+ ] }, item.id);
10930
+ })
10931
+ ] })
10932
+ ]
10933
+ },
10934
+ profile.id
10935
+ );
10936
+ }) })
10937
+ ] }) })
10938
+ ] }) }),
10939
+ /* @__PURE__ */ jsx(
10940
+ StackedFocusModal,
10941
+ {
10942
+ id: STACKED_FOCUS_MODAL_ID,
10943
+ onOpenChangeCallback: (open) => {
10944
+ if (!open) {
10945
+ setData(null);
11239
10946
  }
11240
- ) }),
11241
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
11242
- "rect",
10947
+ return open;
10948
+ },
10949
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
10950
+ }
10951
+ )
10952
+ ] }),
10953
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
10954
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10955
+ /* @__PURE__ */ jsx(
10956
+ Button,
10957
+ {
10958
+ size: "small",
10959
+ type: "button",
10960
+ isLoading: isSubmitting,
10961
+ onClick: onSubmit,
10962
+ children: "Save"
10963
+ }
10964
+ )
10965
+ ] }) })
10966
+ ] });
10967
+ };
10968
+ const StackedModalTrigger$1 = ({
10969
+ shippingProfileId,
10970
+ shippingOption,
10971
+ shippingMethod,
10972
+ setData,
10973
+ children
10974
+ }) => {
10975
+ const { setIsOpen, getIsOpen } = useStackedModal();
10976
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
10977
+ const onToggle = () => {
10978
+ if (isOpen) {
10979
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
10980
+ setData(null);
10981
+ } else {
10982
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
10983
+ setData({
10984
+ shippingProfileId,
10985
+ shippingOption,
10986
+ shippingMethod
10987
+ });
10988
+ }
10989
+ };
10990
+ return /* @__PURE__ */ jsx(
10991
+ Button,
10992
+ {
10993
+ size: "small",
10994
+ variant: "secondary",
10995
+ onClick: onToggle,
10996
+ className: "text-ui-fg-primary shrink-0",
10997
+ children
10998
+ }
10999
+ );
11000
+ };
11001
+ const ShippingProfileForm = ({
11002
+ data,
11003
+ order,
11004
+ preview
11005
+ }) => {
11006
+ var _a, _b, _c, _d, _e, _f;
11007
+ const { setIsOpen } = useStackedModal();
11008
+ const form = useForm({
11009
+ resolver: zodResolver(shippingMethodSchema),
11010
+ defaultValues: {
11011
+ 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,
11012
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11013
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11014
+ }
11015
+ });
11016
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11017
+ const {
11018
+ mutateAsync: updateShippingMethod,
11019
+ isPending: isUpdatingShippingMethod
11020
+ } = useDraftOrderUpdateShippingMethod(order.id);
11021
+ const onSubmit = form.handleSubmit(async (values) => {
11022
+ if (isEqual(values, form.formState.defaultValues)) {
11023
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11024
+ return;
11025
+ }
11026
+ if (data.shippingMethod) {
11027
+ await updateShippingMethod(
11028
+ {
11029
+ method_id: data.shippingMethod.id,
11030
+ shipping_option_id: values.shipping_option_id,
11031
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11032
+ },
11033
+ {
11034
+ onError: (e) => {
11035
+ toast.error(e.message);
11036
+ },
11037
+ onSuccess: () => {
11038
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11039
+ }
11040
+ }
11041
+ );
11042
+ return;
11043
+ }
11044
+ await addShippingMethod(
11045
+ {
11046
+ shipping_option_id: values.shipping_option_id,
11047
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11048
+ },
11049
+ {
11050
+ onError: (e) => {
11051
+ toast.error(e.message);
11052
+ },
11053
+ onSuccess: () => {
11054
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11055
+ }
11056
+ }
11057
+ );
11058
+ });
11059
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11060
+ KeyboundForm,
11061
+ {
11062
+ className: "flex h-full flex-col overflow-hidden",
11063
+ onSubmit,
11064
+ children: [
11065
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11066
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11067
+ /* @__PURE__ */ jsxs("div", { children: [
11068
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11069
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11070
+ ] }),
11071
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11072
+ /* @__PURE__ */ jsx(
11073
+ LocationField,
11243
11074
  {
11244
- width: "12",
11245
- height: "12",
11246
- fill: "white",
11247
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11075
+ control: form.control,
11076
+ setValue: form.setValue
11248
11077
  }
11249
- ) }),
11250
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
11251
- "rect",
11078
+ ),
11079
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11080
+ /* @__PURE__ */ jsx(
11081
+ ShippingOptionField,
11252
11082
  {
11253
- width: "12",
11254
- height: "12",
11255
- fill: "white",
11256
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11083
+ shippingProfileId: data.shippingProfileId,
11084
+ preview,
11085
+ control: form.control
11257
11086
  }
11258
- ) }),
11259
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
11260
- "rect",
11087
+ ),
11088
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11089
+ /* @__PURE__ */ jsx(
11090
+ CustomAmountField,
11261
11091
  {
11262
- width: "12",
11263
- height: "12",
11264
- fill: "white",
11265
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11092
+ control: form.control,
11093
+ currencyCode: order.currency_code
11266
11094
  }
11267
- ) }),
11268
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
11269
- "rect",
11095
+ ),
11096
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11097
+ /* @__PURE__ */ jsx(
11098
+ ItemsPreview,
11270
11099
  {
11271
- width: "12",
11272
- height: "12",
11273
- fill: "white",
11274
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11100
+ order,
11101
+ shippingProfileId: data.shippingProfileId
11275
11102
  }
11276
- ) }),
11277
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
11278
- "rect",
11103
+ )
11104
+ ] }) }) }),
11105
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11106
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11107
+ /* @__PURE__ */ jsx(
11108
+ Button,
11279
11109
  {
11280
- width: "12",
11281
- height: "12",
11282
- fill: "white",
11283
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
11110
+ size: "small",
11111
+ type: "submit",
11112
+ isLoading: isPending || isUpdatingShippingMethod,
11113
+ children: data.shippingMethod ? "Update" : "Add"
11284
11114
  }
11285
- ) })
11286
- ] })
11115
+ )
11116
+ ] }) })
11287
11117
  ]
11288
11118
  }
11289
- );
11119
+ ) }) });
11290
11120
  };
11291
- const schema = objectType({
11292
- customer_id: stringType().min(1)
11121
+ const shippingMethodSchema = objectType({
11122
+ location_id: stringType(),
11123
+ shipping_option_id: stringType(),
11124
+ custom_amount: unionType([numberType(), stringType()]).optional()
11293
11125
  });
11294
- function convertNumber(value) {
11295
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
11296
- }
11297
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11298
- const Shipping = () => {
11299
- var _a;
11300
- const { id } = useParams();
11301
- const { order, isPending, isError, error } = useOrder(id, {
11302
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11303
- });
11304
- const {
11305
- order: preview,
11306
- isPending: isPreviewPending,
11307
- isError: isPreviewError,
11308
- error: previewError
11309
- } = useOrderPreview(id);
11310
- useInitiateOrderEdit({ preview });
11311
- const { onCancel } = useCancelOrderEdit({ preview });
11312
- if (isError) {
11313
- throw error;
11314
- }
11315
- if (isPreviewError) {
11316
- throw previewError;
11317
- }
11318
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11319
- const isReady = preview && !isPreviewPending && order && !isPending;
11320
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11321
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11322
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11323
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11324
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11325
- ] }) }) }),
11326
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11327
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11328
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11329
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11330
- ] }) });
11331
- };
11332
- const ShippingForm = ({ preview, order }) => {
11333
- var _a;
11334
- const { setIsOpen } = useStackedModal();
11335
- const [isSubmitting, setIsSubmitting] = useState(false);
11336
- const [data, setData] = useState(null);
11337
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11338
- const { shipping_options } = useShippingOptions(
11339
- {
11340
- id: appliedShippingOptionIds,
11341
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11342
- },
11343
- {
11344
- enabled: appliedShippingOptionIds.length > 0
11345
- }
11346
- );
11347
- const uniqueShippingProfiles = useMemo(() => {
11348
- const profiles = /* @__PURE__ */ new Map();
11349
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11350
- profiles.set(profile.id, profile);
11351
- });
11352
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11353
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11354
- });
11355
- return Array.from(profiles.values());
11356
- }, [order.items, shipping_options]);
11357
- const { handleSuccess } = useRouteModal();
11358
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11359
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11360
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11361
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11362
- const onSubmit = async () => {
11363
- setIsSubmitting(true);
11364
- let requestSucceeded = false;
11365
- await requestOrderEdit(void 0, {
11366
- onError: (e) => {
11367
- toast.error(`Failed to request order edit: ${e.message}`);
11368
- },
11369
- onSuccess: () => {
11370
- requestSucceeded = true;
11371
- }
11372
- });
11373
- if (!requestSucceeded) {
11374
- setIsSubmitting(false);
11375
- return;
11126
+ const ItemsPreview = ({ order, shippingProfileId }) => {
11127
+ const matches = order.items.filter(
11128
+ (item) => {
11129
+ var _a, _b, _c;
11130
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11376
11131
  }
11377
- await confirmOrderEdit(void 0, {
11378
- onError: (e) => {
11379
- toast.error(`Failed to confirm order edit: ${e.message}`);
11380
- },
11381
- onSuccess: () => {
11382
- handleSuccess();
11383
- },
11384
- onSettled: () => {
11385
- setIsSubmitting(false);
11386
- }
11387
- });
11388
- };
11389
- const onKeydown = useCallback(
11390
- (e) => {
11391
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11392
- if (data || isSubmitting) {
11393
- return;
11394
- }
11395
- onSubmit();
11396
- }
11397
- },
11398
- [data, isSubmitting, onSubmit]
11399
11132
  );
11400
- useEffect(() => {
11401
- document.addEventListener("keydown", onKeydown);
11402
- return () => {
11403
- document.removeEventListener("keydown", onKeydown);
11404
- };
11405
- }, [onKeydown]);
11406
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11407
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11408
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11409
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11410
- /* @__PURE__ */ jsxs("div", { children: [
11411
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11412
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11413
- ] }),
11414
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11415
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11416
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11417
- /* @__PURE__ */ jsx(
11418
- Text,
11419
- {
11420
- size: "xsmall",
11421
- weight: "plus",
11422
- className: "text-ui-fg-muted",
11423
- children: "Shipping profile"
11424
- }
11425
- ),
11426
- /* @__PURE__ */ jsx(
11427
- Text,
11428
- {
11429
- size: "xsmall",
11430
- weight: "plus",
11431
- className: "text-ui-fg-muted",
11432
- children: "Action"
11433
- }
11434
- )
11435
- ] }),
11436
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11437
- var _a2, _b, _c, _d, _e, _f, _g;
11438
- const items = getItemsWithShippingProfile(
11439
- profile.id,
11440
- order.items
11441
- );
11442
- const hasItems = items.length > 0;
11443
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11444
- (option) => option.shipping_profile_id === profile.id
11445
- );
11446
- const shippingMethod = preview.shipping_methods.find(
11447
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11448
- );
11449
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11450
- (action) => action.action === "SHIPPING_ADD"
11451
- );
11452
- return /* @__PURE__ */ jsxs(
11453
- Accordion.Item,
11133
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
11134
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11135
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11136
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11137
+ ] }) }),
11138
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11139
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11140
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
11141
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
11142
+ ] }),
11143
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
11144
+ "div",
11145
+ {
11146
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11147
+ children: [
11148
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11149
+ /* @__PURE__ */ jsx(
11150
+ Thumbnail,
11151
+ {
11152
+ thumbnail: item.thumbnail,
11153
+ alt: item.product_title ?? void 0
11154
+ }
11155
+ ),
11156
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11157
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11158
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11159
+ /* @__PURE__ */ jsxs(
11160
+ Text,
11161
+ {
11162
+ size: "small",
11163
+ leading: "compact",
11164
+ className: "text-ui-fg-subtle",
11165
+ children: [
11166
+ "(",
11167
+ item.variant_title,
11168
+ ")"
11169
+ ]
11170
+ }
11171
+ )
11172
+ ] }),
11173
+ /* @__PURE__ */ jsx(
11174
+ Text,
11175
+ {
11176
+ size: "small",
11177
+ leading: "compact",
11178
+ className: "text-ui-fg-subtle",
11179
+ children: item.variant_sku
11180
+ }
11181
+ )
11182
+ ] })
11183
+ ] }),
11184
+ /* @__PURE__ */ jsxs(
11185
+ Text,
11454
11186
  {
11455
- value: profile.id,
11456
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11187
+ size: "small",
11188
+ leading: "compact",
11189
+ className: "text-ui-fg-subtle",
11457
11190
  children: [
11458
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11459
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11460
- /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11461
- IconButton,
11462
- {
11463
- size: "2xsmall",
11464
- variant: "transparent",
11465
- className: "group/trigger",
11466
- disabled: !hasItems,
11467
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11468
- }
11469
- ) }),
11470
- !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11471
- /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11472
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11473
- /* @__PURE__ */ jsx(
11474
- Text,
11475
- {
11476
- size: "small",
11477
- weight: "plus",
11478
- leading: "compact",
11479
- children: profile.name
11480
- }
11481
- ),
11482
- /* @__PURE__ */ jsxs(
11483
- Text,
11484
- {
11485
- size: "small",
11486
- leading: "compact",
11487
- className: "text-ui-fg-subtle",
11488
- children: [
11489
- items.length,
11490
- " ",
11491
- pluralize(items.length, "items", "item")
11492
- ]
11493
- }
11494
- )
11495
- ] })
11496
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11497
- /* @__PURE__ */ jsx(
11498
- Tooltip,
11499
- {
11500
- content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11501
- var _a3, _b2, _c2;
11502
- return /* @__PURE__ */ jsx(
11503
- "li",
11504
- {
11505
- 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})`
11506
- },
11507
- item.id
11508
- );
11509
- }) }),
11510
- children: /* @__PURE__ */ jsxs(
11511
- Badge,
11512
- {
11513
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11514
- size: "xsmall",
11515
- children: [
11516
- /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11517
- /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11518
- items.reduce(
11519
- (acc, item) => acc + item.quantity,
11520
- 0
11521
- ),
11522
- "x",
11523
- " ",
11524
- pluralize(items.length, "items", "item")
11525
- ] })
11526
- ]
11527
- }
11528
- )
11529
- }
11530
- ),
11531
- /* @__PURE__ */ jsx(
11532
- Tooltip,
11533
- {
11534
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11535
- children: /* @__PURE__ */ jsxs(
11536
- Badge,
11537
- {
11538
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11539
- size: "xsmall",
11540
- children: [
11541
- /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11542
- /* @__PURE__ */ jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11543
- ]
11544
- }
11545
- )
11546
- }
11547
- ),
11548
- /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11549
- Badge,
11550
- {
11551
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11552
- size: "xsmall",
11553
- children: [
11554
- /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11555
- /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11556
- ]
11557
- }
11558
- ) })
11559
- ] })
11560
- ] }),
11561
- shippingOption ? /* @__PURE__ */ jsx(
11562
- ActionMenu,
11563
- {
11564
- groups: [
11565
- {
11566
- actions: [
11567
- hasItems ? {
11568
- label: "Edit shipping option",
11569
- icon: /* @__PURE__ */ jsx(Channels, {}),
11570
- onClick: () => {
11571
- setIsOpen(
11572
- STACKED_FOCUS_MODAL_ID,
11573
- true
11574
- );
11575
- setData({
11576
- shippingProfileId: profile.id,
11577
- shippingOption,
11578
- shippingMethod
11579
- });
11580
- }
11581
- } : void 0,
11582
- {
11583
- label: "Remove shipping option",
11584
- icon: /* @__PURE__ */ jsx(Trash, {}),
11585
- onClick: () => {
11586
- if (shippingMethod) {
11587
- if (addShippingMethodAction) {
11588
- removeActionShippingMethod(
11589
- addShippingMethodAction.id
11590
- );
11591
- } else {
11592
- removeShippingMethod(
11593
- shippingMethod.id
11594
- );
11595
- }
11596
- }
11597
- }
11598
- }
11599
- ].filter(Boolean)
11600
- }
11601
- ]
11602
- }
11603
- ) : /* @__PURE__ */ jsx(
11604
- StackedModalTrigger$1,
11605
- {
11606
- shippingProfileId: profile.id,
11607
- shippingOption,
11608
- shippingMethod,
11609
- setData,
11610
- children: "Add shipping option"
11611
- }
11612
- )
11613
- ] }),
11614
- /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11615
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11616
- items.map((item, idx) => {
11617
- var _a3, _b2, _c2, _d2, _e2;
11618
- return /* @__PURE__ */ jsxs("div", { children: [
11619
- /* @__PURE__ */ jsxs(
11620
- "div",
11621
- {
11622
- className: "px-3 flex items-center gap-x-3",
11623
- children: [
11624
- /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11625
- Divider,
11626
- {
11627
- variant: "dashed",
11628
- orientation: "vertical"
11629
- }
11630
- ) }),
11631
- /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11632
- /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11633
- Text,
11634
- {
11635
- size: "small",
11636
- leading: "compact",
11637
- className: "text-ui-fg-subtle",
11638
- children: [
11639
- item.quantity,
11640
- "x"
11641
- ]
11642
- }
11643
- ) }),
11644
- /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
11645
- /* @__PURE__ */ jsxs("div", { children: [
11646
- /* @__PURE__ */ jsxs(
11647
- Text,
11648
- {
11649
- size: "small",
11650
- leading: "compact",
11651
- weight: "plus",
11652
- children: [
11653
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11654
- " (",
11655
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11656
- ")"
11657
- ]
11658
- }
11659
- ),
11660
- /* @__PURE__ */ jsx(
11661
- Text,
11662
- {
11663
- size: "small",
11664
- leading: "compact",
11665
- className: "text-ui-fg-subtle",
11666
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11667
- }
11668
- )
11669
- ] })
11670
- ] })
11671
- ]
11672
- },
11673
- item.id
11674
- ),
11675
- idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11676
- ] }, item.id);
11677
- })
11678
- ] })
11191
+ item.quantity,
11192
+ "x"
11679
11193
  ]
11194
+ }
11195
+ )
11196
+ ]
11197
+ },
11198
+ item.id
11199
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11200
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11201
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
11202
+ 'No items found for "',
11203
+ query,
11204
+ '".'
11205
+ ] })
11206
+ ] }) })
11207
+ ] })
11208
+ ] });
11209
+ };
11210
+ const LocationField = ({ control, setValue }) => {
11211
+ const locations = useComboboxData({
11212
+ queryKey: ["locations"],
11213
+ queryFn: async (params) => {
11214
+ return await sdk.admin.stockLocation.list(params);
11215
+ },
11216
+ getOptions: (data) => {
11217
+ return data.stock_locations.map((location) => ({
11218
+ label: location.name,
11219
+ value: location.id
11220
+ }));
11221
+ }
11222
+ });
11223
+ return /* @__PURE__ */ jsx(
11224
+ Form$2.Field,
11225
+ {
11226
+ control,
11227
+ name: "location_id",
11228
+ render: ({ field: { onChange, ...field } }) => {
11229
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11230
+ /* @__PURE__ */ jsxs("div", { children: [
11231
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
11232
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11233
+ ] }),
11234
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11235
+ Combobox,
11236
+ {
11237
+ options: locations.options,
11238
+ fetchNextPage: locations.fetchNextPage,
11239
+ isFetchingNextPage: locations.isFetchingNextPage,
11240
+ searchValue: locations.searchValue,
11241
+ onSearchValueChange: locations.onSearchValueChange,
11242
+ placeholder: "Select location",
11243
+ onChange: (value) => {
11244
+ setValue("shipping_option_id", "", {
11245
+ shouldDirty: true,
11246
+ shouldTouch: true
11247
+ });
11248
+ onChange(value);
11680
11249
  },
11681
- profile.id
11682
- );
11683
- }) })
11684
- ] }) })
11685
- ] }) }),
11686
- /* @__PURE__ */ jsx(
11687
- StackedFocusModal,
11688
- {
11689
- id: STACKED_FOCUS_MODAL_ID,
11690
- onOpenChangeCallback: (open) => {
11691
- if (!open) {
11692
- setData(null);
11250
+ ...field
11251
+ }
11252
+ ) })
11253
+ ] }) });
11254
+ }
11255
+ }
11256
+ );
11257
+ };
11258
+ const ShippingOptionField = ({
11259
+ shippingProfileId,
11260
+ preview,
11261
+ control
11262
+ }) => {
11263
+ var _a;
11264
+ const locationId = useWatch({ control, name: "location_id" });
11265
+ const shippingOptions = useComboboxData({
11266
+ queryKey: ["shipping_options", locationId, shippingProfileId],
11267
+ queryFn: async (params) => {
11268
+ return await sdk.admin.shippingOption.list({
11269
+ ...params,
11270
+ stock_location_id: locationId,
11271
+ shipping_profile_id: shippingProfileId
11272
+ });
11273
+ },
11274
+ getOptions: (data) => {
11275
+ return data.shipping_options.map((option) => {
11276
+ var _a2;
11277
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
11278
+ (r) => r.attribute === "is_return" && r.value === "true"
11279
+ )) {
11280
+ return void 0;
11281
+ }
11282
+ return {
11283
+ label: option.name,
11284
+ value: option.id
11285
+ };
11286
+ }).filter(Boolean);
11287
+ },
11288
+ enabled: !!locationId && !!shippingProfileId,
11289
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11290
+ });
11291
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
11292
+ return /* @__PURE__ */ jsx(
11293
+ Form$2.Field,
11294
+ {
11295
+ control,
11296
+ name: "shipping_option_id",
11297
+ render: ({ field }) => {
11298
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11299
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11300
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
11301
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11302
+ ] }),
11303
+ /* @__PURE__ */ jsx(
11304
+ ConditionalTooltip,
11305
+ {
11306
+ content: tooltipContent,
11307
+ showTooltip: !locationId || !shippingProfileId,
11308
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11309
+ Combobox,
11310
+ {
11311
+ options: shippingOptions.options,
11312
+ fetchNextPage: shippingOptions.fetchNextPage,
11313
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
11314
+ searchValue: shippingOptions.searchValue,
11315
+ onSearchValueChange: shippingOptions.onSearchValueChange,
11316
+ placeholder: "Select shipping option",
11317
+ ...field,
11318
+ disabled: !locationId || !shippingProfileId
11319
+ }
11320
+ ) }) })
11321
+ }
11322
+ )
11323
+ ] }) });
11324
+ }
11325
+ }
11326
+ );
11327
+ };
11328
+ const CustomAmountField = ({
11329
+ control,
11330
+ currencyCode
11331
+ }) => {
11332
+ return /* @__PURE__ */ jsx(
11333
+ Form$2.Field,
11334
+ {
11335
+ control,
11336
+ name: "custom_amount",
11337
+ render: ({ field: { onChange, ...field } }) => {
11338
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11339
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11340
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
11341
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11342
+ ] }),
11343
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11344
+ CurrencyInput,
11345
+ {
11346
+ ...field,
11347
+ onValueChange: (value) => onChange(value),
11348
+ symbol: getNativeSymbol(currencyCode),
11349
+ code: currencyCode
11350
+ }
11351
+ ) })
11352
+ ] });
11353
+ }
11354
+ }
11355
+ );
11356
+ };
11357
+ const ShippingAddress = () => {
11358
+ const { id } = useParams();
11359
+ const { order, isPending, isError, error } = useOrder(id, {
11360
+ fields: "+shipping_address"
11361
+ });
11362
+ if (isError) {
11363
+ throw error;
11364
+ }
11365
+ const isReady = !isPending && !!order;
11366
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11367
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11368
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11369
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11370
+ ] }),
11371
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11372
+ ] });
11373
+ };
11374
+ const ShippingAddressForm = ({ order }) => {
11375
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11376
+ const form = useForm({
11377
+ defaultValues: {
11378
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11379
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11380
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11381
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11382
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11383
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11384
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11385
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11386
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11387
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11388
+ },
11389
+ resolver: zodResolver(schema$2)
11390
+ });
11391
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11392
+ const { handleSuccess } = useRouteModal();
11393
+ const onSubmit = form.handleSubmit(async (data) => {
11394
+ await mutateAsync(
11395
+ {
11396
+ shipping_address: {
11397
+ first_name: data.first_name,
11398
+ last_name: data.last_name,
11399
+ company: data.company,
11400
+ address_1: data.address_1,
11401
+ address_2: data.address_2,
11402
+ city: data.city,
11403
+ province: data.province,
11404
+ country_code: data.country_code,
11405
+ postal_code: data.postal_code,
11406
+ phone: data.phone
11407
+ }
11408
+ },
11409
+ {
11410
+ onSuccess: () => {
11411
+ handleSuccess();
11412
+ },
11413
+ onError: (error) => {
11414
+ toast.error(error.message);
11415
+ }
11416
+ }
11417
+ );
11418
+ });
11419
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11420
+ KeyboundForm,
11421
+ {
11422
+ className: "flex flex-1 flex-col overflow-hidden",
11423
+ onSubmit,
11424
+ children: [
11425
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11426
+ /* @__PURE__ */ jsx(
11427
+ Form$2.Field,
11428
+ {
11429
+ control: form.control,
11430
+ name: "country_code",
11431
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11432
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11433
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11434
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11435
+ ] })
11436
+ }
11437
+ ),
11438
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11439
+ /* @__PURE__ */ jsx(
11440
+ Form$2.Field,
11441
+ {
11442
+ control: form.control,
11443
+ name: "first_name",
11444
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11445
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11446
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11447
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11448
+ ] })
11449
+ }
11450
+ ),
11451
+ /* @__PURE__ */ jsx(
11452
+ Form$2.Field,
11453
+ {
11454
+ control: form.control,
11455
+ name: "last_name",
11456
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11457
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11458
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11459
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11460
+ ] })
11461
+ }
11462
+ )
11463
+ ] }),
11464
+ /* @__PURE__ */ jsx(
11465
+ Form$2.Field,
11466
+ {
11467
+ control: form.control,
11468
+ name: "company",
11469
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11470
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11471
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11472
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11473
+ ] })
11693
11474
  }
11694
- return open;
11695
- },
11696
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11697
- }
11698
- )
11475
+ ),
11476
+ /* @__PURE__ */ jsx(
11477
+ Form$2.Field,
11478
+ {
11479
+ control: form.control,
11480
+ name: "address_1",
11481
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11482
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11483
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11484
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11485
+ ] })
11486
+ }
11487
+ ),
11488
+ /* @__PURE__ */ jsx(
11489
+ Form$2.Field,
11490
+ {
11491
+ control: form.control,
11492
+ name: "address_2",
11493
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11494
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11495
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11496
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11497
+ ] })
11498
+ }
11499
+ ),
11500
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11501
+ /* @__PURE__ */ jsx(
11502
+ Form$2.Field,
11503
+ {
11504
+ control: form.control,
11505
+ name: "postal_code",
11506
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11507
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11508
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11509
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11510
+ ] })
11511
+ }
11512
+ ),
11513
+ /* @__PURE__ */ jsx(
11514
+ Form$2.Field,
11515
+ {
11516
+ control: form.control,
11517
+ name: "city",
11518
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11519
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11520
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11521
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11522
+ ] })
11523
+ }
11524
+ )
11525
+ ] }),
11526
+ /* @__PURE__ */ jsx(
11527
+ Form$2.Field,
11528
+ {
11529
+ control: form.control,
11530
+ name: "province",
11531
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11532
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11533
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11534
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11535
+ ] })
11536
+ }
11537
+ ),
11538
+ /* @__PURE__ */ jsx(
11539
+ Form$2.Field,
11540
+ {
11541
+ control: form.control,
11542
+ name: "phone",
11543
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11544
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11545
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11546
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11547
+ ] })
11548
+ }
11549
+ )
11550
+ ] }) }),
11551
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11552
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11553
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11554
+ ] }) })
11555
+ ]
11556
+ }
11557
+ ) });
11558
+ };
11559
+ const schema$2 = addressSchema;
11560
+ const TransferOwnership = () => {
11561
+ const { id } = useParams();
11562
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11563
+ fields: "id,customer_id,customer.*"
11564
+ });
11565
+ if (isError) {
11566
+ throw error;
11567
+ }
11568
+ const isReady = !isPending && !!draft_order;
11569
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11570
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11571
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11572
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11699
11573
  ] }),
11700
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11701
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11702
- /* @__PURE__ */ jsx(
11703
- Button,
11704
- {
11705
- size: "small",
11706
- type: "button",
11707
- isLoading: isSubmitting,
11708
- onClick: onSubmit,
11709
- children: "Save"
11710
- }
11711
- )
11712
- ] }) })
11574
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11713
11575
  ] });
11714
11576
  };
11715
- const StackedModalTrigger$1 = ({
11716
- shippingProfileId,
11717
- shippingOption,
11718
- shippingMethod,
11719
- setData,
11720
- children
11721
- }) => {
11722
- const { setIsOpen, getIsOpen } = useStackedModal();
11723
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11724
- const onToggle = () => {
11725
- if (isOpen) {
11726
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11727
- setData(null);
11728
- } else {
11729
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11730
- setData({
11731
- shippingProfileId,
11732
- shippingOption,
11733
- shippingMethod
11577
+ const TransferOwnershipForm = ({ order }) => {
11578
+ var _a, _b;
11579
+ const form = useForm({
11580
+ defaultValues: {
11581
+ customer_id: order.customer_id || ""
11582
+ },
11583
+ resolver: zodResolver(schema$1)
11584
+ });
11585
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11586
+ const { handleSuccess } = useRouteModal();
11587
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11588
+ const currentCustomer = order.customer ? {
11589
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11590
+ value: order.customer.id
11591
+ } : null;
11592
+ const onSubmit = form.handleSubmit(async (data) => {
11593
+ await mutateAsync(
11594
+ { customer_id: data.customer_id },
11595
+ {
11596
+ onSuccess: () => {
11597
+ toast.success("Customer updated");
11598
+ handleSuccess();
11599
+ },
11600
+ onError: (error) => {
11601
+ toast.error(error.message);
11602
+ }
11603
+ }
11604
+ );
11605
+ });
11606
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11607
+ KeyboundForm,
11608
+ {
11609
+ className: "flex flex-1 flex-col overflow-hidden",
11610
+ onSubmit,
11611
+ children: [
11612
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11613
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11614
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11615
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11616
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11617
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11618
+ ] }),
11619
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11620
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11621
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11622
+ ] })
11623
+ ] }),
11624
+ /* @__PURE__ */ jsx(
11625
+ CustomerField,
11626
+ {
11627
+ control: form.control,
11628
+ currentCustomerId: order.customer_id
11629
+ }
11630
+ )
11631
+ ] }),
11632
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11633
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11634
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11635
+ ] }) })
11636
+ ]
11637
+ }
11638
+ ) });
11639
+ };
11640
+ const CustomerField = ({ control, currentCustomerId }) => {
11641
+ const customers = useComboboxData({
11642
+ queryFn: async (params) => {
11643
+ return await sdk.admin.customer.list({
11644
+ ...params,
11645
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11646
+ });
11647
+ },
11648
+ queryKey: ["customers"],
11649
+ getOptions: (data) => {
11650
+ return data.customers.map((customer) => {
11651
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11652
+ return {
11653
+ label: name ? `${name} (${customer.email})` : customer.email,
11654
+ value: customer.id
11655
+ };
11734
11656
  });
11735
11657
  }
11736
- };
11658
+ });
11737
11659
  return /* @__PURE__ */ jsx(
11738
- Button,
11660
+ Form$2.Field,
11739
11661
  {
11740
- size: "small",
11741
- variant: "secondary",
11742
- onClick: onToggle,
11743
- className: "text-ui-fg-primary shrink-0",
11744
- children
11662
+ name: "customer_id",
11663
+ control,
11664
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11665
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11666
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11667
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11668
+ ] }),
11669
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11670
+ Combobox,
11671
+ {
11672
+ options: customers.options,
11673
+ fetchNextPage: customers.fetchNextPage,
11674
+ isFetchingNextPage: customers.isFetchingNextPage,
11675
+ searchValue: customers.searchValue,
11676
+ onSearchValueChange: customers.onSearchValueChange,
11677
+ placeholder: "Select customer",
11678
+ ...field
11679
+ }
11680
+ ) }),
11681
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11682
+ ] })
11745
11683
  }
11746
11684
  );
11747
11685
  };
11748
- const ShippingProfileForm = ({
11749
- data,
11750
- order,
11751
- preview
11752
- }) => {
11753
- var _a, _b, _c, _d, _e, _f;
11754
- const { setIsOpen } = useStackedModal();
11755
- const form = useForm({
11756
- resolver: zodResolver(shippingMethodSchema),
11757
- defaultValues: {
11758
- 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,
11759
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11760
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11761
- }
11762
- });
11763
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11764
- const {
11765
- mutateAsync: updateShippingMethod,
11766
- isPending: isUpdatingShippingMethod
11767
- } = useDraftOrderUpdateShippingMethod(order.id);
11768
- const onSubmit = form.handleSubmit(async (values) => {
11769
- if (isEqual(values, form.formState.defaultValues)) {
11770
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11771
- return;
11772
- }
11773
- if (data.shippingMethod) {
11774
- await updateShippingMethod(
11775
- {
11776
- method_id: data.shippingMethod.id,
11777
- shipping_option_id: values.shipping_option_id,
11778
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11779
- },
11780
- {
11781
- onError: (e) => {
11782
- toast.error(e.message);
11783
- },
11784
- onSuccess: () => {
11785
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11686
+ const Illustration = () => {
11687
+ return /* @__PURE__ */ jsxs(
11688
+ "svg",
11689
+ {
11690
+ width: "280",
11691
+ height: "180",
11692
+ viewBox: "0 0 280 180",
11693
+ fill: "none",
11694
+ xmlns: "http://www.w3.org/2000/svg",
11695
+ children: [
11696
+ /* @__PURE__ */ jsx(
11697
+ "rect",
11698
+ {
11699
+ x: "0.00428286",
11700
+ y: "-0.742904",
11701
+ width: "33.5",
11702
+ height: "65.5",
11703
+ rx: "6.75",
11704
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11705
+ fill: "#D4D4D8",
11706
+ stroke: "#52525B",
11707
+ strokeWidth: "1.5"
11708
+ }
11709
+ ),
11710
+ /* @__PURE__ */ jsx(
11711
+ "rect",
11712
+ {
11713
+ x: "0.00428286",
11714
+ y: "-0.742904",
11715
+ width: "33.5",
11716
+ height: "65.5",
11717
+ rx: "6.75",
11718
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11719
+ fill: "white",
11720
+ stroke: "#52525B",
11721
+ strokeWidth: "1.5"
11722
+ }
11723
+ ),
11724
+ /* @__PURE__ */ jsx(
11725
+ "path",
11726
+ {
11727
+ d: "M180.579 107.142L179.126 107.959",
11728
+ stroke: "#52525B",
11729
+ strokeWidth: "1.5",
11730
+ strokeLinecap: "round",
11731
+ strokeLinejoin: "round"
11732
+ }
11733
+ ),
11734
+ /* @__PURE__ */ jsx(
11735
+ "path",
11736
+ {
11737
+ opacity: "0.88",
11738
+ d: "M182.305 109.546L180.257 109.534",
11739
+ stroke: "#52525B",
11740
+ strokeWidth: "1.5",
11741
+ strokeLinecap: "round",
11742
+ strokeLinejoin: "round"
11743
+ }
11744
+ ),
11745
+ /* @__PURE__ */ jsx(
11746
+ "path",
11747
+ {
11748
+ opacity: "0.75",
11749
+ d: "M180.551 111.93L179.108 111.096",
11750
+ stroke: "#52525B",
11751
+ strokeWidth: "1.5",
11752
+ strokeLinecap: "round",
11753
+ strokeLinejoin: "round"
11754
+ }
11755
+ ),
11756
+ /* @__PURE__ */ jsx(
11757
+ "path",
11758
+ {
11759
+ opacity: "0.63",
11760
+ d: "M176.347 112.897L176.354 111.73",
11761
+ stroke: "#52525B",
11762
+ strokeWidth: "1.5",
11763
+ strokeLinecap: "round",
11764
+ strokeLinejoin: "round"
11765
+ }
11766
+ ),
11767
+ /* @__PURE__ */ jsx(
11768
+ "path",
11769
+ {
11770
+ opacity: "0.5",
11771
+ d: "M172.153 111.881L173.606 111.064",
11772
+ stroke: "#52525B",
11773
+ strokeWidth: "1.5",
11774
+ strokeLinecap: "round",
11775
+ strokeLinejoin: "round"
11776
+ }
11777
+ ),
11778
+ /* @__PURE__ */ jsx(
11779
+ "path",
11780
+ {
11781
+ opacity: "0.38",
11782
+ d: "M170.428 109.478L172.476 109.489",
11783
+ stroke: "#52525B",
11784
+ strokeWidth: "1.5",
11785
+ strokeLinecap: "round",
11786
+ strokeLinejoin: "round"
11787
+ }
11788
+ ),
11789
+ /* @__PURE__ */ jsx(
11790
+ "path",
11791
+ {
11792
+ opacity: "0.25",
11793
+ d: "M172.181 107.094L173.624 107.928",
11794
+ stroke: "#52525B",
11795
+ strokeWidth: "1.5",
11796
+ strokeLinecap: "round",
11797
+ strokeLinejoin: "round"
11798
+ }
11799
+ ),
11800
+ /* @__PURE__ */ jsx(
11801
+ "path",
11802
+ {
11803
+ opacity: "0.13",
11804
+ d: "M176.386 106.126L176.379 107.294",
11805
+ stroke: "#52525B",
11806
+ strokeWidth: "1.5",
11807
+ strokeLinecap: "round",
11808
+ strokeLinejoin: "round"
11809
+ }
11810
+ ),
11811
+ /* @__PURE__ */ jsx(
11812
+ "rect",
11813
+ {
11814
+ width: "12",
11815
+ height: "3",
11816
+ rx: "1.5",
11817
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11818
+ fill: "#D4D4D8"
11819
+ }
11820
+ ),
11821
+ /* @__PURE__ */ jsx(
11822
+ "rect",
11823
+ {
11824
+ x: "0.00428286",
11825
+ y: "-0.742904",
11826
+ width: "33.5",
11827
+ height: "65.5",
11828
+ rx: "6.75",
11829
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11830
+ fill: "#D4D4D8",
11831
+ stroke: "#52525B",
11832
+ strokeWidth: "1.5"
11833
+ }
11834
+ ),
11835
+ /* @__PURE__ */ jsx(
11836
+ "rect",
11837
+ {
11838
+ x: "0.00428286",
11839
+ y: "-0.742904",
11840
+ width: "33.5",
11841
+ height: "65.5",
11842
+ rx: "6.75",
11843
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11844
+ fill: "white",
11845
+ stroke: "#52525B",
11846
+ strokeWidth: "1.5"
11847
+ }
11848
+ ),
11849
+ /* @__PURE__ */ jsx(
11850
+ "rect",
11851
+ {
11852
+ width: "12",
11853
+ height: "3",
11854
+ rx: "1.5",
11855
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11856
+ fill: "#D4D4D8"
11857
+ }
11858
+ ),
11859
+ /* @__PURE__ */ jsx(
11860
+ "rect",
11861
+ {
11862
+ width: "17",
11863
+ height: "3",
11864
+ rx: "1.5",
11865
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11866
+ fill: "#D4D4D8"
11867
+ }
11868
+ ),
11869
+ /* @__PURE__ */ jsx(
11870
+ "rect",
11871
+ {
11872
+ width: "12",
11873
+ height: "3",
11874
+ rx: "1.5",
11875
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11876
+ fill: "#D4D4D8"
11877
+ }
11878
+ ),
11879
+ /* @__PURE__ */ jsx(
11880
+ "path",
11881
+ {
11882
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11883
+ fill: "#A1A1AA"
11884
+ }
11885
+ ),
11886
+ /* @__PURE__ */ jsx(
11887
+ "rect",
11888
+ {
11889
+ width: "17",
11890
+ height: "3",
11891
+ rx: "1.5",
11892
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11893
+ fill: "#A1A1AA"
11894
+ }
11895
+ ),
11896
+ /* @__PURE__ */ jsx(
11897
+ "rect",
11898
+ {
11899
+ width: "12",
11900
+ height: "3",
11901
+ rx: "1.5",
11902
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11903
+ fill: "#A1A1AA"
11786
11904
  }
11787
- }
11788
- );
11789
- return;
11790
- }
11791
- await addShippingMethod(
11792
- {
11793
- shipping_option_id: values.shipping_option_id,
11794
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11795
- },
11796
- {
11797
- onError: (e) => {
11798
- toast.error(e.message);
11799
- },
11800
- onSuccess: () => {
11801
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11802
- }
11803
- }
11804
- );
11805
- });
11806
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11807
- KeyboundForm,
11808
- {
11809
- className: "flex h-full flex-col overflow-hidden",
11810
- onSubmit,
11811
- children: [
11812
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11813
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11814
- /* @__PURE__ */ jsxs("div", { children: [
11815
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11816
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11817
- ] }),
11818
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11819
- /* @__PURE__ */ jsx(
11820
- LocationField,
11821
- {
11822
- control: form.control,
11823
- setValue: form.setValue
11824
- }
11825
- ),
11826
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11827
- /* @__PURE__ */ jsx(
11828
- ShippingOptionField,
11829
- {
11830
- shippingProfileId: data.shippingProfileId,
11831
- preview,
11832
- control: form.control
11833
- }
11834
- ),
11835
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11836
- /* @__PURE__ */ jsx(
11837
- CustomAmountField,
11838
- {
11839
- control: form.control,
11840
- currencyCode: order.currency_code
11841
- }
11842
- ),
11843
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11844
- /* @__PURE__ */ jsx(
11845
- ItemsPreview,
11846
- {
11847
- order,
11848
- shippingProfileId: data.shippingProfileId
11849
- }
11850
- )
11851
- ] }) }) }),
11852
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11853
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11854
- /* @__PURE__ */ jsx(
11855
- Button,
11856
- {
11857
- size: "small",
11858
- type: "submit",
11859
- isLoading: isPending || isUpdatingShippingMethod,
11860
- children: data.shippingMethod ? "Update" : "Add"
11861
- }
11862
- )
11863
- ] }) })
11864
- ]
11865
- }
11866
- ) }) });
11867
- };
11868
- const shippingMethodSchema = objectType({
11869
- location_id: stringType(),
11870
- shipping_option_id: stringType(),
11871
- custom_amount: unionType([numberType(), stringType()]).optional()
11872
- });
11873
- const ItemsPreview = ({ order, shippingProfileId }) => {
11874
- const matches = order.items.filter(
11875
- (item) => {
11876
- var _a, _b, _c;
11877
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11878
- }
11879
- );
11880
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
11881
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11882
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11883
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11884
- ] }) }),
11885
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11886
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11887
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
11888
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
11889
- ] }),
11890
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
11891
- "div",
11892
- {
11893
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11894
- children: [
11895
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11896
- /* @__PURE__ */ jsx(
11897
- Thumbnail,
11898
- {
11899
- thumbnail: item.thumbnail,
11900
- alt: item.product_title ?? void 0
11901
- }
11902
- ),
11903
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11904
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11905
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11906
- /* @__PURE__ */ jsxs(
11907
- Text,
11908
- {
11909
- size: "small",
11910
- leading: "compact",
11911
- className: "text-ui-fg-subtle",
11912
- children: [
11913
- "(",
11914
- item.variant_title,
11915
- ")"
11916
- ]
11917
- }
11918
- )
11919
- ] }),
11920
- /* @__PURE__ */ jsx(
11921
- Text,
11922
- {
11923
- size: "small",
11924
- leading: "compact",
11925
- className: "text-ui-fg-subtle",
11926
- children: item.variant_sku
11927
- }
11928
- )
11929
- ] })
11930
- ] }),
11931
- /* @__PURE__ */ jsxs(
11932
- Text,
11933
- {
11934
- size: "small",
11935
- leading: "compact",
11936
- className: "text-ui-fg-subtle",
11937
- children: [
11938
- item.quantity,
11939
- "x"
11940
- ]
11941
- }
11942
- )
11943
- ]
11944
- },
11945
- item.id
11946
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11947
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11948
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
11949
- 'No items found for "',
11950
- query,
11951
- '".'
11952
- ] })
11953
- ] }) })
11954
- ] })
11955
- ] });
11956
- };
11957
- const LocationField = ({ control, setValue }) => {
11958
- const locations = useComboboxData({
11959
- queryKey: ["locations"],
11960
- queryFn: async (params) => {
11961
- return await sdk.admin.stockLocation.list(params);
11962
- },
11963
- getOptions: (data) => {
11964
- return data.stock_locations.map((location) => ({
11965
- label: location.name,
11966
- value: location.id
11967
- }));
11968
- }
11969
- });
11970
- return /* @__PURE__ */ jsx(
11971
- Form$2.Field,
11972
- {
11973
- control,
11974
- name: "location_id",
11975
- render: ({ field: { onChange, ...field } }) => {
11976
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11977
- /* @__PURE__ */ jsxs("div", { children: [
11978
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
11979
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11980
- ] }),
11981
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11982
- Combobox,
11905
+ ),
11906
+ /* @__PURE__ */ jsx(
11907
+ "path",
11908
+ {
11909
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11910
+ fill: "#52525B"
11911
+ }
11912
+ ),
11913
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
11914
+ "path",
11915
+ {
11916
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11917
+ stroke: "#A1A1AA",
11918
+ strokeWidth: "1.5",
11919
+ strokeLinecap: "round",
11920
+ strokeLinejoin: "round"
11921
+ }
11922
+ ) }),
11923
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
11924
+ "path",
11925
+ {
11926
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11927
+ stroke: "#A1A1AA",
11928
+ strokeWidth: "1.5",
11929
+ strokeLinecap: "round",
11930
+ strokeLinejoin: "round"
11931
+ }
11932
+ ) }),
11933
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
11934
+ "path",
11935
+ {
11936
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11937
+ stroke: "#A1A1AA",
11938
+ strokeWidth: "1.5",
11939
+ strokeLinecap: "round",
11940
+ strokeLinejoin: "round"
11941
+ }
11942
+ ) }),
11943
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
11944
+ "path",
11945
+ {
11946
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11947
+ stroke: "#A1A1AA",
11948
+ strokeWidth: "1.5",
11949
+ strokeLinecap: "round",
11950
+ strokeLinejoin: "round"
11951
+ }
11952
+ ) }),
11953
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
11954
+ "path",
11955
+ {
11956
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11957
+ stroke: "#A1A1AA",
11958
+ strokeWidth: "1.5",
11959
+ strokeLinecap: "round",
11960
+ strokeLinejoin: "round"
11961
+ }
11962
+ ) }),
11963
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
11964
+ "path",
11965
+ {
11966
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11967
+ stroke: "#A1A1AA",
11968
+ strokeWidth: "1.5",
11969
+ strokeLinecap: "round",
11970
+ strokeLinejoin: "round"
11971
+ }
11972
+ ) }),
11973
+ /* @__PURE__ */ jsxs("defs", { children: [
11974
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
11975
+ "rect",
11983
11976
  {
11984
- options: locations.options,
11985
- fetchNextPage: locations.fetchNextPage,
11986
- isFetchingNextPage: locations.isFetchingNextPage,
11987
- searchValue: locations.searchValue,
11988
- onSearchValueChange: locations.onSearchValueChange,
11989
- placeholder: "Select location",
11990
- onChange: (value) => {
11991
- setValue("shipping_option_id", "", {
11992
- shouldDirty: true,
11993
- shouldTouch: true
11994
- });
11995
- onChange(value);
11996
- },
11997
- ...field
11977
+ width: "12",
11978
+ height: "12",
11979
+ fill: "white",
11980
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11981
+ }
11982
+ ) }),
11983
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
11984
+ "rect",
11985
+ {
11986
+ width: "12",
11987
+ height: "12",
11988
+ fill: "white",
11989
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11990
+ }
11991
+ ) }),
11992
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
11993
+ "rect",
11994
+ {
11995
+ width: "12",
11996
+ height: "12",
11997
+ fill: "white",
11998
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11999
+ }
12000
+ ) }),
12001
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12002
+ "rect",
12003
+ {
12004
+ width: "12",
12005
+ height: "12",
12006
+ fill: "white",
12007
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12008
+ }
12009
+ ) }),
12010
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12011
+ "rect",
12012
+ {
12013
+ width: "12",
12014
+ height: "12",
12015
+ fill: "white",
12016
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12017
+ }
12018
+ ) }),
12019
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12020
+ "rect",
12021
+ {
12022
+ width: "12",
12023
+ height: "12",
12024
+ fill: "white",
12025
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
11998
12026
  }
11999
12027
  ) })
12000
- ] }) });
12001
- }
12028
+ ] })
12029
+ ]
12002
12030
  }
12003
12031
  );
12004
12032
  };
12005
- const ShippingOptionField = ({
12006
- shippingProfileId,
12007
- preview,
12008
- control
12009
- }) => {
12010
- var _a;
12011
- const locationId = useWatch({ control, name: "location_id" });
12012
- const shippingOptions = useComboboxData({
12013
- queryKey: ["shipping_options", locationId, shippingProfileId],
12014
- queryFn: async (params) => {
12015
- return await sdk.admin.shippingOption.list({
12016
- ...params,
12017
- stock_location_id: locationId,
12018
- shipping_profile_id: shippingProfileId
12019
- });
12020
- },
12021
- getOptions: (data) => {
12022
- return data.shipping_options.map((option) => {
12023
- var _a2;
12024
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12025
- (r) => r.attribute === "is_return" && r.value === "true"
12026
- )) {
12027
- return void 0;
12028
- }
12029
- return {
12030
- label: option.name,
12031
- value: option.id
12032
- };
12033
- }).filter(Boolean);
12033
+ const schema$1 = objectType({
12034
+ customer_id: stringType().min(1)
12035
+ });
12036
+ const Email = () => {
12037
+ const { id } = useParams();
12038
+ const { order, isPending, isError, error } = useOrder(id, {
12039
+ fields: "+email"
12040
+ });
12041
+ if (isError) {
12042
+ throw error;
12043
+ }
12044
+ const isReady = !isPending && !!order;
12045
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12046
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12047
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12048
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12049
+ ] }),
12050
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12051
+ ] });
12052
+ };
12053
+ const EmailForm = ({ order }) => {
12054
+ const form = useForm({
12055
+ defaultValues: {
12056
+ email: order.email ?? ""
12034
12057
  },
12035
- enabled: !!locationId && !!shippingProfileId,
12036
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12058
+ resolver: zodResolver(schema)
12037
12059
  });
12038
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12039
- return /* @__PURE__ */ jsx(
12040
- Form$2.Field,
12041
- {
12042
- control,
12043
- name: "shipping_option_id",
12044
- render: ({ field }) => {
12045
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12046
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12047
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12048
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12049
- ] }),
12050
- /* @__PURE__ */ jsx(
12051
- ConditionalTooltip,
12052
- {
12053
- content: tooltipContent,
12054
- showTooltip: !locationId || !shippingProfileId,
12055
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12056
- Combobox,
12057
- {
12058
- options: shippingOptions.options,
12059
- fetchNextPage: shippingOptions.fetchNextPage,
12060
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12061
- searchValue: shippingOptions.searchValue,
12062
- onSearchValueChange: shippingOptions.onSearchValueChange,
12063
- placeholder: "Select shipping option",
12064
- ...field,
12065
- disabled: !locationId || !shippingProfileId
12066
- }
12067
- ) }) })
12068
- }
12069
- )
12070
- ] }) });
12060
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12061
+ const { handleSuccess } = useRouteModal();
12062
+ const onSubmit = form.handleSubmit(async (data) => {
12063
+ await mutateAsync(
12064
+ { email: data.email },
12065
+ {
12066
+ onSuccess: () => {
12067
+ handleSuccess();
12068
+ },
12069
+ onError: (error) => {
12070
+ toast.error(error.message);
12071
+ }
12071
12072
  }
12072
- }
12073
- );
12074
- };
12075
- const CustomAmountField = ({
12076
- control,
12077
- currencyCode
12078
- }) => {
12079
- return /* @__PURE__ */ jsx(
12080
- Form$2.Field,
12073
+ );
12074
+ });
12075
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12076
+ KeyboundForm,
12081
12077
  {
12082
- control,
12083
- name: "custom_amount",
12084
- render: ({ field: { onChange, ...field } }) => {
12085
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12086
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12087
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12088
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12089
- ] }),
12090
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12091
- CurrencyInput,
12092
- {
12093
- ...field,
12094
- onValueChange: (value) => onChange(value),
12095
- symbol: getNativeSymbol(currencyCode),
12096
- code: currencyCode
12097
- }
12098
- ) })
12099
- ] });
12100
- }
12078
+ className: "flex flex-1 flex-col overflow-hidden",
12079
+ onSubmit,
12080
+ children: [
12081
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
12082
+ Form$2.Field,
12083
+ {
12084
+ control: form.control,
12085
+ name: "email",
12086
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12087
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
12088
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12089
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12090
+ ] })
12091
+ }
12092
+ ) }),
12093
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12094
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12095
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12096
+ ] }) })
12097
+ ]
12101
12098
  }
12102
- );
12099
+ ) });
12103
12100
  };
12101
+ const schema = objectType({
12102
+ email: stringType().email()
12103
+ });
12104
12104
  const NumberInput = forwardRef(
12105
12105
  ({
12106
12106
  value,
@@ -13046,17 +13046,13 @@ const routeModule = {
13046
13046
  handle,
13047
13047
  loader,
13048
13048
  children: [
13049
- {
13050
- Component: CustomItems,
13051
- path: "/draft-orders/:id/custom-items"
13052
- },
13053
13049
  {
13054
13050
  Component: BillingAddress,
13055
13051
  path: "/draft-orders/:id/billing-address"
13056
13052
  },
13057
13053
  {
13058
- Component: Email,
13059
- path: "/draft-orders/:id/email"
13054
+ Component: CustomItems,
13055
+ path: "/draft-orders/:id/custom-items"
13060
13056
  },
13061
13057
  {
13062
13058
  Component: Metadata,
@@ -13070,6 +13066,10 @@ const routeModule = {
13070
13066
  Component: SalesChannel,
13071
13067
  path: "/draft-orders/:id/sales-channel"
13072
13068
  },
13069
+ {
13070
+ Component: Shipping,
13071
+ path: "/draft-orders/:id/shipping"
13072
+ },
13073
13073
  {
13074
13074
  Component: ShippingAddress,
13075
13075
  path: "/draft-orders/:id/shipping-address"
@@ -13079,8 +13079,8 @@ const routeModule = {
13079
13079
  path: "/draft-orders/:id/transfer-ownership"
13080
13080
  },
13081
13081
  {
13082
- Component: Shipping,
13083
- path: "/draft-orders/:id/shipping"
13082
+ Component: Email,
13083
+ path: "/draft-orders/:id/email"
13084
13084
  },
13085
13085
  {
13086
13086
  Component: Items,