@medusajs/draft-order 2.11.0-preview-20251016120206 → 2.11.0-preview-20251016180154

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