@medusajs/draft-order 2.10.4-preview-20250930000343 → 2.10.4-preview-20250930031233

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.
@@ -9567,217 +9567,6 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const BillingAddress = () => {
9571
- const { id } = useParams();
9572
- const { order, isPending, isError, error } = useOrder(id, {
9573
- fields: "+billing_address"
9574
- });
9575
- if (isError) {
9576
- throw error;
9577
- }
9578
- const isReady = !isPending && !!order;
9579
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
- ] }),
9584
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9585
- ] });
9586
- };
9587
- const BillingAddressForm = ({ order }) => {
9588
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9589
- const form = useForm({
9590
- defaultValues: {
9591
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
- },
9602
- resolver: zodResolver(schema$5)
9603
- });
9604
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
- const { handleSuccess } = useRouteModal();
9606
- const onSubmit = form.handleSubmit(async (data) => {
9607
- await mutateAsync(
9608
- { billing_address: data },
9609
- {
9610
- onSuccess: () => {
9611
- handleSuccess();
9612
- },
9613
- onError: (error) => {
9614
- toast.error(error.message);
9615
- }
9616
- }
9617
- );
9618
- });
9619
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
- KeyboundForm,
9621
- {
9622
- className: "flex flex-1 flex-col overflow-hidden",
9623
- onSubmit,
9624
- children: [
9625
- /* @__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: [
9626
- /* @__PURE__ */ jsx(
9627
- Form$2.Field,
9628
- {
9629
- control: form.control,
9630
- name: "country_code",
9631
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
- ] })
9636
- }
9637
- ),
9638
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
- /* @__PURE__ */ jsx(
9640
- Form$2.Field,
9641
- {
9642
- control: form.control,
9643
- name: "first_name",
9644
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
- ] })
9649
- }
9650
- ),
9651
- /* @__PURE__ */ jsx(
9652
- Form$2.Field,
9653
- {
9654
- control: form.control,
9655
- name: "last_name",
9656
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
- ] })
9661
- }
9662
- )
9663
- ] }),
9664
- /* @__PURE__ */ jsx(
9665
- Form$2.Field,
9666
- {
9667
- control: form.control,
9668
- name: "company",
9669
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
- ] })
9674
- }
9675
- ),
9676
- /* @__PURE__ */ jsx(
9677
- Form$2.Field,
9678
- {
9679
- control: form.control,
9680
- name: "address_1",
9681
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
- ] })
9686
- }
9687
- ),
9688
- /* @__PURE__ */ jsx(
9689
- Form$2.Field,
9690
- {
9691
- control: form.control,
9692
- name: "address_2",
9693
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
- ] })
9698
- }
9699
- ),
9700
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
- /* @__PURE__ */ jsx(
9702
- Form$2.Field,
9703
- {
9704
- control: form.control,
9705
- name: "postal_code",
9706
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
- ] })
9711
- }
9712
- ),
9713
- /* @__PURE__ */ jsx(
9714
- Form$2.Field,
9715
- {
9716
- control: form.control,
9717
- name: "city",
9718
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
- ] })
9723
- }
9724
- )
9725
- ] }),
9726
- /* @__PURE__ */ jsx(
9727
- Form$2.Field,
9728
- {
9729
- control: form.control,
9730
- name: "province",
9731
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
- ] })
9736
- }
9737
- ),
9738
- /* @__PURE__ */ jsx(
9739
- Form$2.Field,
9740
- {
9741
- control: form.control,
9742
- name: "phone",
9743
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
- ] })
9748
- }
9749
- )
9750
- ] }) }),
9751
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
- ] }) })
9755
- ]
9756
- }
9757
- ) });
9758
- };
9759
- const schema$5 = addressSchema;
9760
- const CustomItems = () => {
9761
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
- ] });
9765
- };
9766
- const CustomItemsForm = () => {
9767
- const form = useForm({
9768
- resolver: zodResolver(schema$4)
9769
- });
9770
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
- ] }) })
9776
- ] }) });
9777
- };
9778
- const schema$4 = objectType({
9779
- email: stringType().email()
9780
- });
9781
9570
  const Email = () => {
9782
9571
  const { id } = useParams();
9783
9572
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9800,7 +9589,7 @@ const EmailForm = ({ order }) => {
9800
9589
  defaultValues: {
9801
9590
  email: order.email ?? ""
9802
9591
  },
9803
- resolver: zodResolver(schema$3)
9592
+ resolver: zodResolver(schema$5)
9804
9593
  });
9805
9594
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
9595
  const { handleSuccess } = useRouteModal();
@@ -9843,7 +9632,28 @@ const EmailForm = ({ order }) => {
9843
9632
  }
9844
9633
  ) });
9845
9634
  };
9846
- const schema$3 = objectType({
9635
+ const schema$5 = objectType({
9636
+ email: stringType().email()
9637
+ });
9638
+ const CustomItems = () => {
9639
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9640
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9641
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9642
+ ] });
9643
+ };
9644
+ const CustomItemsForm = () => {
9645
+ const form = useForm({
9646
+ resolver: zodResolver(schema$4)
9647
+ });
9648
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9649
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9650
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9651
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9652
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9653
+ ] }) })
9654
+ ] }) });
9655
+ };
9656
+ const schema$4 = objectType({
9847
9657
  email: stringType().email()
9848
9658
  });
9849
9659
  const NumberInput = forwardRef(
@@ -11475,7 +11285,7 @@ const SalesChannelForm = ({ order }) => {
11475
11285
  defaultValues: {
11476
11286
  sales_channel_id: order.sales_channel_id || ""
11477
11287
  },
11478
- resolver: zodResolver(schema$2)
11288
+ resolver: zodResolver(schema$3)
11479
11289
  });
11480
11290
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
11291
  const { handleSuccess } = useRouteModal();
@@ -11550,7 +11360,7 @@ const SalesChannelField = ({ control, order }) => {
11550
11360
  }
11551
11361
  );
11552
11362
  };
11553
- const schema$2 = objectType({
11363
+ const schema$3 = objectType({
11554
11364
  sales_channel_id: stringType().min(1)
11555
11365
  });
11556
11366
  const ShippingAddress = () => {
@@ -11585,7 +11395,7 @@ const ShippingAddressForm = ({ order }) => {
11585
11395
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11586
11396
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11587
11397
  },
11588
- resolver: zodResolver(schema$1)
11398
+ resolver: zodResolver(schema$2)
11589
11399
  });
11590
11400
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11591
11401
  const { handleSuccess } = useRouteModal();
@@ -11755,585 +11565,109 @@ const ShippingAddressForm = ({ order }) => {
11755
11565
  }
11756
11566
  ) });
11757
11567
  };
11758
- const schema$1 = addressSchema;
11759
- const TransferOwnership = () => {
11568
+ const schema$2 = addressSchema;
11569
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11570
+ const Shipping = () => {
11571
+ var _a;
11760
11572
  const { id } = useParams();
11761
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11762
- fields: "id,customer_id,customer.*"
11573
+ const { order, isPending, isError, error } = useOrder(id, {
11574
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11763
11575
  });
11576
+ const {
11577
+ order: preview,
11578
+ isPending: isPreviewPending,
11579
+ isError: isPreviewError,
11580
+ error: previewError
11581
+ } = useOrderPreview(id);
11582
+ useInitiateOrderEdit({ preview });
11583
+ const { onCancel } = useCancelOrderEdit({ preview });
11764
11584
  if (isError) {
11765
11585
  throw error;
11766
11586
  }
11767
- const isReady = !isPending && !!draft_order;
11768
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11769
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11770
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11771
- /* @__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" }) })
11772
- ] }),
11773
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11774
- ] });
11587
+ if (isPreviewError) {
11588
+ throw previewError;
11589
+ }
11590
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11591
+ const isReady = preview && !isPreviewPending && order && !isPending;
11592
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11593
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11594
+ /* @__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: [
11595
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11596
+ /* @__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." }) })
11597
+ ] }) }) }),
11598
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11599
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11600
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11601
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11602
+ ] }) });
11775
11603
  };
11776
- const TransferOwnershipForm = ({ order }) => {
11777
- var _a, _b;
11778
- const form = useForm({
11779
- defaultValues: {
11780
- customer_id: order.customer_id || ""
11604
+ const ShippingForm = ({ preview, order }) => {
11605
+ var _a;
11606
+ const { setIsOpen } = useStackedModal();
11607
+ const [isSubmitting, setIsSubmitting] = useState(false);
11608
+ const [data, setData] = useState(null);
11609
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11610
+ const { shipping_options } = useShippingOptions(
11611
+ {
11612
+ id: appliedShippingOptionIds,
11613
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11781
11614
  },
11782
- resolver: zodResolver(schema)
11783
- });
11784
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11615
+ {
11616
+ enabled: appliedShippingOptionIds.length > 0
11617
+ }
11618
+ );
11619
+ const uniqueShippingProfiles = useMemo(() => {
11620
+ const profiles = /* @__PURE__ */ new Map();
11621
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11622
+ profiles.set(profile.id, profile);
11623
+ });
11624
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11625
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11626
+ });
11627
+ return Array.from(profiles.values());
11628
+ }, [order.items, shipping_options]);
11785
11629
  const { handleSuccess } = useRouteModal();
11786
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11787
- const currentCustomer = order.customer ? {
11788
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11789
- value: order.customer.id
11790
- } : null;
11791
- const onSubmit = form.handleSubmit(async (data) => {
11792
- await mutateAsync(
11793
- { customer_id: data.customer_id },
11794
- {
11795
- onSuccess: () => {
11796
- toast.success("Customer updated");
11797
- handleSuccess();
11798
- },
11799
- onError: (error) => {
11800
- toast.error(error.message);
11801
- }
11630
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11631
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11632
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11633
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11634
+ const onSubmit = async () => {
11635
+ setIsSubmitting(true);
11636
+ let requestSucceeded = false;
11637
+ await requestOrderEdit(void 0, {
11638
+ onError: (e) => {
11639
+ toast.error(`Failed to request order edit: ${e.message}`);
11640
+ },
11641
+ onSuccess: () => {
11642
+ requestSucceeded = true;
11802
11643
  }
11803
- );
11804
- });
11805
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11806
- KeyboundForm,
11807
- {
11808
- className: "flex flex-1 flex-col overflow-hidden",
11809
- onSubmit,
11810
- children: [
11811
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11812
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11813
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11814
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11815
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11816
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11817
- ] }),
11818
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11819
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11820
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11821
- ] })
11822
- ] }),
11823
- /* @__PURE__ */ jsx(
11824
- CustomerField,
11825
- {
11826
- control: form.control,
11827
- currentCustomerId: order.customer_id
11828
- }
11829
- )
11830
- ] }),
11831
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11832
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11833
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11834
- ] }) })
11835
- ]
11644
+ });
11645
+ if (!requestSucceeded) {
11646
+ setIsSubmitting(false);
11647
+ return;
11836
11648
  }
11837
- ) });
11838
- };
11839
- const CustomerField = ({ control, currentCustomerId }) => {
11840
- const customers = useComboboxData({
11841
- queryFn: async (params) => {
11842
- return await sdk.admin.customer.list({
11843
- ...params,
11844
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11845
- });
11649
+ await confirmOrderEdit(void 0, {
11650
+ onError: (e) => {
11651
+ toast.error(`Failed to confirm order edit: ${e.message}`);
11652
+ },
11653
+ onSuccess: () => {
11654
+ handleSuccess();
11655
+ },
11656
+ onSettled: () => {
11657
+ setIsSubmitting(false);
11658
+ }
11659
+ });
11660
+ };
11661
+ const onKeydown = useCallback(
11662
+ (e) => {
11663
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11664
+ if (data || isSubmitting) {
11665
+ return;
11666
+ }
11667
+ onSubmit();
11668
+ }
11846
11669
  },
11847
- queryKey: ["customers"],
11848
- getOptions: (data) => {
11849
- return data.customers.map((customer) => {
11850
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11851
- return {
11852
- label: name ? `${name} (${customer.email})` : customer.email,
11853
- value: customer.id
11854
- };
11855
- });
11856
- }
11857
- });
11858
- return /* @__PURE__ */ jsx(
11859
- Form$2.Field,
11860
- {
11861
- name: "customer_id",
11862
- control,
11863
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11864
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11865
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11866
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11867
- ] }),
11868
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11869
- Combobox,
11870
- {
11871
- options: customers.options,
11872
- fetchNextPage: customers.fetchNextPage,
11873
- isFetchingNextPage: customers.isFetchingNextPage,
11874
- searchValue: customers.searchValue,
11875
- onSearchValueChange: customers.onSearchValueChange,
11876
- placeholder: "Select customer",
11877
- ...field
11878
- }
11879
- ) }),
11880
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11881
- ] })
11882
- }
11883
- );
11884
- };
11885
- const Illustration = () => {
11886
- return /* @__PURE__ */ jsxs(
11887
- "svg",
11888
- {
11889
- width: "280",
11890
- height: "180",
11891
- viewBox: "0 0 280 180",
11892
- fill: "none",
11893
- xmlns: "http://www.w3.org/2000/svg",
11894
- children: [
11895
- /* @__PURE__ */ jsx(
11896
- "rect",
11897
- {
11898
- x: "0.00428286",
11899
- y: "-0.742904",
11900
- width: "33.5",
11901
- height: "65.5",
11902
- rx: "6.75",
11903
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11904
- fill: "#D4D4D8",
11905
- stroke: "#52525B",
11906
- strokeWidth: "1.5"
11907
- }
11908
- ),
11909
- /* @__PURE__ */ jsx(
11910
- "rect",
11911
- {
11912
- x: "0.00428286",
11913
- y: "-0.742904",
11914
- width: "33.5",
11915
- height: "65.5",
11916
- rx: "6.75",
11917
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11918
- fill: "white",
11919
- stroke: "#52525B",
11920
- strokeWidth: "1.5"
11921
- }
11922
- ),
11923
- /* @__PURE__ */ jsx(
11924
- "path",
11925
- {
11926
- d: "M180.579 107.142L179.126 107.959",
11927
- stroke: "#52525B",
11928
- strokeWidth: "1.5",
11929
- strokeLinecap: "round",
11930
- strokeLinejoin: "round"
11931
- }
11932
- ),
11933
- /* @__PURE__ */ jsx(
11934
- "path",
11935
- {
11936
- opacity: "0.88",
11937
- d: "M182.305 109.546L180.257 109.534",
11938
- stroke: "#52525B",
11939
- strokeWidth: "1.5",
11940
- strokeLinecap: "round",
11941
- strokeLinejoin: "round"
11942
- }
11943
- ),
11944
- /* @__PURE__ */ jsx(
11945
- "path",
11946
- {
11947
- opacity: "0.75",
11948
- d: "M180.551 111.93L179.108 111.096",
11949
- stroke: "#52525B",
11950
- strokeWidth: "1.5",
11951
- strokeLinecap: "round",
11952
- strokeLinejoin: "round"
11953
- }
11954
- ),
11955
- /* @__PURE__ */ jsx(
11956
- "path",
11957
- {
11958
- opacity: "0.63",
11959
- d: "M176.347 112.897L176.354 111.73",
11960
- stroke: "#52525B",
11961
- strokeWidth: "1.5",
11962
- strokeLinecap: "round",
11963
- strokeLinejoin: "round"
11964
- }
11965
- ),
11966
- /* @__PURE__ */ jsx(
11967
- "path",
11968
- {
11969
- opacity: "0.5",
11970
- d: "M172.153 111.881L173.606 111.064",
11971
- stroke: "#52525B",
11972
- strokeWidth: "1.5",
11973
- strokeLinecap: "round",
11974
- strokeLinejoin: "round"
11975
- }
11976
- ),
11977
- /* @__PURE__ */ jsx(
11978
- "path",
11979
- {
11980
- opacity: "0.38",
11981
- d: "M170.428 109.478L172.476 109.489",
11982
- stroke: "#52525B",
11983
- strokeWidth: "1.5",
11984
- strokeLinecap: "round",
11985
- strokeLinejoin: "round"
11986
- }
11987
- ),
11988
- /* @__PURE__ */ jsx(
11989
- "path",
11990
- {
11991
- opacity: "0.25",
11992
- d: "M172.181 107.094L173.624 107.928",
11993
- stroke: "#52525B",
11994
- strokeWidth: "1.5",
11995
- strokeLinecap: "round",
11996
- strokeLinejoin: "round"
11997
- }
11998
- ),
11999
- /* @__PURE__ */ jsx(
12000
- "path",
12001
- {
12002
- opacity: "0.13",
12003
- d: "M176.386 106.126L176.379 107.294",
12004
- stroke: "#52525B",
12005
- strokeWidth: "1.5",
12006
- strokeLinecap: "round",
12007
- strokeLinejoin: "round"
12008
- }
12009
- ),
12010
- /* @__PURE__ */ jsx(
12011
- "rect",
12012
- {
12013
- width: "12",
12014
- height: "3",
12015
- rx: "1.5",
12016
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12017
- fill: "#D4D4D8"
12018
- }
12019
- ),
12020
- /* @__PURE__ */ jsx(
12021
- "rect",
12022
- {
12023
- x: "0.00428286",
12024
- y: "-0.742904",
12025
- width: "33.5",
12026
- height: "65.5",
12027
- rx: "6.75",
12028
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12029
- fill: "#D4D4D8",
12030
- stroke: "#52525B",
12031
- strokeWidth: "1.5"
12032
- }
12033
- ),
12034
- /* @__PURE__ */ jsx(
12035
- "rect",
12036
- {
12037
- x: "0.00428286",
12038
- y: "-0.742904",
12039
- width: "33.5",
12040
- height: "65.5",
12041
- rx: "6.75",
12042
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12043
- fill: "white",
12044
- stroke: "#52525B",
12045
- strokeWidth: "1.5"
12046
- }
12047
- ),
12048
- /* @__PURE__ */ jsx(
12049
- "rect",
12050
- {
12051
- width: "12",
12052
- height: "3",
12053
- rx: "1.5",
12054
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12055
- fill: "#D4D4D8"
12056
- }
12057
- ),
12058
- /* @__PURE__ */ jsx(
12059
- "rect",
12060
- {
12061
- width: "17",
12062
- height: "3",
12063
- rx: "1.5",
12064
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12065
- fill: "#D4D4D8"
12066
- }
12067
- ),
12068
- /* @__PURE__ */ jsx(
12069
- "rect",
12070
- {
12071
- width: "12",
12072
- height: "3",
12073
- rx: "1.5",
12074
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12075
- fill: "#D4D4D8"
12076
- }
12077
- ),
12078
- /* @__PURE__ */ jsx(
12079
- "path",
12080
- {
12081
- 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",
12082
- fill: "#A1A1AA"
12083
- }
12084
- ),
12085
- /* @__PURE__ */ jsx(
12086
- "rect",
12087
- {
12088
- width: "17",
12089
- height: "3",
12090
- rx: "1.5",
12091
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12092
- fill: "#A1A1AA"
12093
- }
12094
- ),
12095
- /* @__PURE__ */ jsx(
12096
- "rect",
12097
- {
12098
- width: "12",
12099
- height: "3",
12100
- rx: "1.5",
12101
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12102
- fill: "#A1A1AA"
12103
- }
12104
- ),
12105
- /* @__PURE__ */ jsx(
12106
- "path",
12107
- {
12108
- 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",
12109
- fill: "#52525B"
12110
- }
12111
- ),
12112
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12113
- "path",
12114
- {
12115
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12116
- stroke: "#A1A1AA",
12117
- strokeWidth: "1.5",
12118
- strokeLinecap: "round",
12119
- strokeLinejoin: "round"
12120
- }
12121
- ) }),
12122
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12123
- "path",
12124
- {
12125
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12126
- stroke: "#A1A1AA",
12127
- strokeWidth: "1.5",
12128
- strokeLinecap: "round",
12129
- strokeLinejoin: "round"
12130
- }
12131
- ) }),
12132
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12133
- "path",
12134
- {
12135
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12136
- stroke: "#A1A1AA",
12137
- strokeWidth: "1.5",
12138
- strokeLinecap: "round",
12139
- strokeLinejoin: "round"
12140
- }
12141
- ) }),
12142
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12143
- "path",
12144
- {
12145
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12146
- stroke: "#A1A1AA",
12147
- strokeWidth: "1.5",
12148
- strokeLinecap: "round",
12149
- strokeLinejoin: "round"
12150
- }
12151
- ) }),
12152
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12153
- "path",
12154
- {
12155
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12156
- stroke: "#A1A1AA",
12157
- strokeWidth: "1.5",
12158
- strokeLinecap: "round",
12159
- strokeLinejoin: "round"
12160
- }
12161
- ) }),
12162
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12163
- "path",
12164
- {
12165
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12166
- stroke: "#A1A1AA",
12167
- strokeWidth: "1.5",
12168
- strokeLinecap: "round",
12169
- strokeLinejoin: "round"
12170
- }
12171
- ) }),
12172
- /* @__PURE__ */ jsxs("defs", { children: [
12173
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12174
- "rect",
12175
- {
12176
- width: "12",
12177
- height: "12",
12178
- fill: "white",
12179
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12180
- }
12181
- ) }),
12182
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12183
- "rect",
12184
- {
12185
- width: "12",
12186
- height: "12",
12187
- fill: "white",
12188
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12189
- }
12190
- ) }),
12191
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12192
- "rect",
12193
- {
12194
- width: "12",
12195
- height: "12",
12196
- fill: "white",
12197
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12198
- }
12199
- ) }),
12200
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12201
- "rect",
12202
- {
12203
- width: "12",
12204
- height: "12",
12205
- fill: "white",
12206
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12207
- }
12208
- ) }),
12209
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12210
- "rect",
12211
- {
12212
- width: "12",
12213
- height: "12",
12214
- fill: "white",
12215
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12216
- }
12217
- ) }),
12218
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12219
- "rect",
12220
- {
12221
- width: "12",
12222
- height: "12",
12223
- fill: "white",
12224
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12225
- }
12226
- ) })
12227
- ] })
12228
- ]
12229
- }
12230
- );
12231
- };
12232
- const schema = objectType({
12233
- customer_id: stringType().min(1)
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]
11670
+ [data, isSubmitting, onSubmit]
12337
11671
  );
12338
11672
  useEffect(() => {
12339
11673
  document.addEventListener("keydown", onKeydown);
@@ -12620,425 +11954,1091 @@ const ShippingForm = ({ preview, order }) => {
12620
11954
  );
12621
11955
  }) })
12622
11956
  ] }) })
12623
- ] }) }),
12624
- /* @__PURE__ */ jsx(
12625
- StackedFocusModal,
11957
+ ] }) }),
11958
+ /* @__PURE__ */ jsx(
11959
+ StackedFocusModal,
11960
+ {
11961
+ id: STACKED_FOCUS_MODAL_ID,
11962
+ onOpenChangeCallback: (open) => {
11963
+ if (!open) {
11964
+ setData(null);
11965
+ }
11966
+ return open;
11967
+ },
11968
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11969
+ }
11970
+ )
11971
+ ] }),
11972
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11973
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11974
+ /* @__PURE__ */ jsx(
11975
+ Button,
11976
+ {
11977
+ size: "small",
11978
+ type: "button",
11979
+ isLoading: isSubmitting,
11980
+ onClick: onSubmit,
11981
+ children: "Save"
11982
+ }
11983
+ )
11984
+ ] }) })
11985
+ ] });
11986
+ };
11987
+ const StackedModalTrigger = ({
11988
+ shippingProfileId,
11989
+ shippingOption,
11990
+ shippingMethod,
11991
+ setData,
11992
+ children
11993
+ }) => {
11994
+ const { setIsOpen, getIsOpen } = useStackedModal();
11995
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11996
+ const onToggle = () => {
11997
+ if (isOpen) {
11998
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11999
+ setData(null);
12000
+ } else {
12001
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12002
+ setData({
12003
+ shippingProfileId,
12004
+ shippingOption,
12005
+ shippingMethod
12006
+ });
12007
+ }
12008
+ };
12009
+ return /* @__PURE__ */ jsx(
12010
+ Button,
12011
+ {
12012
+ size: "small",
12013
+ variant: "secondary",
12014
+ onClick: onToggle,
12015
+ className: "text-ui-fg-primary shrink-0",
12016
+ children
12017
+ }
12018
+ );
12019
+ };
12020
+ const ShippingProfileForm = ({
12021
+ data,
12022
+ order,
12023
+ preview
12024
+ }) => {
12025
+ var _a, _b, _c, _d, _e, _f;
12026
+ const { setIsOpen } = useStackedModal();
12027
+ const form = useForm({
12028
+ resolver: zodResolver(shippingMethodSchema),
12029
+ defaultValues: {
12030
+ 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,
12031
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12032
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12033
+ }
12034
+ });
12035
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12036
+ const {
12037
+ mutateAsync: updateShippingMethod,
12038
+ isPending: isUpdatingShippingMethod
12039
+ } = useDraftOrderUpdateShippingMethod(order.id);
12040
+ const onSubmit = form.handleSubmit(async (values) => {
12041
+ if (isEqual(values, form.formState.defaultValues)) {
12042
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12043
+ return;
12044
+ }
12045
+ if (data.shippingMethod) {
12046
+ await updateShippingMethod(
12047
+ {
12048
+ method_id: data.shippingMethod.id,
12049
+ shipping_option_id: values.shipping_option_id,
12050
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12051
+ },
12052
+ {
12053
+ onError: (e) => {
12054
+ toast.error(e.message);
12055
+ },
12056
+ onSuccess: () => {
12057
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12058
+ }
12059
+ }
12060
+ );
12061
+ return;
12062
+ }
12063
+ await addShippingMethod(
12064
+ {
12065
+ shipping_option_id: values.shipping_option_id,
12066
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12067
+ },
12068
+ {
12069
+ onError: (e) => {
12070
+ toast.error(e.message);
12071
+ },
12072
+ onSuccess: () => {
12073
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12074
+ }
12075
+ }
12076
+ );
12077
+ });
12078
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12079
+ KeyboundForm,
12080
+ {
12081
+ className: "flex h-full flex-col overflow-hidden",
12082
+ onSubmit,
12083
+ children: [
12084
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12085
+ /* @__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: [
12086
+ /* @__PURE__ */ jsxs("div", { children: [
12087
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12088
+ /* @__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." }) })
12089
+ ] }),
12090
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12091
+ /* @__PURE__ */ jsx(
12092
+ LocationField,
12093
+ {
12094
+ control: form.control,
12095
+ setValue: form.setValue
12096
+ }
12097
+ ),
12098
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12099
+ /* @__PURE__ */ jsx(
12100
+ ShippingOptionField,
12101
+ {
12102
+ shippingProfileId: data.shippingProfileId,
12103
+ preview,
12104
+ control: form.control
12105
+ }
12106
+ ),
12107
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12108
+ /* @__PURE__ */ jsx(
12109
+ CustomAmountField,
12110
+ {
12111
+ control: form.control,
12112
+ currencyCode: order.currency_code
12113
+ }
12114
+ ),
12115
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12116
+ /* @__PURE__ */ jsx(
12117
+ ItemsPreview,
12118
+ {
12119
+ order,
12120
+ shippingProfileId: data.shippingProfileId
12121
+ }
12122
+ )
12123
+ ] }) }) }),
12124
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12125
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12126
+ /* @__PURE__ */ jsx(
12127
+ Button,
12128
+ {
12129
+ size: "small",
12130
+ type: "submit",
12131
+ isLoading: isPending || isUpdatingShippingMethod,
12132
+ children: data.shippingMethod ? "Update" : "Add"
12133
+ }
12134
+ )
12135
+ ] }) })
12136
+ ]
12137
+ }
12138
+ ) }) });
12139
+ };
12140
+ const shippingMethodSchema = objectType({
12141
+ location_id: stringType(),
12142
+ shipping_option_id: stringType(),
12143
+ custom_amount: unionType([numberType(), stringType()]).optional()
12144
+ });
12145
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12146
+ const matches = order.items.filter(
12147
+ (item) => {
12148
+ var _a, _b, _c;
12149
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12150
+ }
12151
+ );
12152
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12153
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12154
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12155
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12156
+ ] }) }),
12157
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12158
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12159
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12160
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12161
+ ] }),
12162
+ /* @__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(
12163
+ "div",
12626
12164
  {
12627
- id: STACKED_FOCUS_MODAL_ID,
12628
- onOpenChangeCallback: (open) => {
12629
- if (!open) {
12630
- setData(null);
12165
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12166
+ children: [
12167
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12168
+ /* @__PURE__ */ jsx(
12169
+ Thumbnail,
12170
+ {
12171
+ thumbnail: item.thumbnail,
12172
+ alt: item.product_title ?? void 0
12173
+ }
12174
+ ),
12175
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12176
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12177
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12178
+ /* @__PURE__ */ jsxs(
12179
+ Text,
12180
+ {
12181
+ size: "small",
12182
+ leading: "compact",
12183
+ className: "text-ui-fg-subtle",
12184
+ children: [
12185
+ "(",
12186
+ item.variant_title,
12187
+ ")"
12188
+ ]
12189
+ }
12190
+ )
12191
+ ] }),
12192
+ /* @__PURE__ */ jsx(
12193
+ Text,
12194
+ {
12195
+ size: "small",
12196
+ leading: "compact",
12197
+ className: "text-ui-fg-subtle",
12198
+ children: item.variant_sku
12199
+ }
12200
+ )
12201
+ ] })
12202
+ ] }),
12203
+ /* @__PURE__ */ jsxs(
12204
+ Text,
12205
+ {
12206
+ size: "small",
12207
+ leading: "compact",
12208
+ className: "text-ui-fg-subtle",
12209
+ children: [
12210
+ item.quantity,
12211
+ "x"
12212
+ ]
12213
+ }
12214
+ )
12215
+ ]
12216
+ },
12217
+ item.id
12218
+ )) : /* @__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: [
12219
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12220
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12221
+ 'No items found for "',
12222
+ query,
12223
+ '".'
12224
+ ] })
12225
+ ] }) })
12226
+ ] })
12227
+ ] });
12228
+ };
12229
+ const LocationField = ({ control, setValue }) => {
12230
+ const locations = useComboboxData({
12231
+ queryKey: ["locations"],
12232
+ queryFn: async (params) => {
12233
+ return await sdk.admin.stockLocation.list(params);
12234
+ },
12235
+ getOptions: (data) => {
12236
+ return data.stock_locations.map((location) => ({
12237
+ label: location.name,
12238
+ value: location.id
12239
+ }));
12240
+ }
12241
+ });
12242
+ return /* @__PURE__ */ jsx(
12243
+ Form$2.Field,
12244
+ {
12245
+ control,
12246
+ name: "location_id",
12247
+ render: ({ field: { onChange, ...field } }) => {
12248
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12249
+ /* @__PURE__ */ jsxs("div", { children: [
12250
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12251
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12252
+ ] }),
12253
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12254
+ Combobox,
12255
+ {
12256
+ options: locations.options,
12257
+ fetchNextPage: locations.fetchNextPage,
12258
+ isFetchingNextPage: locations.isFetchingNextPage,
12259
+ searchValue: locations.searchValue,
12260
+ onSearchValueChange: locations.onSearchValueChange,
12261
+ placeholder: "Select location",
12262
+ onChange: (value) => {
12263
+ setValue("shipping_option_id", "", {
12264
+ shouldDirty: true,
12265
+ shouldTouch: true
12266
+ });
12267
+ onChange(value);
12268
+ },
12269
+ ...field
12631
12270
  }
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"
12271
+ ) })
12272
+ ] }) });
12273
+ }
12274
+ }
12275
+ );
12276
+ };
12277
+ const ShippingOptionField = ({
12278
+ shippingProfileId,
12279
+ preview,
12280
+ control
12281
+ }) => {
12282
+ var _a;
12283
+ const locationId = useWatch({ control, name: "location_id" });
12284
+ const shippingOptions = useComboboxData({
12285
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12286
+ queryFn: async (params) => {
12287
+ return await sdk.admin.shippingOption.list({
12288
+ ...params,
12289
+ stock_location_id: locationId,
12290
+ shipping_profile_id: shippingProfileId
12291
+ });
12292
+ },
12293
+ getOptions: (data) => {
12294
+ return data.shipping_options.map((option) => {
12295
+ var _a2;
12296
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12297
+ (r) => r.attribute === "is_return" && r.value === "true"
12298
+ )) {
12299
+ return void 0;
12648
12300
  }
12649
- )
12650
- ] }) })
12651
- ] });
12301
+ return {
12302
+ label: option.name,
12303
+ value: option.id
12304
+ };
12305
+ }).filter(Boolean);
12306
+ },
12307
+ enabled: !!locationId && !!shippingProfileId,
12308
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12309
+ });
12310
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12311
+ return /* @__PURE__ */ jsx(
12312
+ Form$2.Field,
12313
+ {
12314
+ control,
12315
+ name: "shipping_option_id",
12316
+ render: ({ field }) => {
12317
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12318
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12319
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12320
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12321
+ ] }),
12322
+ /* @__PURE__ */ jsx(
12323
+ ConditionalTooltip,
12324
+ {
12325
+ content: tooltipContent,
12326
+ showTooltip: !locationId || !shippingProfileId,
12327
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12328
+ Combobox,
12329
+ {
12330
+ options: shippingOptions.options,
12331
+ fetchNextPage: shippingOptions.fetchNextPage,
12332
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12333
+ searchValue: shippingOptions.searchValue,
12334
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12335
+ placeholder: "Select shipping option",
12336
+ ...field,
12337
+ disabled: !locationId || !shippingProfileId
12338
+ }
12339
+ ) }) })
12340
+ }
12341
+ )
12342
+ ] }) });
12343
+ }
12344
+ }
12345
+ );
12652
12346
  };
12653
- const StackedModalTrigger = ({
12654
- shippingProfileId,
12655
- shippingOption,
12656
- shippingMethod,
12657
- setData,
12658
- children
12347
+ const CustomAmountField = ({
12348
+ control,
12349
+ currencyCode
12659
12350
  }) => {
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
12351
  return /* @__PURE__ */ jsx(
12676
- Button,
12352
+ Form$2.Field,
12677
12353
  {
12678
- size: "small",
12679
- variant: "secondary",
12680
- onClick: onToggle,
12681
- className: "text-ui-fg-primary shrink-0",
12682
- children
12354
+ control,
12355
+ name: "custom_amount",
12356
+ render: ({ field: { onChange, ...field } }) => {
12357
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12358
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12359
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12360
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12361
+ ] }),
12362
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12363
+ CurrencyInput,
12364
+ {
12365
+ ...field,
12366
+ onValueChange: (value) => onChange(value),
12367
+ symbol: getNativeSymbol(currencyCode),
12368
+ code: currencyCode
12369
+ }
12370
+ ) })
12371
+ ] });
12372
+ }
12683
12373
  }
12684
12374
  );
12685
12375
  };
12686
- const ShippingProfileForm = ({
12687
- data,
12688
- order,
12689
- preview
12690
- }) => {
12691
- var _a, _b, _c, _d, _e, _f;
12692
- const { setIsOpen } = useStackedModal();
12376
+ const TransferOwnership = () => {
12377
+ const { id } = useParams();
12378
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12379
+ fields: "id,customer_id,customer.*"
12380
+ });
12381
+ if (isError) {
12382
+ throw error;
12383
+ }
12384
+ const isReady = !isPending && !!draft_order;
12385
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12386
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12387
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12388
+ /* @__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" }) })
12389
+ ] }),
12390
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12391
+ ] });
12392
+ };
12393
+ const TransferOwnershipForm = ({ order }) => {
12394
+ var _a, _b;
12693
12395
  const form = useForm({
12694
- resolver: zodResolver(shippingMethodSchema),
12695
12396
  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
12397
+ customer_id: order.customer_id || ""
12398
+ },
12399
+ resolver: zodResolver(schema$1)
12400
+ });
12401
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12402
+ const { handleSuccess } = useRouteModal();
12403
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12404
+ const currentCustomer = order.customer ? {
12405
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12406
+ value: order.customer.id
12407
+ } : null;
12408
+ const onSubmit = form.handleSubmit(async (data) => {
12409
+ await mutateAsync(
12410
+ { customer_id: data.customer_id },
12411
+ {
12412
+ onSuccess: () => {
12413
+ toast.success("Customer updated");
12414
+ handleSuccess();
12415
+ },
12416
+ onError: (error) => {
12417
+ toast.error(error.message);
12418
+ }
12419
+ }
12420
+ );
12421
+ });
12422
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12423
+ KeyboundForm,
12424
+ {
12425
+ className: "flex flex-1 flex-col overflow-hidden",
12426
+ onSubmit,
12427
+ children: [
12428
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12429
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12430
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12431
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12432
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12433
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12434
+ ] }),
12435
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12436
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12437
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12438
+ ] })
12439
+ ] }),
12440
+ /* @__PURE__ */ jsx(
12441
+ CustomerField,
12442
+ {
12443
+ control: form.control,
12444
+ currentCustomerId: order.customer_id
12445
+ }
12446
+ )
12447
+ ] }),
12448
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12449
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12450
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12451
+ ] }) })
12452
+ ]
12453
+ }
12454
+ ) });
12455
+ };
12456
+ const CustomerField = ({ control, currentCustomerId }) => {
12457
+ const customers = useComboboxData({
12458
+ queryFn: async (params) => {
12459
+ return await sdk.admin.customer.list({
12460
+ ...params,
12461
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12462
+ });
12463
+ },
12464
+ queryKey: ["customers"],
12465
+ getOptions: (data) => {
12466
+ return data.customers.map((customer) => {
12467
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12468
+ return {
12469
+ label: name ? `${name} (${customer.email})` : customer.email,
12470
+ value: customer.id
12471
+ };
12472
+ });
12699
12473
  }
12700
12474
  });
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;
12475
+ return /* @__PURE__ */ jsx(
12476
+ Form$2.Field,
12477
+ {
12478
+ name: "customer_id",
12479
+ control,
12480
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12481
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12482
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12483
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12484
+ ] }),
12485
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12486
+ Combobox,
12487
+ {
12488
+ options: customers.options,
12489
+ fetchNextPage: customers.fetchNextPage,
12490
+ isFetchingNextPage: customers.isFetchingNextPage,
12491
+ searchValue: customers.searchValue,
12492
+ onSearchValueChange: customers.onSearchValueChange,
12493
+ placeholder: "Select customer",
12494
+ ...field
12495
+ }
12496
+ ) }),
12497
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12498
+ ] })
12710
12499
  }
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);
12500
+ );
12501
+ };
12502
+ const Illustration = () => {
12503
+ return /* @__PURE__ */ jsxs(
12504
+ "svg",
12505
+ {
12506
+ width: "280",
12507
+ height: "180",
12508
+ viewBox: "0 0 280 180",
12509
+ fill: "none",
12510
+ xmlns: "http://www.w3.org/2000/svg",
12511
+ children: [
12512
+ /* @__PURE__ */ jsx(
12513
+ "rect",
12514
+ {
12515
+ x: "0.00428286",
12516
+ y: "-0.742904",
12517
+ width: "33.5",
12518
+ height: "65.5",
12519
+ rx: "6.75",
12520
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12521
+ fill: "#D4D4D8",
12522
+ stroke: "#52525B",
12523
+ strokeWidth: "1.5"
12524
+ }
12525
+ ),
12526
+ /* @__PURE__ */ jsx(
12527
+ "rect",
12528
+ {
12529
+ x: "0.00428286",
12530
+ y: "-0.742904",
12531
+ width: "33.5",
12532
+ height: "65.5",
12533
+ rx: "6.75",
12534
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12535
+ fill: "white",
12536
+ stroke: "#52525B",
12537
+ strokeWidth: "1.5"
12538
+ }
12539
+ ),
12540
+ /* @__PURE__ */ jsx(
12541
+ "path",
12542
+ {
12543
+ d: "M180.579 107.142L179.126 107.959",
12544
+ stroke: "#52525B",
12545
+ strokeWidth: "1.5",
12546
+ strokeLinecap: "round",
12547
+ strokeLinejoin: "round"
12724
12548
  }
12725
- }
12726
- );
12727
- return;
12728
- }
12729
- await addShippingMethod(
12730
- {
12731
- shipping_option_id: values.shipping_option_id,
12732
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12733
- },
12734
- {
12735
- onError: (e) => {
12736
- toast.error(e.message);
12737
- },
12738
- onSuccess: () => {
12739
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12740
- }
12741
- }
12742
- );
12743
- });
12744
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12745
- KeyboundForm,
12746
- {
12747
- className: "flex h-full flex-col overflow-hidden",
12748
- onSubmit,
12749
- 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." }) })
12755
- ] }),
12756
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12757
- /* @__PURE__ */ jsx(
12758
- LocationField,
12549
+ ),
12550
+ /* @__PURE__ */ jsx(
12551
+ "path",
12552
+ {
12553
+ opacity: "0.88",
12554
+ d: "M182.305 109.546L180.257 109.534",
12555
+ stroke: "#52525B",
12556
+ strokeWidth: "1.5",
12557
+ strokeLinecap: "round",
12558
+ strokeLinejoin: "round"
12559
+ }
12560
+ ),
12561
+ /* @__PURE__ */ jsx(
12562
+ "path",
12563
+ {
12564
+ opacity: "0.75",
12565
+ d: "M180.551 111.93L179.108 111.096",
12566
+ stroke: "#52525B",
12567
+ strokeWidth: "1.5",
12568
+ strokeLinecap: "round",
12569
+ strokeLinejoin: "round"
12570
+ }
12571
+ ),
12572
+ /* @__PURE__ */ jsx(
12573
+ "path",
12574
+ {
12575
+ opacity: "0.63",
12576
+ d: "M176.347 112.897L176.354 111.73",
12577
+ stroke: "#52525B",
12578
+ strokeWidth: "1.5",
12579
+ strokeLinecap: "round",
12580
+ strokeLinejoin: "round"
12581
+ }
12582
+ ),
12583
+ /* @__PURE__ */ jsx(
12584
+ "path",
12585
+ {
12586
+ opacity: "0.5",
12587
+ d: "M172.153 111.881L173.606 111.064",
12588
+ stroke: "#52525B",
12589
+ strokeWidth: "1.5",
12590
+ strokeLinecap: "round",
12591
+ strokeLinejoin: "round"
12592
+ }
12593
+ ),
12594
+ /* @__PURE__ */ jsx(
12595
+ "path",
12596
+ {
12597
+ opacity: "0.38",
12598
+ d: "M170.428 109.478L172.476 109.489",
12599
+ stroke: "#52525B",
12600
+ strokeWidth: "1.5",
12601
+ strokeLinecap: "round",
12602
+ strokeLinejoin: "round"
12603
+ }
12604
+ ),
12605
+ /* @__PURE__ */ jsx(
12606
+ "path",
12607
+ {
12608
+ opacity: "0.25",
12609
+ d: "M172.181 107.094L173.624 107.928",
12610
+ stroke: "#52525B",
12611
+ strokeWidth: "1.5",
12612
+ strokeLinecap: "round",
12613
+ strokeLinejoin: "round"
12614
+ }
12615
+ ),
12616
+ /* @__PURE__ */ jsx(
12617
+ "path",
12618
+ {
12619
+ opacity: "0.13",
12620
+ d: "M176.386 106.126L176.379 107.294",
12621
+ stroke: "#52525B",
12622
+ strokeWidth: "1.5",
12623
+ strokeLinecap: "round",
12624
+ strokeLinejoin: "round"
12625
+ }
12626
+ ),
12627
+ /* @__PURE__ */ jsx(
12628
+ "rect",
12629
+ {
12630
+ width: "12",
12631
+ height: "3",
12632
+ rx: "1.5",
12633
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12634
+ fill: "#D4D4D8"
12635
+ }
12636
+ ),
12637
+ /* @__PURE__ */ jsx(
12638
+ "rect",
12639
+ {
12640
+ x: "0.00428286",
12641
+ y: "-0.742904",
12642
+ width: "33.5",
12643
+ height: "65.5",
12644
+ rx: "6.75",
12645
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12646
+ fill: "#D4D4D8",
12647
+ stroke: "#52525B",
12648
+ strokeWidth: "1.5"
12649
+ }
12650
+ ),
12651
+ /* @__PURE__ */ jsx(
12652
+ "rect",
12653
+ {
12654
+ x: "0.00428286",
12655
+ y: "-0.742904",
12656
+ width: "33.5",
12657
+ height: "65.5",
12658
+ rx: "6.75",
12659
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12660
+ fill: "white",
12661
+ stroke: "#52525B",
12662
+ strokeWidth: "1.5"
12663
+ }
12664
+ ),
12665
+ /* @__PURE__ */ jsx(
12666
+ "rect",
12667
+ {
12668
+ width: "12",
12669
+ height: "3",
12670
+ rx: "1.5",
12671
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12672
+ fill: "#D4D4D8"
12673
+ }
12674
+ ),
12675
+ /* @__PURE__ */ jsx(
12676
+ "rect",
12677
+ {
12678
+ width: "17",
12679
+ height: "3",
12680
+ rx: "1.5",
12681
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12682
+ fill: "#D4D4D8"
12683
+ }
12684
+ ),
12685
+ /* @__PURE__ */ jsx(
12686
+ "rect",
12687
+ {
12688
+ width: "12",
12689
+ height: "3",
12690
+ rx: "1.5",
12691
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12692
+ fill: "#D4D4D8"
12693
+ }
12694
+ ),
12695
+ /* @__PURE__ */ jsx(
12696
+ "path",
12697
+ {
12698
+ 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",
12699
+ fill: "#A1A1AA"
12700
+ }
12701
+ ),
12702
+ /* @__PURE__ */ jsx(
12703
+ "rect",
12704
+ {
12705
+ width: "17",
12706
+ height: "3",
12707
+ rx: "1.5",
12708
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12709
+ fill: "#A1A1AA"
12710
+ }
12711
+ ),
12712
+ /* @__PURE__ */ jsx(
12713
+ "rect",
12714
+ {
12715
+ width: "12",
12716
+ height: "3",
12717
+ rx: "1.5",
12718
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12719
+ fill: "#A1A1AA"
12720
+ }
12721
+ ),
12722
+ /* @__PURE__ */ jsx(
12723
+ "path",
12724
+ {
12725
+ 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",
12726
+ fill: "#52525B"
12727
+ }
12728
+ ),
12729
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12730
+ "path",
12731
+ {
12732
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12733
+ stroke: "#A1A1AA",
12734
+ strokeWidth: "1.5",
12735
+ strokeLinecap: "round",
12736
+ strokeLinejoin: "round"
12737
+ }
12738
+ ) }),
12739
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12740
+ "path",
12741
+ {
12742
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12743
+ stroke: "#A1A1AA",
12744
+ strokeWidth: "1.5",
12745
+ strokeLinecap: "round",
12746
+ strokeLinejoin: "round"
12747
+ }
12748
+ ) }),
12749
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12750
+ "path",
12751
+ {
12752
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12753
+ stroke: "#A1A1AA",
12754
+ strokeWidth: "1.5",
12755
+ strokeLinecap: "round",
12756
+ strokeLinejoin: "round"
12757
+ }
12758
+ ) }),
12759
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12760
+ "path",
12761
+ {
12762
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12763
+ stroke: "#A1A1AA",
12764
+ strokeWidth: "1.5",
12765
+ strokeLinecap: "round",
12766
+ strokeLinejoin: "round"
12767
+ }
12768
+ ) }),
12769
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12770
+ "path",
12771
+ {
12772
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12773
+ stroke: "#A1A1AA",
12774
+ strokeWidth: "1.5",
12775
+ strokeLinecap: "round",
12776
+ strokeLinejoin: "round"
12777
+ }
12778
+ ) }),
12779
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12780
+ "path",
12781
+ {
12782
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12783
+ stroke: "#A1A1AA",
12784
+ strokeWidth: "1.5",
12785
+ strokeLinecap: "round",
12786
+ strokeLinejoin: "round"
12787
+ }
12788
+ ) }),
12789
+ /* @__PURE__ */ jsxs("defs", { children: [
12790
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12791
+ "rect",
12759
12792
  {
12760
- control: form.control,
12761
- setValue: form.setValue
12793
+ width: "12",
12794
+ height: "12",
12795
+ fill: "white",
12796
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12762
12797
  }
12763
- ),
12764
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12765
- /* @__PURE__ */ jsx(
12766
- ShippingOptionField,
12798
+ ) }),
12799
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12800
+ "rect",
12767
12801
  {
12768
- shippingProfileId: data.shippingProfileId,
12769
- preview,
12770
- control: form.control
12802
+ width: "12",
12803
+ height: "12",
12804
+ fill: "white",
12805
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12771
12806
  }
12772
- ),
12773
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12774
- /* @__PURE__ */ jsx(
12775
- CustomAmountField,
12807
+ ) }),
12808
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12809
+ "rect",
12776
12810
  {
12777
- control: form.control,
12778
- currencyCode: order.currency_code
12811
+ width: "12",
12812
+ height: "12",
12813
+ fill: "white",
12814
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12779
12815
  }
12780
- ),
12781
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12782
- /* @__PURE__ */ jsx(
12783
- ItemsPreview,
12816
+ ) }),
12817
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12818
+ "rect",
12784
12819
  {
12785
- order,
12786
- shippingProfileId: data.shippingProfileId
12820
+ width: "12",
12821
+ height: "12",
12822
+ fill: "white",
12823
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12787
12824
  }
12788
- )
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" }) }),
12792
- /* @__PURE__ */ jsx(
12793
- Button,
12825
+ ) }),
12826
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12827
+ "rect",
12794
12828
  {
12795
- size: "small",
12796
- type: "submit",
12797
- isLoading: isPending || isUpdatingShippingMethod,
12798
- children: data.shippingMethod ? "Update" : "Add"
12829
+ width: "12",
12830
+ height: "12",
12831
+ fill: "white",
12832
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12799
12833
  }
12800
- )
12801
- ] }) })
12802
- ]
12803
- }
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
- ] });
12894
- };
12895
- const LocationField = ({ control, setValue }) => {
12896
- const locations = useComboboxData({
12897
- queryKey: ["locations"],
12898
- queryFn: async (params) => {
12899
- return await sdk.admin.stockLocation.list(params);
12900
- },
12901
- getOptions: (data) => {
12902
- return data.stock_locations.map((location) => ({
12903
- label: location.name,
12904
- value: location.id
12905
- }));
12906
- }
12907
- });
12908
- return /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12910
- {
12911
- 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,
12834
+ ) }),
12835
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12836
+ "rect",
12921
12837
  {
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
12838
+ width: "12",
12839
+ height: "12",
12840
+ fill: "white",
12841
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12936
12842
  }
12937
12843
  ) })
12938
- ] }) });
12939
- }
12844
+ ] })
12845
+ ]
12940
12846
  }
12941
12847
  );
12942
12848
  };
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
- });
12849
+ const schema$1 = objectType({
12850
+ customer_id: stringType().min(1)
12851
+ });
12852
+ const BillingAddress = () => {
12853
+ const { id } = useParams();
12854
+ const { order, isPending, isError, error } = useOrder(id, {
12855
+ fields: "+billing_address"
12856
+ });
12857
+ if (isError) {
12858
+ throw error;
12859
+ }
12860
+ const isReady = !isPending && !!order;
12861
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12863
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12865
+ ] }),
12866
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12867
+ ] });
12868
+ };
12869
+ const BillingAddressForm = ({ order }) => {
12870
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12871
+ const form = useForm({
12872
+ defaultValues: {
12873
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12958
12883
  },
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;
12884
+ resolver: zodResolver(schema)
12885
+ });
12886
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
+ const { handleSuccess } = useRouteModal();
12888
+ const onSubmit = form.handleSubmit(async (data) => {
12889
+ await mutateAsync(
12890
+ { billing_address: data },
12891
+ {
12892
+ onSuccess: () => {
12893
+ handleSuccess();
12894
+ },
12895
+ onError: (error) => {
12896
+ toast.error(error.message);
12966
12897
  }
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
12898
+ }
12899
+ );
12975
12900
  });
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,
12901
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
+ KeyboundForm,
12979
12903
  {
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." })
12904
+ className: "flex flex-1 flex-col overflow-hidden",
12905
+ onSubmit,
12906
+ children: [
12907
+ /* @__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: [
12908
+ /* @__PURE__ */ jsx(
12909
+ Form$2.Field,
12910
+ {
12911
+ control: form.control,
12912
+ name: "country_code",
12913
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
+ ] })
12918
+ }
12919
+ ),
12920
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
+ /* @__PURE__ */ jsx(
12922
+ Form$2.Field,
12923
+ {
12924
+ control: form.control,
12925
+ name: "first_name",
12926
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
+ ] })
12931
+ }
12932
+ ),
12933
+ /* @__PURE__ */ jsx(
12934
+ Form$2.Field,
12935
+ {
12936
+ control: form.control,
12937
+ name: "last_name",
12938
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
+ ] })
12943
+ }
12944
+ )
12987
12945
  ] }),
12988
12946
  /* @__PURE__ */ jsx(
12989
- ConditionalTooltip,
12947
+ Form$2.Field,
12990
12948
  {
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
- ) }) })
12949
+ control: form.control,
12950
+ name: "company",
12951
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
+ ] })
13006
12956
  }
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." })
12957
+ ),
12958
+ /* @__PURE__ */ jsx(
12959
+ Form$2.Field,
12960
+ {
12961
+ control: form.control,
12962
+ name: "address_1",
12963
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
+ ] })
12968
+ }
12969
+ ),
12970
+ /* @__PURE__ */ jsx(
12971
+ Form$2.Field,
12972
+ {
12973
+ control: form.control,
12974
+ name: "address_2",
12975
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
+ ] })
12980
+ }
12981
+ ),
12982
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
+ /* @__PURE__ */ jsx(
12984
+ Form$2.Field,
12985
+ {
12986
+ control: form.control,
12987
+ name: "postal_code",
12988
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
+ ] })
12993
+ }
12994
+ ),
12995
+ /* @__PURE__ */ jsx(
12996
+ Form$2.Field,
12997
+ {
12998
+ control: form.control,
12999
+ name: "city",
13000
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
+ ] })
13005
+ }
13006
+ )
13027
13007
  ] }),
13028
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13029
- CurrencyInput,
13008
+ /* @__PURE__ */ jsx(
13009
+ Form$2.Field,
13030
13010
  {
13031
- ...field,
13032
- onValueChange: (value) => onChange(value),
13033
- symbol: getNativeSymbol(currencyCode),
13034
- code: currencyCode
13011
+ control: form.control,
13012
+ name: "province",
13013
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
+ ] })
13035
13018
  }
13036
- ) })
13037
- ] });
13038
- }
13019
+ ),
13020
+ /* @__PURE__ */ jsx(
13021
+ Form$2.Field,
13022
+ {
13023
+ control: form.control,
13024
+ name: "phone",
13025
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
+ ] })
13030
+ }
13031
+ )
13032
+ ] }) }),
13033
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13036
+ ] }) })
13037
+ ]
13039
13038
  }
13040
- );
13039
+ ) });
13041
13040
  };
13041
+ const schema = addressSchema;
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13060,17 +13060,13 @@ const routeModule = {
13060
13060
  loader,
13061
13061
  children: [
13062
13062
  {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13063
+ Component: Email,
13064
+ path: "/draft-orders/:id/email"
13065
13065
  },
13066
13066
  {
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
- },
13074
13070
  {
13075
13071
  Component: Items,
13076
13072
  path: "/draft-orders/:id/items"
@@ -13091,13 +13087,17 @@ const routeModule = {
13091
13087
  Component: ShippingAddress,
13092
13088
  path: "/draft-orders/:id/shipping-address"
13093
13089
  },
13090
+ {
13091
+ Component: Shipping,
13092
+ path: "/draft-orders/:id/shipping"
13093
+ },
13094
13094
  {
13095
13095
  Component: TransferOwnership,
13096
13096
  path: "/draft-orders/:id/transfer-ownership"
13097
13097
  },
13098
13098
  {
13099
- Component: Shipping,
13100
- path: "/draft-orders/:id/shipping"
13099
+ Component: BillingAddress,
13100
+ path: "/draft-orders/:id/billing-address"
13101
13101
  }
13102
13102
  ]
13103
13103
  }