@medusajs/draft-order 2.10.4-snapshot-20251007075945 → 2.10.4-snapshot-20251007164739

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.
@@ -9778,6 +9778,74 @@ const CustomItemsForm = () => {
9778
9778
  const schema$4 = objectType({
9779
9779
  email: stringType().email()
9780
9780
  });
9781
+ const Email = () => {
9782
+ const { id } = useParams();
9783
+ const { order, isPending, isError, error } = useOrder(id, {
9784
+ fields: "+email"
9785
+ });
9786
+ if (isError) {
9787
+ throw error;
9788
+ }
9789
+ const isReady = !isPending && !!order;
9790
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9791
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9792
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9793
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9794
+ ] }),
9795
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9796
+ ] });
9797
+ };
9798
+ const EmailForm = ({ order }) => {
9799
+ const form = useForm({
9800
+ defaultValues: {
9801
+ email: order.email ?? ""
9802
+ },
9803
+ resolver: zodResolver(schema$3)
9804
+ });
9805
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
+ const { handleSuccess } = useRouteModal();
9807
+ const onSubmit = form.handleSubmit(async (data) => {
9808
+ await mutateAsync(
9809
+ { email: data.email },
9810
+ {
9811
+ onSuccess: () => {
9812
+ handleSuccess();
9813
+ },
9814
+ onError: (error) => {
9815
+ toast.error(error.message);
9816
+ }
9817
+ }
9818
+ );
9819
+ });
9820
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9821
+ KeyboundForm,
9822
+ {
9823
+ className: "flex flex-1 flex-col overflow-hidden",
9824
+ onSubmit,
9825
+ children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9827
+ Form$2.Field,
9828
+ {
9829
+ control: form.control,
9830
+ name: "email",
9831
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9832
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9833
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9834
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9835
+ ] })
9836
+ }
9837
+ ) }),
9838
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9841
+ ] }) })
9842
+ ]
9843
+ }
9844
+ ) });
9845
+ };
9846
+ const schema$3 = objectType({
9847
+ email: stringType().email()
9848
+ });
9781
9849
  const NumberInput = forwardRef(
9782
9850
  ({
9783
9851
  value,
@@ -11407,7 +11475,7 @@ const SalesChannelForm = ({ order }) => {
11407
11475
  defaultValues: {
11408
11476
  sales_channel_id: order.sales_channel_id || ""
11409
11477
  },
11410
- resolver: zodResolver(schema$3)
11478
+ resolver: zodResolver(schema$2)
11411
11479
  });
11412
11480
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11413
11481
  const { handleSuccess } = useRouteModal();
@@ -11482,913 +11550,166 @@ const SalesChannelField = ({ control, order }) => {
11482
11550
  }
11483
11551
  );
11484
11552
  };
11485
- const schema$3 = objectType({
11553
+ const schema$2 = objectType({
11486
11554
  sales_channel_id: stringType().min(1)
11487
11555
  });
11488
- const ShippingAddress = () => {
11556
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
+ const Shipping = () => {
11558
+ var _a;
11489
11559
  const { id } = useParams();
11490
11560
  const { order, isPending, isError, error } = useOrder(id, {
11491
- fields: "+shipping_address"
11561
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11492
11562
  });
11563
+ const {
11564
+ order: preview,
11565
+ isPending: isPreviewPending,
11566
+ isError: isPreviewError,
11567
+ error: previewError
11568
+ } = useOrderPreview(id);
11569
+ useInitiateOrderEdit({ preview });
11570
+ const { onCancel } = useCancelOrderEdit({ preview });
11493
11571
  if (isError) {
11494
11572
  throw error;
11495
11573
  }
11496
- const isReady = !isPending && !!order;
11497
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11498
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11499
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11500
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11501
- ] }),
11502
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11503
- ] });
11574
+ if (isPreviewError) {
11575
+ throw previewError;
11576
+ }
11577
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
+ const isReady = preview && !isPreviewPending && order && !isPending;
11579
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11582
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11583
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11584
+ ] }) }) }),
11585
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11586
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11587
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11588
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11589
+ ] }) });
11504
11590
  };
11505
- const ShippingAddressForm = ({ order }) => {
11506
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11507
- const form = useForm({
11508
- defaultValues: {
11509
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11510
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11511
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11512
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11513
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11514
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11515
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11516
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11517
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11518
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11591
+ const ShippingForm = ({ preview, order }) => {
11592
+ var _a;
11593
+ const { setIsOpen } = useStackedModal();
11594
+ const [isSubmitting, setIsSubmitting] = useState(false);
11595
+ const [data, setData] = useState(null);
11596
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11597
+ const { shipping_options } = useShippingOptions(
11598
+ {
11599
+ id: appliedShippingOptionIds,
11600
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11519
11601
  },
11520
- resolver: zodResolver(schema$2)
11521
- });
11522
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11602
+ {
11603
+ enabled: appliedShippingOptionIds.length > 0
11604
+ }
11605
+ );
11606
+ const uniqueShippingProfiles = useMemo(() => {
11607
+ const profiles = /* @__PURE__ */ new Map();
11608
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11609
+ profiles.set(profile.id, profile);
11610
+ });
11611
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11612
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11613
+ });
11614
+ return Array.from(profiles.values());
11615
+ }, [order.items, shipping_options]);
11523
11616
  const { handleSuccess } = useRouteModal();
11524
- const onSubmit = form.handleSubmit(async (data) => {
11525
- await mutateAsync(
11526
- {
11527
- shipping_address: {
11528
- first_name: data.first_name,
11529
- last_name: data.last_name,
11530
- company: data.company,
11531
- address_1: data.address_1,
11532
- address_2: data.address_2,
11533
- city: data.city,
11534
- province: data.province,
11535
- country_code: data.country_code,
11536
- postal_code: data.postal_code,
11537
- phone: data.phone
11538
- }
11617
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11618
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11619
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11620
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11621
+ const onSubmit = async () => {
11622
+ setIsSubmitting(true);
11623
+ let requestSucceeded = false;
11624
+ await requestOrderEdit(void 0, {
11625
+ onError: (e) => {
11626
+ toast.error(`Failed to request order edit: ${e.message}`);
11539
11627
  },
11540
- {
11541
- onSuccess: () => {
11542
- handleSuccess();
11543
- },
11544
- onError: (error) => {
11545
- toast.error(error.message);
11628
+ onSuccess: () => {
11629
+ requestSucceeded = true;
11630
+ }
11631
+ });
11632
+ if (!requestSucceeded) {
11633
+ setIsSubmitting(false);
11634
+ return;
11635
+ }
11636
+ await confirmOrderEdit(void 0, {
11637
+ onError: (e) => {
11638
+ toast.error(`Failed to confirm order edit: ${e.message}`);
11639
+ },
11640
+ onSuccess: () => {
11641
+ handleSuccess();
11642
+ },
11643
+ onSettled: () => {
11644
+ setIsSubmitting(false);
11645
+ }
11646
+ });
11647
+ };
11648
+ const onKeydown = useCallback(
11649
+ (e) => {
11650
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11651
+ if (data || isSubmitting) {
11652
+ return;
11546
11653
  }
11654
+ onSubmit();
11547
11655
  }
11548
- );
11549
- });
11550
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11551
- KeyboundForm,
11552
- {
11553
- className: "flex flex-1 flex-col overflow-hidden",
11554
- onSubmit,
11555
- children: [
11556
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11557
- /* @__PURE__ */ jsx(
11558
- Form$2.Field,
11559
- {
11560
- control: form.control,
11561
- name: "country_code",
11562
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11563
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11564
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11565
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11566
- ] })
11567
- }
11568
- ),
11569
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11656
+ },
11657
+ [data, isSubmitting, onSubmit]
11658
+ );
11659
+ useEffect(() => {
11660
+ document.addEventListener("keydown", onKeydown);
11661
+ return () => {
11662
+ document.removeEventListener("keydown", onKeydown);
11663
+ };
11664
+ }, [onKeydown]);
11665
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11666
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11667
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11668
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11669
+ /* @__PURE__ */ jsxs("div", { children: [
11670
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11671
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11672
+ ] }),
11673
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11674
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11675
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11570
11676
  /* @__PURE__ */ jsx(
11571
- Form$2.Field,
11677
+ Text,
11572
11678
  {
11573
- control: form.control,
11574
- name: "first_name",
11575
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11576
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11577
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11578
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11579
- ] })
11679
+ size: "xsmall",
11680
+ weight: "plus",
11681
+ className: "text-ui-fg-muted",
11682
+ children: "Shipping profile"
11580
11683
  }
11581
11684
  ),
11582
11685
  /* @__PURE__ */ jsx(
11583
- Form$2.Field,
11686
+ Text,
11584
11687
  {
11585
- control: form.control,
11586
- name: "last_name",
11587
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11588
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11589
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11590
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11591
- ] })
11688
+ size: "xsmall",
11689
+ weight: "plus",
11690
+ className: "text-ui-fg-muted",
11691
+ children: "Action"
11592
11692
  }
11593
11693
  )
11594
11694
  ] }),
11595
- /* @__PURE__ */ jsx(
11596
- Form$2.Field,
11597
- {
11598
- control: form.control,
11599
- name: "company",
11600
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11601
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11602
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11603
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11604
- ] })
11605
- }
11606
- ),
11607
- /* @__PURE__ */ jsx(
11608
- Form$2.Field,
11609
- {
11610
- control: form.control,
11611
- name: "address_1",
11612
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11613
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11614
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11615
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11616
- ] })
11617
- }
11618
- ),
11619
- /* @__PURE__ */ jsx(
11620
- Form$2.Field,
11621
- {
11622
- control: form.control,
11623
- name: "address_2",
11624
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11625
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11626
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11627
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11628
- ] })
11629
- }
11630
- ),
11631
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11632
- /* @__PURE__ */ jsx(
11633
- Form$2.Field,
11634
- {
11635
- control: form.control,
11636
- name: "postal_code",
11637
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11638
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11639
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11640
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11641
- ] })
11642
- }
11643
- ),
11644
- /* @__PURE__ */ jsx(
11645
- Form$2.Field,
11646
- {
11647
- control: form.control,
11648
- name: "city",
11649
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11650
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11651
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11652
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11653
- ] })
11654
- }
11655
- )
11656
- ] }),
11657
- /* @__PURE__ */ jsx(
11658
- Form$2.Field,
11659
- {
11660
- control: form.control,
11661
- name: "province",
11662
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11663
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11664
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11665
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11666
- ] })
11667
- }
11668
- ),
11669
- /* @__PURE__ */ jsx(
11670
- Form$2.Field,
11671
- {
11672
- control: form.control,
11673
- name: "phone",
11674
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11675
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11676
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11677
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11678
- ] })
11679
- }
11680
- )
11681
- ] }) }),
11682
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11683
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11684
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11685
- ] }) })
11686
- ]
11687
- }
11688
- ) });
11689
- };
11690
- const schema$2 = addressSchema;
11691
- const TransferOwnership = () => {
11692
- const { id } = useParams();
11693
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11694
- fields: "id,customer_id,customer.*"
11695
- });
11696
- if (isError) {
11697
- throw error;
11698
- }
11699
- const isReady = !isPending && !!draft_order;
11700
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11701
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11702
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11703
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11704
- ] }),
11705
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11706
- ] });
11707
- };
11708
- const TransferOwnershipForm = ({ order }) => {
11709
- var _a, _b;
11710
- const form = useForm({
11711
- defaultValues: {
11712
- customer_id: order.customer_id || ""
11713
- },
11714
- resolver: zodResolver(schema$1)
11715
- });
11716
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11717
- const { handleSuccess } = useRouteModal();
11718
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11719
- const currentCustomer = order.customer ? {
11720
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11721
- value: order.customer.id
11722
- } : null;
11723
- const onSubmit = form.handleSubmit(async (data) => {
11724
- await mutateAsync(
11725
- { customer_id: data.customer_id },
11726
- {
11727
- onSuccess: () => {
11728
- toast.success("Customer updated");
11729
- handleSuccess();
11730
- },
11731
- onError: (error) => {
11732
- toast.error(error.message);
11733
- }
11734
- }
11735
- );
11736
- });
11737
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11738
- KeyboundForm,
11739
- {
11740
- className: "flex flex-1 flex-col overflow-hidden",
11741
- onSubmit,
11742
- children: [
11743
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11744
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11745
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11746
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11747
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11748
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11749
- ] }),
11750
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11751
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11752
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11753
- ] })
11754
- ] }),
11755
- /* @__PURE__ */ jsx(
11756
- CustomerField,
11757
- {
11758
- control: form.control,
11759
- currentCustomerId: order.customer_id
11760
- }
11761
- )
11762
- ] }),
11763
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11764
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11765
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11766
- ] }) })
11767
- ]
11768
- }
11769
- ) });
11770
- };
11771
- const CustomerField = ({ control, currentCustomerId }) => {
11772
- const customers = useComboboxData({
11773
- queryFn: async (params) => {
11774
- return await sdk.admin.customer.list({
11775
- ...params,
11776
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11777
- });
11778
- },
11779
- queryKey: ["customers"],
11780
- getOptions: (data) => {
11781
- return data.customers.map((customer) => {
11782
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11783
- return {
11784
- label: name ? `${name} (${customer.email})` : customer.email,
11785
- value: customer.id
11786
- };
11787
- });
11788
- }
11789
- });
11790
- return /* @__PURE__ */ jsx(
11791
- Form$2.Field,
11792
- {
11793
- name: "customer_id",
11794
- control,
11795
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11796
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11797
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11798
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11799
- ] }),
11800
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11801
- Combobox,
11802
- {
11803
- options: customers.options,
11804
- fetchNextPage: customers.fetchNextPage,
11805
- isFetchingNextPage: customers.isFetchingNextPage,
11806
- searchValue: customers.searchValue,
11807
- onSearchValueChange: customers.onSearchValueChange,
11808
- placeholder: "Select customer",
11809
- ...field
11810
- }
11811
- ) }),
11812
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11813
- ] })
11814
- }
11815
- );
11816
- };
11817
- const Illustration = () => {
11818
- return /* @__PURE__ */ jsxs(
11819
- "svg",
11820
- {
11821
- width: "280",
11822
- height: "180",
11823
- viewBox: "0 0 280 180",
11824
- fill: "none",
11825
- xmlns: "http://www.w3.org/2000/svg",
11826
- children: [
11827
- /* @__PURE__ */ jsx(
11828
- "rect",
11829
- {
11830
- x: "0.00428286",
11831
- y: "-0.742904",
11832
- width: "33.5",
11833
- height: "65.5",
11834
- rx: "6.75",
11835
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11836
- fill: "#D4D4D8",
11837
- stroke: "#52525B",
11838
- strokeWidth: "1.5"
11839
- }
11840
- ),
11841
- /* @__PURE__ */ jsx(
11842
- "rect",
11843
- {
11844
- x: "0.00428286",
11845
- y: "-0.742904",
11846
- width: "33.5",
11847
- height: "65.5",
11848
- rx: "6.75",
11849
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11850
- fill: "white",
11851
- stroke: "#52525B",
11852
- strokeWidth: "1.5"
11853
- }
11854
- ),
11855
- /* @__PURE__ */ jsx(
11856
- "path",
11857
- {
11858
- d: "M180.579 107.142L179.126 107.959",
11859
- stroke: "#52525B",
11860
- strokeWidth: "1.5",
11861
- strokeLinecap: "round",
11862
- strokeLinejoin: "round"
11863
- }
11864
- ),
11865
- /* @__PURE__ */ jsx(
11866
- "path",
11867
- {
11868
- opacity: "0.88",
11869
- d: "M182.305 109.546L180.257 109.534",
11870
- stroke: "#52525B",
11871
- strokeWidth: "1.5",
11872
- strokeLinecap: "round",
11873
- strokeLinejoin: "round"
11874
- }
11875
- ),
11876
- /* @__PURE__ */ jsx(
11877
- "path",
11878
- {
11879
- opacity: "0.75",
11880
- d: "M180.551 111.93L179.108 111.096",
11881
- stroke: "#52525B",
11882
- strokeWidth: "1.5",
11883
- strokeLinecap: "round",
11884
- strokeLinejoin: "round"
11885
- }
11886
- ),
11887
- /* @__PURE__ */ jsx(
11888
- "path",
11889
- {
11890
- opacity: "0.63",
11891
- d: "M176.347 112.897L176.354 111.73",
11892
- stroke: "#52525B",
11893
- strokeWidth: "1.5",
11894
- strokeLinecap: "round",
11895
- strokeLinejoin: "round"
11896
- }
11897
- ),
11898
- /* @__PURE__ */ jsx(
11899
- "path",
11900
- {
11901
- opacity: "0.5",
11902
- d: "M172.153 111.881L173.606 111.064",
11903
- stroke: "#52525B",
11904
- strokeWidth: "1.5",
11905
- strokeLinecap: "round",
11906
- strokeLinejoin: "round"
11907
- }
11908
- ),
11909
- /* @__PURE__ */ jsx(
11910
- "path",
11911
- {
11912
- opacity: "0.38",
11913
- d: "M170.428 109.478L172.476 109.489",
11914
- stroke: "#52525B",
11915
- strokeWidth: "1.5",
11916
- strokeLinecap: "round",
11917
- strokeLinejoin: "round"
11918
- }
11919
- ),
11920
- /* @__PURE__ */ jsx(
11921
- "path",
11922
- {
11923
- opacity: "0.25",
11924
- d: "M172.181 107.094L173.624 107.928",
11925
- stroke: "#52525B",
11926
- strokeWidth: "1.5",
11927
- strokeLinecap: "round",
11928
- strokeLinejoin: "round"
11929
- }
11930
- ),
11931
- /* @__PURE__ */ jsx(
11932
- "path",
11933
- {
11934
- opacity: "0.13",
11935
- d: "M176.386 106.126L176.379 107.294",
11936
- stroke: "#52525B",
11937
- strokeWidth: "1.5",
11938
- strokeLinecap: "round",
11939
- strokeLinejoin: "round"
11940
- }
11941
- ),
11942
- /* @__PURE__ */ jsx(
11943
- "rect",
11944
- {
11945
- width: "12",
11946
- height: "3",
11947
- rx: "1.5",
11948
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11949
- fill: "#D4D4D8"
11950
- }
11951
- ),
11952
- /* @__PURE__ */ jsx(
11953
- "rect",
11954
- {
11955
- x: "0.00428286",
11956
- y: "-0.742904",
11957
- width: "33.5",
11958
- height: "65.5",
11959
- rx: "6.75",
11960
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11961
- fill: "#D4D4D8",
11962
- stroke: "#52525B",
11963
- strokeWidth: "1.5"
11964
- }
11965
- ),
11966
- /* @__PURE__ */ jsx(
11967
- "rect",
11968
- {
11969
- x: "0.00428286",
11970
- y: "-0.742904",
11971
- width: "33.5",
11972
- height: "65.5",
11973
- rx: "6.75",
11974
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11975
- fill: "white",
11976
- stroke: "#52525B",
11977
- strokeWidth: "1.5"
11978
- }
11979
- ),
11980
- /* @__PURE__ */ jsx(
11981
- "rect",
11982
- {
11983
- width: "12",
11984
- height: "3",
11985
- rx: "1.5",
11986
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11987
- fill: "#D4D4D8"
11988
- }
11989
- ),
11990
- /* @__PURE__ */ jsx(
11991
- "rect",
11992
- {
11993
- width: "17",
11994
- height: "3",
11995
- rx: "1.5",
11996
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11997
- fill: "#D4D4D8"
11998
- }
11999
- ),
12000
- /* @__PURE__ */ jsx(
12001
- "rect",
12002
- {
12003
- width: "12",
12004
- height: "3",
12005
- rx: "1.5",
12006
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12007
- fill: "#D4D4D8"
12008
- }
12009
- ),
12010
- /* @__PURE__ */ jsx(
12011
- "path",
12012
- {
12013
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12014
- fill: "#A1A1AA"
12015
- }
12016
- ),
12017
- /* @__PURE__ */ jsx(
12018
- "rect",
12019
- {
12020
- width: "17",
12021
- height: "3",
12022
- rx: "1.5",
12023
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12024
- fill: "#A1A1AA"
12025
- }
12026
- ),
12027
- /* @__PURE__ */ jsx(
12028
- "rect",
12029
- {
12030
- width: "12",
12031
- height: "3",
12032
- rx: "1.5",
12033
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12034
- fill: "#A1A1AA"
12035
- }
12036
- ),
12037
- /* @__PURE__ */ jsx(
12038
- "path",
12039
- {
12040
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12041
- fill: "#52525B"
12042
- }
12043
- ),
12044
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12045
- "path",
12046
- {
12047
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12048
- stroke: "#A1A1AA",
12049
- strokeWidth: "1.5",
12050
- strokeLinecap: "round",
12051
- strokeLinejoin: "round"
12052
- }
12053
- ) }),
12054
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12055
- "path",
12056
- {
12057
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12058
- stroke: "#A1A1AA",
12059
- strokeWidth: "1.5",
12060
- strokeLinecap: "round",
12061
- strokeLinejoin: "round"
12062
- }
12063
- ) }),
12064
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12065
- "path",
12066
- {
12067
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12068
- stroke: "#A1A1AA",
12069
- strokeWidth: "1.5",
12070
- strokeLinecap: "round",
12071
- strokeLinejoin: "round"
12072
- }
12073
- ) }),
12074
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12075
- "path",
12076
- {
12077
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12078
- stroke: "#A1A1AA",
12079
- strokeWidth: "1.5",
12080
- strokeLinecap: "round",
12081
- strokeLinejoin: "round"
12082
- }
12083
- ) }),
12084
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12085
- "path",
12086
- {
12087
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12088
- stroke: "#A1A1AA",
12089
- strokeWidth: "1.5",
12090
- strokeLinecap: "round",
12091
- strokeLinejoin: "round"
12092
- }
12093
- ) }),
12094
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12095
- "path",
12096
- {
12097
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12098
- stroke: "#A1A1AA",
12099
- strokeWidth: "1.5",
12100
- strokeLinecap: "round",
12101
- strokeLinejoin: "round"
12102
- }
12103
- ) }),
12104
- /* @__PURE__ */ jsxs("defs", { children: [
12105
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12106
- "rect",
12107
- {
12108
- width: "12",
12109
- height: "12",
12110
- fill: "white",
12111
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12112
- }
12113
- ) }),
12114
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12115
- "rect",
12116
- {
12117
- width: "12",
12118
- height: "12",
12119
- fill: "white",
12120
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12121
- }
12122
- ) }),
12123
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12124
- "rect",
12125
- {
12126
- width: "12",
12127
- height: "12",
12128
- fill: "white",
12129
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12130
- }
12131
- ) }),
12132
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12133
- "rect",
12134
- {
12135
- width: "12",
12136
- height: "12",
12137
- fill: "white",
12138
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12139
- }
12140
- ) }),
12141
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12142
- "rect",
12143
- {
12144
- width: "12",
12145
- height: "12",
12146
- fill: "white",
12147
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12148
- }
12149
- ) }),
12150
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12151
- "rect",
12152
- {
12153
- width: "12",
12154
- height: "12",
12155
- fill: "white",
12156
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12157
- }
12158
- ) })
12159
- ] })
12160
- ]
12161
- }
12162
- );
12163
- };
12164
- const schema$1 = objectType({
12165
- customer_id: stringType().min(1)
12166
- });
12167
- const Email = () => {
12168
- const { id } = useParams();
12169
- const { order, isPending, isError, error } = useOrder(id, {
12170
- fields: "+email"
12171
- });
12172
- if (isError) {
12173
- throw error;
12174
- }
12175
- const isReady = !isPending && !!order;
12176
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12177
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12178
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12179
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12180
- ] }),
12181
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12182
- ] });
12183
- };
12184
- const EmailForm = ({ order }) => {
12185
- const form = useForm({
12186
- defaultValues: {
12187
- email: order.email ?? ""
12188
- },
12189
- resolver: zodResolver(schema)
12190
- });
12191
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12192
- const { handleSuccess } = useRouteModal();
12193
- const onSubmit = form.handleSubmit(async (data) => {
12194
- await mutateAsync(
12195
- { email: data.email },
12196
- {
12197
- onSuccess: () => {
12198
- handleSuccess();
12199
- },
12200
- onError: (error) => {
12201
- toast.error(error.message);
12202
- }
12203
- }
12204
- );
12205
- });
12206
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12207
- KeyboundForm,
12208
- {
12209
- className: "flex flex-1 flex-col overflow-hidden",
12210
- onSubmit,
12211
- children: [
12212
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
12213
- Form$2.Field,
12214
- {
12215
- control: form.control,
12216
- name: "email",
12217
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12218
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
12219
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12220
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12221
- ] })
12222
- }
12223
- ) }),
12224
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12225
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12226
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12227
- ] }) })
12228
- ]
12229
- }
12230
- ) });
12231
- };
12232
- const schema = objectType({
12233
- email: stringType().email()
12234
- });
12235
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12236
- const Shipping = () => {
12237
- var _a;
12238
- const { id } = useParams();
12239
- const { order, isPending, isError, error } = useOrder(id, {
12240
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12241
- });
12242
- const {
12243
- order: preview,
12244
- isPending: isPreviewPending,
12245
- isError: isPreviewError,
12246
- error: previewError
12247
- } = useOrderPreview(id);
12248
- useInitiateOrderEdit({ preview });
12249
- const { onCancel } = useCancelOrderEdit({ preview });
12250
- if (isError) {
12251
- throw error;
12252
- }
12253
- if (isPreviewError) {
12254
- throw previewError;
12255
- }
12256
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12257
- const isReady = preview && !isPreviewPending && order && !isPending;
12258
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12259
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12260
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12261
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12262
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12263
- ] }) }) }),
12264
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12265
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
12266
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12267
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12268
- ] }) });
12269
- };
12270
- const ShippingForm = ({ preview, order }) => {
12271
- var _a;
12272
- const { setIsOpen } = useStackedModal();
12273
- const [isSubmitting, setIsSubmitting] = useState(false);
12274
- const [data, setData] = useState(null);
12275
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12276
- const { shipping_options } = useShippingOptions(
12277
- {
12278
- id: appliedShippingOptionIds,
12279
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12280
- },
12281
- {
12282
- enabled: appliedShippingOptionIds.length > 0
12283
- }
12284
- );
12285
- const uniqueShippingProfiles = useMemo(() => {
12286
- const profiles = /* @__PURE__ */ new Map();
12287
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12288
- profiles.set(profile.id, profile);
12289
- });
12290
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12291
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12292
- });
12293
- return Array.from(profiles.values());
12294
- }, [order.items, shipping_options]);
12295
- const { handleSuccess } = useRouteModal();
12296
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12297
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12298
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12299
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12300
- const onSubmit = async () => {
12301
- setIsSubmitting(true);
12302
- let requestSucceeded = false;
12303
- await requestOrderEdit(void 0, {
12304
- onError: (e) => {
12305
- toast.error(`Failed to request order edit: ${e.message}`);
12306
- },
12307
- onSuccess: () => {
12308
- requestSucceeded = true;
12309
- }
12310
- });
12311
- if (!requestSucceeded) {
12312
- setIsSubmitting(false);
12313
- return;
12314
- }
12315
- await confirmOrderEdit(void 0, {
12316
- onError: (e) => {
12317
- toast.error(`Failed to confirm order edit: ${e.message}`);
12318
- },
12319
- onSuccess: () => {
12320
- handleSuccess();
12321
- },
12322
- onSettled: () => {
12323
- setIsSubmitting(false);
12324
- }
12325
- });
12326
- };
12327
- const onKeydown = useCallback(
12328
- (e) => {
12329
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12330
- if (data || isSubmitting) {
12331
- return;
12332
- }
12333
- onSubmit();
12334
- }
12335
- },
12336
- [data, isSubmitting, onSubmit]
12337
- );
12338
- useEffect(() => {
12339
- document.addEventListener("keydown", onKeydown);
12340
- return () => {
12341
- document.removeEventListener("keydown", onKeydown);
12342
- };
12343
- }, [onKeydown]);
12344
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12345
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12346
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12347
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12348
- /* @__PURE__ */ jsxs("div", { children: [
12349
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12350
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
12351
- ] }),
12352
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12353
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
12354
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12355
- /* @__PURE__ */ jsx(
12356
- Text,
12357
- {
12358
- size: "xsmall",
12359
- weight: "plus",
12360
- className: "text-ui-fg-muted",
12361
- children: "Shipping profile"
12362
- }
12363
- ),
12364
- /* @__PURE__ */ jsx(
12365
- Text,
12366
- {
12367
- size: "xsmall",
12368
- weight: "plus",
12369
- className: "text-ui-fg-muted",
12370
- children: "Action"
12371
- }
12372
- )
12373
- ] }),
12374
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12375
- var _a2, _b, _c, _d, _e, _f, _g;
12376
- const items = getItemsWithShippingProfile(
12377
- profile.id,
12378
- order.items
12379
- );
12380
- const hasItems = items.length > 0;
12381
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12382
- (option) => option.shipping_profile_id === profile.id
12383
- );
12384
- const shippingMethod = preview.shipping_methods.find(
12385
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12386
- );
12387
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12388
- (action) => action.action === "SHIPPING_ADD"
12389
- );
12390
- return /* @__PURE__ */ jsxs(
12391
- Accordion.Item,
11695
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11696
+ var _a2, _b, _c, _d, _e, _f, _g;
11697
+ const items = getItemsWithShippingProfile(
11698
+ profile.id,
11699
+ order.items
11700
+ );
11701
+ const hasItems = items.length > 0;
11702
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11703
+ (option) => option.shipping_profile_id === profile.id
11704
+ );
11705
+ const shippingMethod = preview.shipping_methods.find(
11706
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11707
+ );
11708
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11709
+ (action) => action.action === "SHIPPING_ADD"
11710
+ );
11711
+ return /* @__PURE__ */ jsxs(
11712
+ Accordion.Item,
12392
11713
  {
12393
11714
  value: profile.id,
12394
11715
  className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
@@ -12620,425 +11941,1104 @@ const ShippingForm = ({ preview, order }) => {
12620
11941
  );
12621
11942
  }) })
12622
11943
  ] }) })
12623
- ] }) }),
12624
- /* @__PURE__ */ jsx(
12625
- StackedFocusModal,
11944
+ ] }) }),
11945
+ /* @__PURE__ */ jsx(
11946
+ StackedFocusModal,
11947
+ {
11948
+ id: STACKED_FOCUS_MODAL_ID,
11949
+ onOpenChangeCallback: (open) => {
11950
+ if (!open) {
11951
+ setData(null);
11952
+ }
11953
+ return open;
11954
+ },
11955
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11956
+ }
11957
+ )
11958
+ ] }),
11959
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11960
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11961
+ /* @__PURE__ */ jsx(
11962
+ Button,
11963
+ {
11964
+ size: "small",
11965
+ type: "button",
11966
+ isLoading: isSubmitting,
11967
+ onClick: onSubmit,
11968
+ children: "Save"
11969
+ }
11970
+ )
11971
+ ] }) })
11972
+ ] });
11973
+ };
11974
+ const StackedModalTrigger = ({
11975
+ shippingProfileId,
11976
+ shippingOption,
11977
+ shippingMethod,
11978
+ setData,
11979
+ children
11980
+ }) => {
11981
+ const { setIsOpen, getIsOpen } = useStackedModal();
11982
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11983
+ const onToggle = () => {
11984
+ if (isOpen) {
11985
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11986
+ setData(null);
11987
+ } else {
11988
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11989
+ setData({
11990
+ shippingProfileId,
11991
+ shippingOption,
11992
+ shippingMethod
11993
+ });
11994
+ }
11995
+ };
11996
+ return /* @__PURE__ */ jsx(
11997
+ Button,
11998
+ {
11999
+ size: "small",
12000
+ variant: "secondary",
12001
+ onClick: onToggle,
12002
+ className: "text-ui-fg-primary shrink-0",
12003
+ children
12004
+ }
12005
+ );
12006
+ };
12007
+ const ShippingProfileForm = ({
12008
+ data,
12009
+ order,
12010
+ preview
12011
+ }) => {
12012
+ var _a, _b, _c, _d, _e, _f;
12013
+ const { setIsOpen } = useStackedModal();
12014
+ const form = useForm({
12015
+ resolver: zodResolver(shippingMethodSchema),
12016
+ defaultValues: {
12017
+ 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,
12018
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12019
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12020
+ }
12021
+ });
12022
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12023
+ const {
12024
+ mutateAsync: updateShippingMethod,
12025
+ isPending: isUpdatingShippingMethod
12026
+ } = useDraftOrderUpdateShippingMethod(order.id);
12027
+ const onSubmit = form.handleSubmit(async (values) => {
12028
+ if (isEqual(values, form.formState.defaultValues)) {
12029
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12030
+ return;
12031
+ }
12032
+ if (data.shippingMethod) {
12033
+ await updateShippingMethod(
12034
+ {
12035
+ method_id: data.shippingMethod.id,
12036
+ shipping_option_id: values.shipping_option_id,
12037
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12038
+ },
12039
+ {
12040
+ onError: (e) => {
12041
+ toast.error(e.message);
12042
+ },
12043
+ onSuccess: () => {
12044
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12045
+ }
12046
+ }
12047
+ );
12048
+ return;
12049
+ }
12050
+ await addShippingMethod(
12051
+ {
12052
+ shipping_option_id: values.shipping_option_id,
12053
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12054
+ },
12055
+ {
12056
+ onError: (e) => {
12057
+ toast.error(e.message);
12058
+ },
12059
+ onSuccess: () => {
12060
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12061
+ }
12062
+ }
12063
+ );
12064
+ });
12065
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12066
+ KeyboundForm,
12067
+ {
12068
+ className: "flex h-full flex-col overflow-hidden",
12069
+ onSubmit,
12070
+ children: [
12071
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12072
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12073
+ /* @__PURE__ */ jsxs("div", { children: [
12074
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12075
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12076
+ ] }),
12077
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12078
+ /* @__PURE__ */ jsx(
12079
+ LocationField,
12080
+ {
12081
+ control: form.control,
12082
+ setValue: form.setValue
12083
+ }
12084
+ ),
12085
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12086
+ /* @__PURE__ */ jsx(
12087
+ ShippingOptionField,
12088
+ {
12089
+ shippingProfileId: data.shippingProfileId,
12090
+ preview,
12091
+ control: form.control
12092
+ }
12093
+ ),
12094
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12095
+ /* @__PURE__ */ jsx(
12096
+ CustomAmountField,
12097
+ {
12098
+ control: form.control,
12099
+ currencyCode: order.currency_code
12100
+ }
12101
+ ),
12102
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12103
+ /* @__PURE__ */ jsx(
12104
+ ItemsPreview,
12105
+ {
12106
+ order,
12107
+ shippingProfileId: data.shippingProfileId
12108
+ }
12109
+ )
12110
+ ] }) }) }),
12111
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12112
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12113
+ /* @__PURE__ */ jsx(
12114
+ Button,
12115
+ {
12116
+ size: "small",
12117
+ type: "submit",
12118
+ isLoading: isPending || isUpdatingShippingMethod,
12119
+ children: data.shippingMethod ? "Update" : "Add"
12120
+ }
12121
+ )
12122
+ ] }) })
12123
+ ]
12124
+ }
12125
+ ) }) });
12126
+ };
12127
+ const shippingMethodSchema = objectType({
12128
+ location_id: stringType(),
12129
+ shipping_option_id: stringType(),
12130
+ custom_amount: unionType([numberType(), stringType()]).optional()
12131
+ });
12132
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12133
+ const matches = order.items.filter(
12134
+ (item) => {
12135
+ var _a, _b, _c;
12136
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12137
+ }
12138
+ );
12139
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12140
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12141
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12142
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12143
+ ] }) }),
12144
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12145
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12146
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12147
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12148
+ ] }),
12149
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12150
+ "div",
12626
12151
  {
12627
- id: STACKED_FOCUS_MODAL_ID,
12628
- onOpenChangeCallback: (open) => {
12629
- if (!open) {
12630
- setData(null);
12152
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12153
+ children: [
12154
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12155
+ /* @__PURE__ */ jsx(
12156
+ Thumbnail,
12157
+ {
12158
+ thumbnail: item.thumbnail,
12159
+ alt: item.product_title ?? void 0
12160
+ }
12161
+ ),
12162
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12163
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12164
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12165
+ /* @__PURE__ */ jsxs(
12166
+ Text,
12167
+ {
12168
+ size: "small",
12169
+ leading: "compact",
12170
+ className: "text-ui-fg-subtle",
12171
+ children: [
12172
+ "(",
12173
+ item.variant_title,
12174
+ ")"
12175
+ ]
12176
+ }
12177
+ )
12178
+ ] }),
12179
+ /* @__PURE__ */ jsx(
12180
+ Text,
12181
+ {
12182
+ size: "small",
12183
+ leading: "compact",
12184
+ className: "text-ui-fg-subtle",
12185
+ children: item.variant_sku
12186
+ }
12187
+ )
12188
+ ] })
12189
+ ] }),
12190
+ /* @__PURE__ */ jsxs(
12191
+ Text,
12192
+ {
12193
+ size: "small",
12194
+ leading: "compact",
12195
+ className: "text-ui-fg-subtle",
12196
+ children: [
12197
+ item.quantity,
12198
+ "x"
12199
+ ]
12200
+ }
12201
+ )
12202
+ ]
12203
+ },
12204
+ item.id
12205
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12206
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12207
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12208
+ 'No items found for "',
12209
+ query,
12210
+ '".'
12211
+ ] })
12212
+ ] }) })
12213
+ ] })
12214
+ ] });
12215
+ };
12216
+ const LocationField = ({ control, setValue }) => {
12217
+ const locations = useComboboxData({
12218
+ queryKey: ["locations"],
12219
+ queryFn: async (params) => {
12220
+ return await sdk.admin.stockLocation.list(params);
12221
+ },
12222
+ getOptions: (data) => {
12223
+ return data.stock_locations.map((location) => ({
12224
+ label: location.name,
12225
+ value: location.id
12226
+ }));
12227
+ }
12228
+ });
12229
+ return /* @__PURE__ */ jsx(
12230
+ Form$2.Field,
12231
+ {
12232
+ control,
12233
+ name: "location_id",
12234
+ render: ({ field: { onChange, ...field } }) => {
12235
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12236
+ /* @__PURE__ */ jsxs("div", { children: [
12237
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12238
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12239
+ ] }),
12240
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12241
+ Combobox,
12242
+ {
12243
+ options: locations.options,
12244
+ fetchNextPage: locations.fetchNextPage,
12245
+ isFetchingNextPage: locations.isFetchingNextPage,
12246
+ searchValue: locations.searchValue,
12247
+ onSearchValueChange: locations.onSearchValueChange,
12248
+ placeholder: "Select location",
12249
+ onChange: (value) => {
12250
+ setValue("shipping_option_id", "", {
12251
+ shouldDirty: true,
12252
+ shouldTouch: true
12253
+ });
12254
+ onChange(value);
12255
+ },
12256
+ ...field
12257
+ }
12258
+ ) })
12259
+ ] }) });
12260
+ }
12261
+ }
12262
+ );
12263
+ };
12264
+ const ShippingOptionField = ({
12265
+ shippingProfileId,
12266
+ preview,
12267
+ control
12268
+ }) => {
12269
+ var _a;
12270
+ const locationId = useWatch({ control, name: "location_id" });
12271
+ const shippingOptions = useComboboxData({
12272
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12273
+ queryFn: async (params) => {
12274
+ return await sdk.admin.shippingOption.list({
12275
+ ...params,
12276
+ stock_location_id: locationId,
12277
+ shipping_profile_id: shippingProfileId
12278
+ });
12279
+ },
12280
+ getOptions: (data) => {
12281
+ return data.shipping_options.map((option) => {
12282
+ var _a2;
12283
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12284
+ (r) => r.attribute === "is_return" && r.value === "true"
12285
+ )) {
12286
+ return void 0;
12287
+ }
12288
+ return {
12289
+ label: option.name,
12290
+ value: option.id
12291
+ };
12292
+ }).filter(Boolean);
12293
+ },
12294
+ enabled: !!locationId && !!shippingProfileId,
12295
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12296
+ });
12297
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12298
+ return /* @__PURE__ */ jsx(
12299
+ Form$2.Field,
12300
+ {
12301
+ control,
12302
+ name: "shipping_option_id",
12303
+ render: ({ field }) => {
12304
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12305
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12306
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12307
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12308
+ ] }),
12309
+ /* @__PURE__ */ jsx(
12310
+ ConditionalTooltip,
12311
+ {
12312
+ content: tooltipContent,
12313
+ showTooltip: !locationId || !shippingProfileId,
12314
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12315
+ Combobox,
12316
+ {
12317
+ options: shippingOptions.options,
12318
+ fetchNextPage: shippingOptions.fetchNextPage,
12319
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12320
+ searchValue: shippingOptions.searchValue,
12321
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12322
+ placeholder: "Select shipping option",
12323
+ ...field,
12324
+ disabled: !locationId || !shippingProfileId
12325
+ }
12326
+ ) }) })
12631
12327
  }
12632
- return open;
12633
- },
12634
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
12635
- }
12636
- )
12637
- ] }),
12638
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12639
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12640
- /* @__PURE__ */ jsx(
12641
- Button,
12642
- {
12643
- size: "small",
12644
- type: "button",
12645
- isLoading: isSubmitting,
12646
- onClick: onSubmit,
12647
- children: "Save"
12648
- }
12649
- )
12650
- ] }) })
12651
- ] });
12328
+ )
12329
+ ] }) });
12330
+ }
12331
+ }
12332
+ );
12652
12333
  };
12653
- const StackedModalTrigger = ({
12654
- shippingProfileId,
12655
- shippingOption,
12656
- shippingMethod,
12657
- setData,
12658
- children
12334
+ const CustomAmountField = ({
12335
+ control,
12336
+ currencyCode
12659
12337
  }) => {
12660
- const { setIsOpen, getIsOpen } = useStackedModal();
12661
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12662
- const onToggle = () => {
12663
- if (isOpen) {
12664
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12665
- setData(null);
12666
- } else {
12667
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12668
- setData({
12669
- shippingProfileId,
12670
- shippingOption,
12671
- shippingMethod
12672
- });
12673
- }
12674
- };
12675
12338
  return /* @__PURE__ */ jsx(
12676
- Button,
12339
+ Form$2.Field,
12677
12340
  {
12678
- size: "small",
12679
- variant: "secondary",
12680
- onClick: onToggle,
12681
- className: "text-ui-fg-primary shrink-0",
12682
- children
12341
+ control,
12342
+ name: "custom_amount",
12343
+ render: ({ field: { onChange, ...field } }) => {
12344
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12345
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12346
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12348
+ ] }),
12349
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
+ CurrencyInput,
12351
+ {
12352
+ ...field,
12353
+ onValueChange: (value) => onChange(value),
12354
+ symbol: getNativeSymbol(currencyCode),
12355
+ code: currencyCode
12356
+ }
12357
+ ) })
12358
+ ] });
12359
+ }
12683
12360
  }
12684
12361
  );
12685
12362
  };
12686
- const ShippingProfileForm = ({
12687
- data,
12688
- order,
12689
- preview
12690
- }) => {
12691
- var _a, _b, _c, _d, _e, _f;
12692
- const { setIsOpen } = useStackedModal();
12363
+ const ShippingAddress = () => {
12364
+ const { id } = useParams();
12365
+ const { order, isPending, isError, error } = useOrder(id, {
12366
+ fields: "+shipping_address"
12367
+ });
12368
+ if (isError) {
12369
+ throw error;
12370
+ }
12371
+ const isReady = !isPending && !!order;
12372
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12373
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12374
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12376
+ ] }),
12377
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12378
+ ] });
12379
+ };
12380
+ const ShippingAddressForm = ({ order }) => {
12381
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12693
12382
  const form = useForm({
12694
- resolver: zodResolver(shippingMethodSchema),
12695
12383
  defaultValues: {
12696
- 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,
12697
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12698
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12699
- }
12384
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12394
+ },
12395
+ resolver: zodResolver(schema$1)
12700
12396
  });
12701
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12702
- const {
12703
- mutateAsync: updateShippingMethod,
12704
- isPending: isUpdatingShippingMethod
12705
- } = useDraftOrderUpdateShippingMethod(order.id);
12706
- const onSubmit = form.handleSubmit(async (values) => {
12707
- if (isEqual(values, form.formState.defaultValues)) {
12708
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12709
- return;
12710
- }
12711
- if (data.shippingMethod) {
12712
- await updateShippingMethod(
12713
- {
12714
- method_id: data.shippingMethod.id,
12715
- shipping_option_id: values.shipping_option_id,
12716
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12717
- },
12718
- {
12719
- onError: (e) => {
12720
- toast.error(e.message);
12721
- },
12722
- onSuccess: () => {
12723
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12724
- }
12725
- }
12726
- );
12727
- return;
12728
- }
12729
- await addShippingMethod(
12397
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
+ const { handleSuccess } = useRouteModal();
12399
+ const onSubmit = form.handleSubmit(async (data) => {
12400
+ await mutateAsync(
12730
12401
  {
12731
- shipping_option_id: values.shipping_option_id,
12732
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12402
+ shipping_address: {
12403
+ first_name: data.first_name,
12404
+ last_name: data.last_name,
12405
+ company: data.company,
12406
+ address_1: data.address_1,
12407
+ address_2: data.address_2,
12408
+ city: data.city,
12409
+ province: data.province,
12410
+ country_code: data.country_code,
12411
+ postal_code: data.postal_code,
12412
+ phone: data.phone
12413
+ }
12733
12414
  },
12734
12415
  {
12735
- onError: (e) => {
12736
- toast.error(e.message);
12737
- },
12738
12416
  onSuccess: () => {
12739
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12417
+ handleSuccess();
12418
+ },
12419
+ onError: (error) => {
12420
+ toast.error(error.message);
12740
12421
  }
12741
12422
  }
12742
12423
  );
12743
12424
  });
12744
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12425
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12745
12426
  KeyboundForm,
12746
12427
  {
12747
- className: "flex h-full flex-col overflow-hidden",
12428
+ className: "flex flex-1 flex-col overflow-hidden",
12748
12429
  onSubmit,
12749
12430
  children: [
12750
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12751
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12752
- /* @__PURE__ */ jsxs("div", { children: [
12753
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12754
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12431
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12432
+ /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control: form.control,
12436
+ name: "country_code",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
+ ] })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
+ /* @__PURE__ */ jsx(
12446
+ Form$2.Field,
12447
+ {
12448
+ control: form.control,
12449
+ name: "first_name",
12450
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
+ ] })
12455
+ }
12456
+ ),
12457
+ /* @__PURE__ */ jsx(
12458
+ Form$2.Field,
12459
+ {
12460
+ control: form.control,
12461
+ name: "last_name",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
+ ] })
12467
+ }
12468
+ )
12755
12469
  ] }),
12756
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12757
12470
  /* @__PURE__ */ jsx(
12758
- LocationField,
12471
+ Form$2.Field,
12472
+ {
12473
+ control: form.control,
12474
+ name: "company",
12475
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
+ ] })
12480
+ }
12481
+ ),
12482
+ /* @__PURE__ */ jsx(
12483
+ Form$2.Field,
12759
12484
  {
12760
12485
  control: form.control,
12761
- setValue: form.setValue
12486
+ name: "address_1",
12487
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
+ ] })
12762
12492
  }
12763
12493
  ),
12764
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12765
12494
  /* @__PURE__ */ jsx(
12766
- ShippingOptionField,
12495
+ Form$2.Field,
12767
12496
  {
12768
- shippingProfileId: data.shippingProfileId,
12769
- preview,
12770
- control: form.control
12497
+ control: form.control,
12498
+ name: "address_2",
12499
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
+ ] })
12771
12504
  }
12772
12505
  ),
12773
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12506
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
+ /* @__PURE__ */ jsx(
12508
+ Form$2.Field,
12509
+ {
12510
+ control: form.control,
12511
+ name: "postal_code",
12512
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
+ ] })
12517
+ }
12518
+ ),
12519
+ /* @__PURE__ */ jsx(
12520
+ Form$2.Field,
12521
+ {
12522
+ control: form.control,
12523
+ name: "city",
12524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
+ ] })
12529
+ }
12530
+ )
12531
+ ] }),
12774
12532
  /* @__PURE__ */ jsx(
12775
- CustomAmountField,
12533
+ Form$2.Field,
12776
12534
  {
12777
12535
  control: form.control,
12778
- currencyCode: order.currency_code
12536
+ name: "province",
12537
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
+ ] })
12779
12542
  }
12780
12543
  ),
12781
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12782
12544
  /* @__PURE__ */ jsx(
12783
- ItemsPreview,
12545
+ Form$2.Field,
12784
12546
  {
12785
- order,
12786
- shippingProfileId: data.shippingProfileId
12547
+ control: form.control,
12548
+ name: "phone",
12549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
+ ] })
12787
12554
  }
12788
12555
  )
12789
- ] }) }) }),
12790
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12791
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12556
+ ] }) }),
12557
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
+ ] }) })
12561
+ ]
12562
+ }
12563
+ ) });
12564
+ };
12565
+ const schema$1 = addressSchema;
12566
+ const TransferOwnership = () => {
12567
+ const { id } = useParams();
12568
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12569
+ fields: "id,customer_id,customer.*"
12570
+ });
12571
+ if (isError) {
12572
+ throw error;
12573
+ }
12574
+ const isReady = !isPending && !!draft_order;
12575
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12576
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12577
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12578
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12579
+ ] }),
12580
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12581
+ ] });
12582
+ };
12583
+ const TransferOwnershipForm = ({ order }) => {
12584
+ var _a, _b;
12585
+ const form = useForm({
12586
+ defaultValues: {
12587
+ customer_id: order.customer_id || ""
12588
+ },
12589
+ resolver: zodResolver(schema)
12590
+ });
12591
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
+ const { handleSuccess } = useRouteModal();
12593
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12594
+ const currentCustomer = order.customer ? {
12595
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12596
+ value: order.customer.id
12597
+ } : null;
12598
+ const onSubmit = form.handleSubmit(async (data) => {
12599
+ await mutateAsync(
12600
+ { customer_id: data.customer_id },
12601
+ {
12602
+ onSuccess: () => {
12603
+ toast.success("Customer updated");
12604
+ handleSuccess();
12605
+ },
12606
+ onError: (error) => {
12607
+ toast.error(error.message);
12608
+ }
12609
+ }
12610
+ );
12611
+ });
12612
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12613
+ KeyboundForm,
12614
+ {
12615
+ className: "flex flex-1 flex-col overflow-hidden",
12616
+ onSubmit,
12617
+ children: [
12618
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12619
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12620
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12621
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12622
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12623
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12624
+ ] }),
12625
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12626
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12627
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12628
+ ] })
12629
+ ] }),
12792
12630
  /* @__PURE__ */ jsx(
12793
- Button,
12631
+ CustomerField,
12794
12632
  {
12795
- size: "small",
12796
- type: "submit",
12797
- isLoading: isPending || isUpdatingShippingMethod,
12798
- children: data.shippingMethod ? "Update" : "Add"
12633
+ control: form.control,
12634
+ currentCustomerId: order.customer_id
12799
12635
  }
12800
12636
  )
12637
+ ] }),
12638
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12639
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12640
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12801
12641
  ] }) })
12802
12642
  ]
12803
12643
  }
12804
- ) }) });
12805
- };
12806
- const shippingMethodSchema = objectType({
12807
- location_id: stringType(),
12808
- shipping_option_id: stringType(),
12809
- custom_amount: unionType([numberType(), stringType()]).optional()
12810
- });
12811
- const ItemsPreview = ({ order, shippingProfileId }) => {
12812
- const matches = order.items.filter(
12813
- (item) => {
12814
- var _a, _b, _c;
12815
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12816
- }
12817
- );
12818
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12819
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12820
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12821
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12822
- ] }) }),
12823
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12824
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12825
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12826
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12827
- ] }),
12828
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12829
- "div",
12830
- {
12831
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12832
- children: [
12833
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12834
- /* @__PURE__ */ jsx(
12835
- Thumbnail,
12836
- {
12837
- thumbnail: item.thumbnail,
12838
- alt: item.product_title ?? void 0
12839
- }
12840
- ),
12841
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12842
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12843
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12844
- /* @__PURE__ */ jsxs(
12845
- Text,
12846
- {
12847
- size: "small",
12848
- leading: "compact",
12849
- className: "text-ui-fg-subtle",
12850
- children: [
12851
- "(",
12852
- item.variant_title,
12853
- ")"
12854
- ]
12855
- }
12856
- )
12857
- ] }),
12858
- /* @__PURE__ */ jsx(
12859
- Text,
12860
- {
12861
- size: "small",
12862
- leading: "compact",
12863
- className: "text-ui-fg-subtle",
12864
- children: item.variant_sku
12865
- }
12866
- )
12867
- ] })
12868
- ] }),
12869
- /* @__PURE__ */ jsxs(
12870
- Text,
12871
- {
12872
- size: "small",
12873
- leading: "compact",
12874
- className: "text-ui-fg-subtle",
12875
- children: [
12876
- item.quantity,
12877
- "x"
12878
- ]
12879
- }
12880
- )
12881
- ]
12882
- },
12883
- item.id
12884
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12885
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12886
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12887
- 'No items found for "',
12888
- query,
12889
- '".'
12890
- ] })
12891
- ] }) })
12892
- ] })
12893
- ] });
12644
+ ) });
12894
12645
  };
12895
- const LocationField = ({ control, setValue }) => {
12896
- const locations = useComboboxData({
12897
- queryKey: ["locations"],
12646
+ const CustomerField = ({ control, currentCustomerId }) => {
12647
+ const customers = useComboboxData({
12898
12648
  queryFn: async (params) => {
12899
- return await sdk.admin.stockLocation.list(params);
12649
+ return await sdk.admin.customer.list({
12650
+ ...params,
12651
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12652
+ });
12900
12653
  },
12654
+ queryKey: ["customers"],
12901
12655
  getOptions: (data) => {
12902
- return data.stock_locations.map((location) => ({
12903
- label: location.name,
12904
- value: location.id
12905
- }));
12656
+ return data.customers.map((customer) => {
12657
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12658
+ return {
12659
+ label: name ? `${name} (${customer.email})` : customer.email,
12660
+ value: customer.id
12661
+ };
12662
+ });
12906
12663
  }
12907
12664
  });
12908
12665
  return /* @__PURE__ */ jsx(
12909
12666
  Form$2.Field,
12910
12667
  {
12668
+ name: "customer_id",
12911
12669
  control,
12912
- name: "location_id",
12913
- render: ({ field: { onChange, ...field } }) => {
12914
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12915
- /* @__PURE__ */ jsxs("div", { children: [
12916
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12917
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12918
- ] }),
12919
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12920
- Combobox,
12670
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12671
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12672
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12673
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12674
+ ] }),
12675
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12676
+ Combobox,
12677
+ {
12678
+ options: customers.options,
12679
+ fetchNextPage: customers.fetchNextPage,
12680
+ isFetchingNextPage: customers.isFetchingNextPage,
12681
+ searchValue: customers.searchValue,
12682
+ onSearchValueChange: customers.onSearchValueChange,
12683
+ placeholder: "Select customer",
12684
+ ...field
12685
+ }
12686
+ ) }),
12687
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12688
+ ] })
12689
+ }
12690
+ );
12691
+ };
12692
+ const Illustration = () => {
12693
+ return /* @__PURE__ */ jsxs(
12694
+ "svg",
12695
+ {
12696
+ width: "280",
12697
+ height: "180",
12698
+ viewBox: "0 0 280 180",
12699
+ fill: "none",
12700
+ xmlns: "http://www.w3.org/2000/svg",
12701
+ children: [
12702
+ /* @__PURE__ */ jsx(
12703
+ "rect",
12704
+ {
12705
+ x: "0.00428286",
12706
+ y: "-0.742904",
12707
+ width: "33.5",
12708
+ height: "65.5",
12709
+ rx: "6.75",
12710
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12711
+ fill: "#D4D4D8",
12712
+ stroke: "#52525B",
12713
+ strokeWidth: "1.5"
12714
+ }
12715
+ ),
12716
+ /* @__PURE__ */ jsx(
12717
+ "rect",
12718
+ {
12719
+ x: "0.00428286",
12720
+ y: "-0.742904",
12721
+ width: "33.5",
12722
+ height: "65.5",
12723
+ rx: "6.75",
12724
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12725
+ fill: "white",
12726
+ stroke: "#52525B",
12727
+ strokeWidth: "1.5"
12728
+ }
12729
+ ),
12730
+ /* @__PURE__ */ jsx(
12731
+ "path",
12732
+ {
12733
+ d: "M180.579 107.142L179.126 107.959",
12734
+ stroke: "#52525B",
12735
+ strokeWidth: "1.5",
12736
+ strokeLinecap: "round",
12737
+ strokeLinejoin: "round"
12738
+ }
12739
+ ),
12740
+ /* @__PURE__ */ jsx(
12741
+ "path",
12742
+ {
12743
+ opacity: "0.88",
12744
+ d: "M182.305 109.546L180.257 109.534",
12745
+ stroke: "#52525B",
12746
+ strokeWidth: "1.5",
12747
+ strokeLinecap: "round",
12748
+ strokeLinejoin: "round"
12749
+ }
12750
+ ),
12751
+ /* @__PURE__ */ jsx(
12752
+ "path",
12753
+ {
12754
+ opacity: "0.75",
12755
+ d: "M180.551 111.93L179.108 111.096",
12756
+ stroke: "#52525B",
12757
+ strokeWidth: "1.5",
12758
+ strokeLinecap: "round",
12759
+ strokeLinejoin: "round"
12760
+ }
12761
+ ),
12762
+ /* @__PURE__ */ jsx(
12763
+ "path",
12764
+ {
12765
+ opacity: "0.63",
12766
+ d: "M176.347 112.897L176.354 111.73",
12767
+ stroke: "#52525B",
12768
+ strokeWidth: "1.5",
12769
+ strokeLinecap: "round",
12770
+ strokeLinejoin: "round"
12771
+ }
12772
+ ),
12773
+ /* @__PURE__ */ jsx(
12774
+ "path",
12775
+ {
12776
+ opacity: "0.5",
12777
+ d: "M172.153 111.881L173.606 111.064",
12778
+ stroke: "#52525B",
12779
+ strokeWidth: "1.5",
12780
+ strokeLinecap: "round",
12781
+ strokeLinejoin: "round"
12782
+ }
12783
+ ),
12784
+ /* @__PURE__ */ jsx(
12785
+ "path",
12786
+ {
12787
+ opacity: "0.38",
12788
+ d: "M170.428 109.478L172.476 109.489",
12789
+ stroke: "#52525B",
12790
+ strokeWidth: "1.5",
12791
+ strokeLinecap: "round",
12792
+ strokeLinejoin: "round"
12793
+ }
12794
+ ),
12795
+ /* @__PURE__ */ jsx(
12796
+ "path",
12797
+ {
12798
+ opacity: "0.25",
12799
+ d: "M172.181 107.094L173.624 107.928",
12800
+ stroke: "#52525B",
12801
+ strokeWidth: "1.5",
12802
+ strokeLinecap: "round",
12803
+ strokeLinejoin: "round"
12804
+ }
12805
+ ),
12806
+ /* @__PURE__ */ jsx(
12807
+ "path",
12808
+ {
12809
+ opacity: "0.13",
12810
+ d: "M176.386 106.126L176.379 107.294",
12811
+ stroke: "#52525B",
12812
+ strokeWidth: "1.5",
12813
+ strokeLinecap: "round",
12814
+ strokeLinejoin: "round"
12815
+ }
12816
+ ),
12817
+ /* @__PURE__ */ jsx(
12818
+ "rect",
12819
+ {
12820
+ width: "12",
12821
+ height: "3",
12822
+ rx: "1.5",
12823
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12824
+ fill: "#D4D4D8"
12825
+ }
12826
+ ),
12827
+ /* @__PURE__ */ jsx(
12828
+ "rect",
12829
+ {
12830
+ x: "0.00428286",
12831
+ y: "-0.742904",
12832
+ width: "33.5",
12833
+ height: "65.5",
12834
+ rx: "6.75",
12835
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12836
+ fill: "#D4D4D8",
12837
+ stroke: "#52525B",
12838
+ strokeWidth: "1.5"
12839
+ }
12840
+ ),
12841
+ /* @__PURE__ */ jsx(
12842
+ "rect",
12843
+ {
12844
+ x: "0.00428286",
12845
+ y: "-0.742904",
12846
+ width: "33.5",
12847
+ height: "65.5",
12848
+ rx: "6.75",
12849
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12850
+ fill: "white",
12851
+ stroke: "#52525B",
12852
+ strokeWidth: "1.5"
12853
+ }
12854
+ ),
12855
+ /* @__PURE__ */ jsx(
12856
+ "rect",
12857
+ {
12858
+ width: "12",
12859
+ height: "3",
12860
+ rx: "1.5",
12861
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12862
+ fill: "#D4D4D8"
12863
+ }
12864
+ ),
12865
+ /* @__PURE__ */ jsx(
12866
+ "rect",
12867
+ {
12868
+ width: "17",
12869
+ height: "3",
12870
+ rx: "1.5",
12871
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12872
+ fill: "#D4D4D8"
12873
+ }
12874
+ ),
12875
+ /* @__PURE__ */ jsx(
12876
+ "rect",
12877
+ {
12878
+ width: "12",
12879
+ height: "3",
12880
+ rx: "1.5",
12881
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12882
+ fill: "#D4D4D8"
12883
+ }
12884
+ ),
12885
+ /* @__PURE__ */ jsx(
12886
+ "path",
12887
+ {
12888
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12889
+ fill: "#A1A1AA"
12890
+ }
12891
+ ),
12892
+ /* @__PURE__ */ jsx(
12893
+ "rect",
12894
+ {
12895
+ width: "17",
12896
+ height: "3",
12897
+ rx: "1.5",
12898
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12899
+ fill: "#A1A1AA"
12900
+ }
12901
+ ),
12902
+ /* @__PURE__ */ jsx(
12903
+ "rect",
12904
+ {
12905
+ width: "12",
12906
+ height: "3",
12907
+ rx: "1.5",
12908
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12909
+ fill: "#A1A1AA"
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ "path",
12914
+ {
12915
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12916
+ fill: "#52525B"
12917
+ }
12918
+ ),
12919
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12920
+ "path",
12921
+ {
12922
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12923
+ stroke: "#A1A1AA",
12924
+ strokeWidth: "1.5",
12925
+ strokeLinecap: "round",
12926
+ strokeLinejoin: "round"
12927
+ }
12928
+ ) }),
12929
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12930
+ "path",
12931
+ {
12932
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12933
+ stroke: "#A1A1AA",
12934
+ strokeWidth: "1.5",
12935
+ strokeLinecap: "round",
12936
+ strokeLinejoin: "round"
12937
+ }
12938
+ ) }),
12939
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12940
+ "path",
12941
+ {
12942
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12943
+ stroke: "#A1A1AA",
12944
+ strokeWidth: "1.5",
12945
+ strokeLinecap: "round",
12946
+ strokeLinejoin: "round"
12947
+ }
12948
+ ) }),
12949
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12950
+ "path",
12951
+ {
12952
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12953
+ stroke: "#A1A1AA",
12954
+ strokeWidth: "1.5",
12955
+ strokeLinecap: "round",
12956
+ strokeLinejoin: "round"
12957
+ }
12958
+ ) }),
12959
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
+ "path",
12961
+ {
12962
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
+ stroke: "#A1A1AA",
12964
+ strokeWidth: "1.5",
12965
+ strokeLinecap: "round",
12966
+ strokeLinejoin: "round"
12967
+ }
12968
+ ) }),
12969
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
+ "path",
12971
+ {
12972
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
+ stroke: "#A1A1AA",
12974
+ strokeWidth: "1.5",
12975
+ strokeLinecap: "round",
12976
+ strokeLinejoin: "round"
12977
+ }
12978
+ ) }),
12979
+ /* @__PURE__ */ jsxs("defs", { children: [
12980
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
+ "rect",
12921
12982
  {
12922
- options: locations.options,
12923
- fetchNextPage: locations.fetchNextPage,
12924
- isFetchingNextPage: locations.isFetchingNextPage,
12925
- searchValue: locations.searchValue,
12926
- onSearchValueChange: locations.onSearchValueChange,
12927
- placeholder: "Select location",
12928
- onChange: (value) => {
12929
- setValue("shipping_option_id", "", {
12930
- shouldDirty: true,
12931
- shouldTouch: true
12932
- });
12933
- onChange(value);
12934
- },
12935
- ...field
12983
+ width: "12",
12984
+ height: "12",
12985
+ fill: "white",
12986
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12936
12987
  }
12937
- ) })
12938
- ] }) });
12939
- }
12940
- }
12941
- );
12942
- };
12943
- const ShippingOptionField = ({
12944
- shippingProfileId,
12945
- preview,
12946
- control
12947
- }) => {
12948
- var _a;
12949
- const locationId = useWatch({ control, name: "location_id" });
12950
- const shippingOptions = useComboboxData({
12951
- queryKey: ["shipping_options", locationId, shippingProfileId],
12952
- queryFn: async (params) => {
12953
- return await sdk.admin.shippingOption.list({
12954
- ...params,
12955
- stock_location_id: locationId,
12956
- shipping_profile_id: shippingProfileId
12957
- });
12958
- },
12959
- getOptions: (data) => {
12960
- return data.shipping_options.map((option) => {
12961
- var _a2;
12962
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12963
- (r) => r.attribute === "is_return" && r.value === "true"
12964
- )) {
12965
- return void 0;
12966
- }
12967
- return {
12968
- label: option.name,
12969
- value: option.id
12970
- };
12971
- }).filter(Boolean);
12972
- },
12973
- enabled: !!locationId && !!shippingProfileId,
12974
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12975
- });
12976
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12977
- return /* @__PURE__ */ jsx(
12978
- Form$2.Field,
12979
- {
12980
- control,
12981
- name: "shipping_option_id",
12982
- render: ({ field }) => {
12983
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12984
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12985
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12986
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12987
- ] }),
12988
- /* @__PURE__ */ jsx(
12989
- ConditionalTooltip,
12988
+ ) }),
12989
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
+ "rect",
12990
12991
  {
12991
- content: tooltipContent,
12992
- showTooltip: !locationId || !shippingProfileId,
12993
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12994
- Combobox,
12995
- {
12996
- options: shippingOptions.options,
12997
- fetchNextPage: shippingOptions.fetchNextPage,
12998
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12999
- searchValue: shippingOptions.searchValue,
13000
- onSearchValueChange: shippingOptions.onSearchValueChange,
13001
- placeholder: "Select shipping option",
13002
- ...field,
13003
- disabled: !locationId || !shippingProfileId
13004
- }
13005
- ) }) })
12992
+ width: "12",
12993
+ height: "12",
12994
+ fill: "white",
12995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13006
12996
  }
13007
- )
13008
- ] }) });
13009
- }
13010
- }
13011
- );
13012
- };
13013
- const CustomAmountField = ({
13014
- control,
13015
- currencyCode
13016
- }) => {
13017
- return /* @__PURE__ */ jsx(
13018
- Form$2.Field,
13019
- {
13020
- control,
13021
- name: "custom_amount",
13022
- render: ({ field: { onChange, ...field } }) => {
13023
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13024
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
13025
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13026
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
13027
- ] }),
13028
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13029
- CurrencyInput,
12997
+ ) }),
12998
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
+ "rect",
13030
13000
  {
13031
- ...field,
13032
- onValueChange: (value) => onChange(value),
13033
- symbol: getNativeSymbol(currencyCode),
13034
- code: currencyCode
13001
+ width: "12",
13002
+ height: "12",
13003
+ fill: "white",
13004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13005
+ }
13006
+ ) }),
13007
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
+ "rect",
13009
+ {
13010
+ width: "12",
13011
+ height: "12",
13012
+ fill: "white",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13014
+ }
13015
+ ) }),
13016
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
+ "rect",
13018
+ {
13019
+ width: "12",
13020
+ height: "12",
13021
+ fill: "white",
13022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13023
+ }
13024
+ ) }),
13025
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
+ "rect",
13027
+ {
13028
+ width: "12",
13029
+ height: "12",
13030
+ fill: "white",
13031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13035
13032
  }
13036
13033
  ) })
13037
- ] });
13038
- }
13034
+ ] })
13035
+ ]
13039
13036
  }
13040
13037
  );
13041
13038
  };
13039
+ const schema = objectType({
13040
+ customer_id: stringType().min(1)
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13067,6 +13067,10 @@ const routeModule = {
13067
13067
  Component: CustomItems,
13068
13068
  path: "/draft-orders/:id/custom-items"
13069
13069
  },
13070
+ {
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13073
+ },
13070
13074
  {
13071
13075
  Component: Items,
13072
13076
  path: "/draft-orders/:id/items"
@@ -13083,6 +13087,10 @@ const routeModule = {
13083
13087
  Component: SalesChannel,
13084
13088
  path: "/draft-orders/:id/sales-channel"
13085
13089
  },
13090
+ {
13091
+ Component: Shipping,
13092
+ path: "/draft-orders/:id/shipping"
13093
+ },
13086
13094
  {
13087
13095
  Component: ShippingAddress,
13088
13096
  path: "/draft-orders/:id/shipping-address"
@@ -13090,14 +13098,6 @@ const routeModule = {
13090
13098
  {
13091
13099
  Component: TransferOwnership,
13092
13100
  path: "/draft-orders/:id/transfer-ownership"
13093
- },
13094
- {
13095
- Component: Email,
13096
- path: "/draft-orders/:id/email"
13097
- },
13098
- {
13099
- Component: Shipping,
13100
- path: "/draft-orders/:id/shipping"
13101
13101
  }
13102
13102
  ]
13103
13103
  }