@medusajs/draft-order 2.11.4-preview-20251111120137 → 2.11.4-preview-20251111180137

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