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