@medusajs/draft-order 2.11.4-preview-20251113060137 → 2.11.4-preview-20251113120143

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