@medusajs/draft-order 3.0.0-preview-20260222000310 → 3.0.0-preview-20260222034626

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