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