@medusajs/draft-order 2.10.2-preview-20250910090158 → 2.10.2-preview-20250910113759

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.
@@ -9757,6 +9757,27 @@ const BillingAddressForm = ({ order }) => {
9757
9757
  ) });
9758
9758
  };
9759
9759
  const schema$5 = addressSchema;
9760
+ const CustomItems = () => {
9761
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
+ ] });
9765
+ };
9766
+ const CustomItemsForm = () => {
9767
+ const form = useForm({
9768
+ resolver: zodResolver(schema$4)
9769
+ });
9770
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
+ ] }) })
9776
+ ] }) });
9777
+ };
9778
+ const schema$4 = objectType({
9779
+ email: stringType().email()
9780
+ });
9760
9781
  const Email = () => {
9761
9782
  const { id } = useParams();
9762
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9779,7 +9800,7 @@ const EmailForm = ({ order }) => {
9779
9800
  defaultValues: {
9780
9801
  email: order.email ?? ""
9781
9802
  },
9782
- resolver: zodResolver(schema$4)
9803
+ resolver: zodResolver(schema$3)
9783
9804
  });
9784
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9785
9806
  const { handleSuccess } = useRouteModal();
@@ -9822,27 +9843,6 @@ const EmailForm = ({ order }) => {
9822
9843
  }
9823
9844
  ) });
9824
9845
  };
9825
- const schema$4 = objectType({
9826
- email: stringType().email()
9827
- });
9828
- const CustomItems = () => {
9829
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9830
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9831
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9832
- ] });
9833
- };
9834
- const CustomItemsForm = () => {
9835
- const form = useForm({
9836
- resolver: zodResolver(schema$3)
9837
- });
9838
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9839
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9840
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9841
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9842
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9843
- ] }) })
9844
- ] }) });
9845
- };
9846
9846
  const schema$3 = objectType({
9847
9847
  email: stringType().email()
9848
9848
  });
@@ -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,663 +11755,81 @@ const ShippingAddressForm = ({ order }) => {
11649
11755
  }
11650
11756
  ) });
11651
11757
  };
11652
- const schema$2 = addressSchema;
11653
- const TransferOwnership = () => {
11758
+ const schema$1 = addressSchema;
11759
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11760
+ const Shipping = () => {
11761
+ var _a;
11654
11762
  const { id } = useParams();
11655
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11656
- fields: "id,customer_id,customer.*"
11763
+ const { order, isPending, isError, error } = useOrder(id, {
11764
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11657
11765
  });
11766
+ const {
11767
+ order: preview,
11768
+ isPending: isPreviewPending,
11769
+ isError: isPreviewError,
11770
+ error: previewError
11771
+ } = useOrderPreview(id);
11772
+ useInitiateOrderEdit({ preview });
11773
+ const { onCancel } = useCancelOrderEdit({ preview });
11658
11774
  if (isError) {
11659
11775
  throw error;
11660
11776
  }
11661
- const isReady = !isPending && !!draft_order;
11662
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11663
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11664
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11665
- /* @__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" }) })
11666
- ] }),
11667
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11668
- ] });
11777
+ if (isPreviewError) {
11778
+ throw previewError;
11779
+ }
11780
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11781
+ const isReady = preview && !isPreviewPending && order && !isPending;
11782
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11783
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11784
+ /* @__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: [
11785
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11786
+ /* @__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." }) })
11787
+ ] }) }) }),
11788
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11789
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11790
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11791
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11792
+ ] }) });
11669
11793
  };
11670
- const TransferOwnershipForm = ({ order }) => {
11671
- var _a, _b;
11672
- const form = useForm({
11673
- defaultValues: {
11674
- customer_id: order.customer_id || ""
11794
+ const ShippingForm = ({ preview, order }) => {
11795
+ var _a;
11796
+ const { setIsOpen } = useStackedModal();
11797
+ const [isSubmitting, setIsSubmitting] = useState(false);
11798
+ const [data, setData] = useState(null);
11799
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11800
+ const { shipping_options } = useShippingOptions(
11801
+ {
11802
+ id: appliedShippingOptionIds,
11803
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11675
11804
  },
11676
- resolver: zodResolver(schema$1)
11677
- });
11678
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11805
+ {
11806
+ enabled: appliedShippingOptionIds.length > 0
11807
+ }
11808
+ );
11809
+ const uniqueShippingProfiles = useMemo(() => {
11810
+ const profiles = /* @__PURE__ */ new Map();
11811
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11812
+ profiles.set(profile.id, profile);
11813
+ });
11814
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11815
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11816
+ });
11817
+ return Array.from(profiles.values());
11818
+ }, [order.items, shipping_options]);
11679
11819
  const { handleSuccess } = useRouteModal();
11680
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11681
- const currentCustomer = order.customer ? {
11682
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11683
- value: order.customer.id
11684
- } : null;
11685
- const onSubmit = form.handleSubmit(async (data) => {
11686
- await mutateAsync(
11687
- { customer_id: data.customer_id },
11688
- {
11689
- onSuccess: () => {
11690
- toast.success("Customer updated");
11691
- handleSuccess();
11692
- },
11693
- onError: (error) => {
11694
- toast.error(error.message);
11695
- }
11696
- }
11697
- );
11698
- });
11699
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11700
- KeyboundForm,
11701
- {
11702
- className: "flex flex-1 flex-col overflow-hidden",
11703
- onSubmit,
11704
- children: [
11705
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11706
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11707
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11708
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11709
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11710
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11711
- ] }),
11712
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11713
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11714
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11715
- ] })
11716
- ] }),
11717
- /* @__PURE__ */ jsx(
11718
- CustomerField,
11719
- {
11720
- control: form.control,
11721
- currentCustomerId: order.customer_id
11722
- }
11723
- )
11724
- ] }),
11725
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11726
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11727
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11728
- ] }) })
11729
- ]
11730
- }
11731
- ) });
11732
- };
11733
- const CustomerField = ({ control, currentCustomerId }) => {
11734
- const customers = useComboboxData({
11735
- queryFn: async (params) => {
11736
- return await sdk.admin.customer.list({
11737
- ...params,
11738
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11739
- });
11740
- },
11741
- queryKey: ["customers"],
11742
- getOptions: (data) => {
11743
- return data.customers.map((customer) => {
11744
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11745
- return {
11746
- label: name ? `${name} (${customer.email})` : customer.email,
11747
- value: customer.id
11748
- };
11749
- });
11750
- }
11751
- });
11752
- return /* @__PURE__ */ jsx(
11753
- Form$2.Field,
11754
- {
11755
- name: "customer_id",
11756
- control,
11757
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11758
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11759
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11760
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11761
- ] }),
11762
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11763
- Combobox,
11764
- {
11765
- options: customers.options,
11766
- fetchNextPage: customers.fetchNextPage,
11767
- isFetchingNextPage: customers.isFetchingNextPage,
11768
- searchValue: customers.searchValue,
11769
- onSearchValueChange: customers.onSearchValueChange,
11770
- placeholder: "Select customer",
11771
- ...field
11772
- }
11773
- ) }),
11774
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11775
- ] })
11776
- }
11777
- );
11778
- };
11779
- const Illustration = () => {
11780
- return /* @__PURE__ */ jsxs(
11781
- "svg",
11782
- {
11783
- width: "280",
11784
- height: "180",
11785
- viewBox: "0 0 280 180",
11786
- fill: "none",
11787
- xmlns: "http://www.w3.org/2000/svg",
11788
- children: [
11789
- /* @__PURE__ */ jsx(
11790
- "rect",
11791
- {
11792
- x: "0.00428286",
11793
- y: "-0.742904",
11794
- width: "33.5",
11795
- height: "65.5",
11796
- rx: "6.75",
11797
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11798
- fill: "#D4D4D8",
11799
- stroke: "#52525B",
11800
- strokeWidth: "1.5"
11801
- }
11802
- ),
11803
- /* @__PURE__ */ jsx(
11804
- "rect",
11805
- {
11806
- x: "0.00428286",
11807
- y: "-0.742904",
11808
- width: "33.5",
11809
- height: "65.5",
11810
- rx: "6.75",
11811
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11812
- fill: "white",
11813
- stroke: "#52525B",
11814
- strokeWidth: "1.5"
11815
- }
11816
- ),
11817
- /* @__PURE__ */ jsx(
11818
- "path",
11819
- {
11820
- d: "M180.579 107.142L179.126 107.959",
11821
- stroke: "#52525B",
11822
- strokeWidth: "1.5",
11823
- strokeLinecap: "round",
11824
- strokeLinejoin: "round"
11825
- }
11826
- ),
11827
- /* @__PURE__ */ jsx(
11828
- "path",
11829
- {
11830
- opacity: "0.88",
11831
- d: "M182.305 109.546L180.257 109.534",
11832
- stroke: "#52525B",
11833
- strokeWidth: "1.5",
11834
- strokeLinecap: "round",
11835
- strokeLinejoin: "round"
11836
- }
11837
- ),
11838
- /* @__PURE__ */ jsx(
11839
- "path",
11840
- {
11841
- opacity: "0.75",
11842
- d: "M180.551 111.93L179.108 111.096",
11843
- stroke: "#52525B",
11844
- strokeWidth: "1.5",
11845
- strokeLinecap: "round",
11846
- strokeLinejoin: "round"
11847
- }
11848
- ),
11849
- /* @__PURE__ */ jsx(
11850
- "path",
11851
- {
11852
- opacity: "0.63",
11853
- d: "M176.347 112.897L176.354 111.73",
11854
- stroke: "#52525B",
11855
- strokeWidth: "1.5",
11856
- strokeLinecap: "round",
11857
- strokeLinejoin: "round"
11858
- }
11859
- ),
11860
- /* @__PURE__ */ jsx(
11861
- "path",
11862
- {
11863
- opacity: "0.5",
11864
- d: "M172.153 111.881L173.606 111.064",
11865
- stroke: "#52525B",
11866
- strokeWidth: "1.5",
11867
- strokeLinecap: "round",
11868
- strokeLinejoin: "round"
11869
- }
11870
- ),
11871
- /* @__PURE__ */ jsx(
11872
- "path",
11873
- {
11874
- opacity: "0.38",
11875
- d: "M170.428 109.478L172.476 109.489",
11876
- stroke: "#52525B",
11877
- strokeWidth: "1.5",
11878
- strokeLinecap: "round",
11879
- strokeLinejoin: "round"
11880
- }
11881
- ),
11882
- /* @__PURE__ */ jsx(
11883
- "path",
11884
- {
11885
- opacity: "0.25",
11886
- d: "M172.181 107.094L173.624 107.928",
11887
- stroke: "#52525B",
11888
- strokeWidth: "1.5",
11889
- strokeLinecap: "round",
11890
- strokeLinejoin: "round"
11891
- }
11892
- ),
11893
- /* @__PURE__ */ jsx(
11894
- "path",
11895
- {
11896
- opacity: "0.13",
11897
- d: "M176.386 106.126L176.379 107.294",
11898
- stroke: "#52525B",
11899
- strokeWidth: "1.5",
11900
- strokeLinecap: "round",
11901
- strokeLinejoin: "round"
11902
- }
11903
- ),
11904
- /* @__PURE__ */ jsx(
11905
- "rect",
11906
- {
11907
- width: "12",
11908
- height: "3",
11909
- rx: "1.5",
11910
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11911
- fill: "#D4D4D8"
11912
- }
11913
- ),
11914
- /* @__PURE__ */ jsx(
11915
- "rect",
11916
- {
11917
- x: "0.00428286",
11918
- y: "-0.742904",
11919
- width: "33.5",
11920
- height: "65.5",
11921
- rx: "6.75",
11922
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11923
- fill: "#D4D4D8",
11924
- stroke: "#52525B",
11925
- strokeWidth: "1.5"
11926
- }
11927
- ),
11928
- /* @__PURE__ */ jsx(
11929
- "rect",
11930
- {
11931
- x: "0.00428286",
11932
- y: "-0.742904",
11933
- width: "33.5",
11934
- height: "65.5",
11935
- rx: "6.75",
11936
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11937
- fill: "white",
11938
- stroke: "#52525B",
11939
- strokeWidth: "1.5"
11940
- }
11941
- ),
11942
- /* @__PURE__ */ jsx(
11943
- "rect",
11944
- {
11945
- width: "12",
11946
- height: "3",
11947
- rx: "1.5",
11948
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11949
- fill: "#D4D4D8"
11950
- }
11951
- ),
11952
- /* @__PURE__ */ jsx(
11953
- "rect",
11954
- {
11955
- width: "17",
11956
- height: "3",
11957
- rx: "1.5",
11958
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11959
- fill: "#D4D4D8"
11960
- }
11961
- ),
11962
- /* @__PURE__ */ jsx(
11963
- "rect",
11964
- {
11965
- width: "12",
11966
- height: "3",
11967
- rx: "1.5",
11968
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11969
- fill: "#D4D4D8"
11970
- }
11971
- ),
11972
- /* @__PURE__ */ jsx(
11973
- "path",
11974
- {
11975
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11976
- fill: "#A1A1AA"
11977
- }
11978
- ),
11979
- /* @__PURE__ */ jsx(
11980
- "rect",
11981
- {
11982
- width: "17",
11983
- height: "3",
11984
- rx: "1.5",
11985
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11986
- fill: "#A1A1AA"
11987
- }
11988
- ),
11989
- /* @__PURE__ */ jsx(
11990
- "rect",
11991
- {
11992
- width: "12",
11993
- height: "3",
11994
- rx: "1.5",
11995
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11996
- fill: "#A1A1AA"
11997
- }
11998
- ),
11999
- /* @__PURE__ */ jsx(
12000
- "path",
12001
- {
12002
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12003
- fill: "#52525B"
12004
- }
12005
- ),
12006
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12007
- "path",
12008
- {
12009
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12010
- stroke: "#A1A1AA",
12011
- strokeWidth: "1.5",
12012
- strokeLinecap: "round",
12013
- strokeLinejoin: "round"
12014
- }
12015
- ) }),
12016
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12017
- "path",
12018
- {
12019
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12020
- stroke: "#A1A1AA",
12021
- strokeWidth: "1.5",
12022
- strokeLinecap: "round",
12023
- strokeLinejoin: "round"
12024
- }
12025
- ) }),
12026
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12027
- "path",
12028
- {
12029
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12030
- stroke: "#A1A1AA",
12031
- strokeWidth: "1.5",
12032
- strokeLinecap: "round",
12033
- strokeLinejoin: "round"
12034
- }
12035
- ) }),
12036
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12037
- "path",
12038
- {
12039
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12040
- stroke: "#A1A1AA",
12041
- strokeWidth: "1.5",
12042
- strokeLinecap: "round",
12043
- strokeLinejoin: "round"
12044
- }
12045
- ) }),
12046
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12047
- "path",
12048
- {
12049
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12050
- stroke: "#A1A1AA",
12051
- strokeWidth: "1.5",
12052
- strokeLinecap: "round",
12053
- strokeLinejoin: "round"
12054
- }
12055
- ) }),
12056
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12057
- "path",
12058
- {
12059
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12060
- stroke: "#A1A1AA",
12061
- strokeWidth: "1.5",
12062
- strokeLinecap: "round",
12063
- strokeLinejoin: "round"
12064
- }
12065
- ) }),
12066
- /* @__PURE__ */ jsxs("defs", { children: [
12067
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12068
- "rect",
12069
- {
12070
- width: "12",
12071
- height: "12",
12072
- fill: "white",
12073
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12074
- }
12075
- ) }),
12076
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12077
- "rect",
12078
- {
12079
- width: "12",
12080
- height: "12",
12081
- fill: "white",
12082
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12083
- }
12084
- ) }),
12085
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12086
- "rect",
12087
- {
12088
- width: "12",
12089
- height: "12",
12090
- fill: "white",
12091
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12092
- }
12093
- ) }),
12094
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12095
- "rect",
12096
- {
12097
- width: "12",
12098
- height: "12",
12099
- fill: "white",
12100
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12101
- }
12102
- ) }),
12103
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12104
- "rect",
12105
- {
12106
- width: "12",
12107
- height: "12",
12108
- fill: "white",
12109
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12110
- }
12111
- ) }),
12112
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12113
- "rect",
12114
- {
12115
- width: "12",
12116
- height: "12",
12117
- fill: "white",
12118
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12119
- }
12120
- ) })
12121
- ] })
12122
- ]
12123
- }
12124
- );
12125
- };
12126
- const schema$1 = objectType({
12127
- customer_id: stringType().min(1)
12128
- });
12129
- const SalesChannel = () => {
12130
- const { id } = useParams();
12131
- const { draft_order, isPending, isError, error } = useDraftOrder(
12132
- id,
12133
- {
12134
- fields: "+sales_channel_id"
12135
- },
12136
- {
12137
- enabled: !!id
12138
- }
12139
- );
12140
- if (isError) {
12141
- throw error;
12142
- }
12143
- const ISrEADY = !!draft_order && !isPending;
12144
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12145
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12146
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12147
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12148
- ] }),
12149
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12150
- ] });
12151
- };
12152
- const SalesChannelForm = ({ order }) => {
12153
- const form = useForm({
12154
- defaultValues: {
12155
- sales_channel_id: order.sales_channel_id || ""
12156
- },
12157
- resolver: zodResolver(schema)
12158
- });
12159
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12160
- const { handleSuccess } = useRouteModal();
12161
- const onSubmit = form.handleSubmit(async (data) => {
12162
- await mutateAsync(
12163
- {
12164
- sales_channel_id: data.sales_channel_id
12165
- },
12166
- {
12167
- onSuccess: () => {
12168
- toast.success("Sales channel updated");
12169
- handleSuccess();
12170
- },
12171
- onError: (error) => {
12172
- toast.error(error.message);
12173
- }
12174
- }
12175
- );
12176
- });
12177
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12178
- KeyboundForm,
12179
- {
12180
- className: "flex flex-1 flex-col overflow-hidden",
12181
- onSubmit,
12182
- children: [
12183
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12184
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12185
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12186
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12187
- ] }) })
12188
- ]
12189
- }
12190
- ) });
12191
- };
12192
- const SalesChannelField = ({ control, order }) => {
12193
- const salesChannels = useComboboxData({
12194
- queryFn: async (params) => {
12195
- return await sdk.admin.salesChannel.list(params);
12196
- },
12197
- queryKey: ["sales-channels"],
12198
- getOptions: (data) => {
12199
- return data.sales_channels.map((salesChannel) => ({
12200
- label: salesChannel.name,
12201
- value: salesChannel.id
12202
- }));
12203
- },
12204
- defaultValue: order.sales_channel_id || void 0
12205
- });
12206
- return /* @__PURE__ */ jsx(
12207
- Form$2.Field,
12208
- {
12209
- control,
12210
- name: "sales_channel_id",
12211
- render: ({ field }) => {
12212
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12213
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12214
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12215
- Combobox,
12216
- {
12217
- options: salesChannels.options,
12218
- fetchNextPage: salesChannels.fetchNextPage,
12219
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12220
- searchValue: salesChannels.searchValue,
12221
- onSearchValueChange: salesChannels.onSearchValueChange,
12222
- placeholder: "Select sales channel",
12223
- ...field
12224
- }
12225
- ) }),
12226
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12227
- ] });
12228
- }
12229
- }
12230
- );
12231
- };
12232
- const schema = objectType({
12233
- sales_channel_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;
11820
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11821
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11822
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11823
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11824
+ const onSubmit = async () => {
11825
+ setIsSubmitting(true);
11826
+ let requestSucceeded = false;
11827
+ await requestOrderEdit(void 0, {
11828
+ onError: (e) => {
11829
+ toast.error(`Failed to request order edit: ${e.message}`);
11830
+ },
11831
+ onSuccess: () => {
11832
+ requestSucceeded = true;
12309
11833
  }
12310
11834
  });
12311
11835
  if (!requestSucceeded) {
@@ -12909,136 +12433,612 @@ const LocationField = ({ control, setValue }) => {
12909
12433
  Form$2.Field,
12910
12434
  {
12911
12435
  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,
12436
+ name: "location_id",
12437
+ render: ({ field: { onChange, ...field } }) => {
12438
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12439
+ /* @__PURE__ */ jsxs("div", { children: [
12440
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12441
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12442
+ ] }),
12443
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12444
+ Combobox,
12445
+ {
12446
+ options: locations.options,
12447
+ fetchNextPage: locations.fetchNextPage,
12448
+ isFetchingNextPage: locations.isFetchingNextPage,
12449
+ searchValue: locations.searchValue,
12450
+ onSearchValueChange: locations.onSearchValueChange,
12451
+ placeholder: "Select location",
12452
+ onChange: (value) => {
12453
+ setValue("shipping_option_id", "", {
12454
+ shouldDirty: true,
12455
+ shouldTouch: true
12456
+ });
12457
+ onChange(value);
12458
+ },
12459
+ ...field
12460
+ }
12461
+ ) })
12462
+ ] }) });
12463
+ }
12464
+ }
12465
+ );
12466
+ };
12467
+ const ShippingOptionField = ({
12468
+ shippingProfileId,
12469
+ preview,
12470
+ control
12471
+ }) => {
12472
+ var _a;
12473
+ const locationId = useWatch({ control, name: "location_id" });
12474
+ const shippingOptions = useComboboxData({
12475
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12476
+ queryFn: async (params) => {
12477
+ return await sdk.admin.shippingOption.list({
12478
+ ...params,
12479
+ stock_location_id: locationId,
12480
+ shipping_profile_id: shippingProfileId
12481
+ });
12482
+ },
12483
+ getOptions: (data) => {
12484
+ return data.shipping_options.map((option) => {
12485
+ var _a2;
12486
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12487
+ (r) => r.attribute === "is_return" && r.value === "true"
12488
+ )) {
12489
+ return void 0;
12490
+ }
12491
+ return {
12492
+ label: option.name,
12493
+ value: option.id
12494
+ };
12495
+ }).filter(Boolean);
12496
+ },
12497
+ enabled: !!locationId && !!shippingProfileId,
12498
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12499
+ });
12500
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12501
+ return /* @__PURE__ */ jsx(
12502
+ Form$2.Field,
12503
+ {
12504
+ control,
12505
+ name: "shipping_option_id",
12506
+ render: ({ field }) => {
12507
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12508
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12509
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12510
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12511
+ ] }),
12512
+ /* @__PURE__ */ jsx(
12513
+ ConditionalTooltip,
12514
+ {
12515
+ content: tooltipContent,
12516
+ showTooltip: !locationId || !shippingProfileId,
12517
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12518
+ Combobox,
12519
+ {
12520
+ options: shippingOptions.options,
12521
+ fetchNextPage: shippingOptions.fetchNextPage,
12522
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12523
+ searchValue: shippingOptions.searchValue,
12524
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12525
+ placeholder: "Select shipping option",
12526
+ ...field,
12527
+ disabled: !locationId || !shippingProfileId
12528
+ }
12529
+ ) }) })
12530
+ }
12531
+ )
12532
+ ] }) });
12533
+ }
12534
+ }
12535
+ );
12536
+ };
12537
+ const CustomAmountField = ({
12538
+ control,
12539
+ currencyCode
12540
+ }) => {
12541
+ return /* @__PURE__ */ jsx(
12542
+ Form$2.Field,
12543
+ {
12544
+ control,
12545
+ name: "custom_amount",
12546
+ render: ({ field: { onChange, ...field } }) => {
12547
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12548
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12549
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12550
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12551
+ ] }),
12552
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12553
+ CurrencyInput,
12554
+ {
12555
+ ...field,
12556
+ onValueChange: (value) => onChange(value),
12557
+ symbol: getNativeSymbol(currencyCode),
12558
+ code: currencyCode
12559
+ }
12560
+ ) })
12561
+ ] });
12562
+ }
12563
+ }
12564
+ );
12565
+ };
12566
+ const TransferOwnership = () => {
12567
+ const { id } = useParams();
12568
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12569
+ fields: "id,customer_id,customer.*"
12570
+ });
12571
+ if (isError) {
12572
+ throw error;
12573
+ }
12574
+ const isReady = !isPending && !!draft_order;
12575
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12576
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12577
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12578
+ /* @__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" }) })
12579
+ ] }),
12580
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12581
+ ] });
12582
+ };
12583
+ const TransferOwnershipForm = ({ order }) => {
12584
+ var _a, _b;
12585
+ const form = useForm({
12586
+ defaultValues: {
12587
+ customer_id: order.customer_id || ""
12588
+ },
12589
+ resolver: zodResolver(schema)
12590
+ });
12591
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
+ const { handleSuccess } = useRouteModal();
12593
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12594
+ const currentCustomer = order.customer ? {
12595
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12596
+ value: order.customer.id
12597
+ } : null;
12598
+ const onSubmit = form.handleSubmit(async (data) => {
12599
+ await mutateAsync(
12600
+ { customer_id: data.customer_id },
12601
+ {
12602
+ onSuccess: () => {
12603
+ toast.success("Customer updated");
12604
+ handleSuccess();
12605
+ },
12606
+ onError: (error) => {
12607
+ toast.error(error.message);
12608
+ }
12609
+ }
12610
+ );
12611
+ });
12612
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12613
+ KeyboundForm,
12614
+ {
12615
+ className: "flex flex-1 flex-col overflow-hidden",
12616
+ onSubmit,
12617
+ children: [
12618
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12619
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12620
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12621
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12622
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12623
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12624
+ ] }),
12625
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12626
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12627
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12628
+ ] })
12629
+ ] }),
12630
+ /* @__PURE__ */ jsx(
12631
+ CustomerField,
12632
+ {
12633
+ control: form.control,
12634
+ currentCustomerId: order.customer_id
12635
+ }
12636
+ )
12637
+ ] }),
12638
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12639
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12640
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12641
+ ] }) })
12642
+ ]
12643
+ }
12644
+ ) });
12645
+ };
12646
+ const CustomerField = ({ control, currentCustomerId }) => {
12647
+ const customers = useComboboxData({
12648
+ queryFn: async (params) => {
12649
+ return await sdk.admin.customer.list({
12650
+ ...params,
12651
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12652
+ });
12653
+ },
12654
+ queryKey: ["customers"],
12655
+ getOptions: (data) => {
12656
+ return data.customers.map((customer) => {
12657
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12658
+ return {
12659
+ label: name ? `${name} (${customer.email})` : customer.email,
12660
+ value: customer.id
12661
+ };
12662
+ });
12663
+ }
12664
+ });
12665
+ return /* @__PURE__ */ jsx(
12666
+ Form$2.Field,
12667
+ {
12668
+ name: "customer_id",
12669
+ control,
12670
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12671
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12672
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12673
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12674
+ ] }),
12675
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12676
+ Combobox,
12677
+ {
12678
+ options: customers.options,
12679
+ fetchNextPage: customers.fetchNextPage,
12680
+ isFetchingNextPage: customers.isFetchingNextPage,
12681
+ searchValue: customers.searchValue,
12682
+ onSearchValueChange: customers.onSearchValueChange,
12683
+ placeholder: "Select customer",
12684
+ ...field
12685
+ }
12686
+ ) }),
12687
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12688
+ ] })
12689
+ }
12690
+ );
12691
+ };
12692
+ const Illustration = () => {
12693
+ return /* @__PURE__ */ jsxs(
12694
+ "svg",
12695
+ {
12696
+ width: "280",
12697
+ height: "180",
12698
+ viewBox: "0 0 280 180",
12699
+ fill: "none",
12700
+ xmlns: "http://www.w3.org/2000/svg",
12701
+ children: [
12702
+ /* @__PURE__ */ jsx(
12703
+ "rect",
12704
+ {
12705
+ x: "0.00428286",
12706
+ y: "-0.742904",
12707
+ width: "33.5",
12708
+ height: "65.5",
12709
+ rx: "6.75",
12710
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12711
+ fill: "#D4D4D8",
12712
+ stroke: "#52525B",
12713
+ strokeWidth: "1.5"
12714
+ }
12715
+ ),
12716
+ /* @__PURE__ */ jsx(
12717
+ "rect",
12718
+ {
12719
+ x: "0.00428286",
12720
+ y: "-0.742904",
12721
+ width: "33.5",
12722
+ height: "65.5",
12723
+ rx: "6.75",
12724
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12725
+ fill: "white",
12726
+ stroke: "#52525B",
12727
+ strokeWidth: "1.5"
12728
+ }
12729
+ ),
12730
+ /* @__PURE__ */ jsx(
12731
+ "path",
12732
+ {
12733
+ d: "M180.579 107.142L179.126 107.959",
12734
+ stroke: "#52525B",
12735
+ strokeWidth: "1.5",
12736
+ strokeLinecap: "round",
12737
+ strokeLinejoin: "round"
12738
+ }
12739
+ ),
12740
+ /* @__PURE__ */ jsx(
12741
+ "path",
12742
+ {
12743
+ opacity: "0.88",
12744
+ d: "M182.305 109.546L180.257 109.534",
12745
+ stroke: "#52525B",
12746
+ strokeWidth: "1.5",
12747
+ strokeLinecap: "round",
12748
+ strokeLinejoin: "round"
12749
+ }
12750
+ ),
12751
+ /* @__PURE__ */ jsx(
12752
+ "path",
12753
+ {
12754
+ opacity: "0.75",
12755
+ d: "M180.551 111.93L179.108 111.096",
12756
+ stroke: "#52525B",
12757
+ strokeWidth: "1.5",
12758
+ strokeLinecap: "round",
12759
+ strokeLinejoin: "round"
12760
+ }
12761
+ ),
12762
+ /* @__PURE__ */ jsx(
12763
+ "path",
12764
+ {
12765
+ opacity: "0.63",
12766
+ d: "M176.347 112.897L176.354 111.73",
12767
+ stroke: "#52525B",
12768
+ strokeWidth: "1.5",
12769
+ strokeLinecap: "round",
12770
+ strokeLinejoin: "round"
12771
+ }
12772
+ ),
12773
+ /* @__PURE__ */ jsx(
12774
+ "path",
12775
+ {
12776
+ opacity: "0.5",
12777
+ d: "M172.153 111.881L173.606 111.064",
12778
+ stroke: "#52525B",
12779
+ strokeWidth: "1.5",
12780
+ strokeLinecap: "round",
12781
+ strokeLinejoin: "round"
12782
+ }
12783
+ ),
12784
+ /* @__PURE__ */ jsx(
12785
+ "path",
12786
+ {
12787
+ opacity: "0.38",
12788
+ d: "M170.428 109.478L172.476 109.489",
12789
+ stroke: "#52525B",
12790
+ strokeWidth: "1.5",
12791
+ strokeLinecap: "round",
12792
+ strokeLinejoin: "round"
12793
+ }
12794
+ ),
12795
+ /* @__PURE__ */ jsx(
12796
+ "path",
12797
+ {
12798
+ opacity: "0.25",
12799
+ d: "M172.181 107.094L173.624 107.928",
12800
+ stroke: "#52525B",
12801
+ strokeWidth: "1.5",
12802
+ strokeLinecap: "round",
12803
+ strokeLinejoin: "round"
12804
+ }
12805
+ ),
12806
+ /* @__PURE__ */ jsx(
12807
+ "path",
12808
+ {
12809
+ opacity: "0.13",
12810
+ d: "M176.386 106.126L176.379 107.294",
12811
+ stroke: "#52525B",
12812
+ strokeWidth: "1.5",
12813
+ strokeLinecap: "round",
12814
+ strokeLinejoin: "round"
12815
+ }
12816
+ ),
12817
+ /* @__PURE__ */ jsx(
12818
+ "rect",
12819
+ {
12820
+ width: "12",
12821
+ height: "3",
12822
+ rx: "1.5",
12823
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12824
+ fill: "#D4D4D8"
12825
+ }
12826
+ ),
12827
+ /* @__PURE__ */ jsx(
12828
+ "rect",
12829
+ {
12830
+ x: "0.00428286",
12831
+ y: "-0.742904",
12832
+ width: "33.5",
12833
+ height: "65.5",
12834
+ rx: "6.75",
12835
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12836
+ fill: "#D4D4D8",
12837
+ stroke: "#52525B",
12838
+ strokeWidth: "1.5"
12839
+ }
12840
+ ),
12841
+ /* @__PURE__ */ jsx(
12842
+ "rect",
12843
+ {
12844
+ x: "0.00428286",
12845
+ y: "-0.742904",
12846
+ width: "33.5",
12847
+ height: "65.5",
12848
+ rx: "6.75",
12849
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12850
+ fill: "white",
12851
+ stroke: "#52525B",
12852
+ strokeWidth: "1.5"
12853
+ }
12854
+ ),
12855
+ /* @__PURE__ */ jsx(
12856
+ "rect",
12857
+ {
12858
+ width: "12",
12859
+ height: "3",
12860
+ rx: "1.5",
12861
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12862
+ fill: "#D4D4D8"
12863
+ }
12864
+ ),
12865
+ /* @__PURE__ */ jsx(
12866
+ "rect",
12867
+ {
12868
+ width: "17",
12869
+ height: "3",
12870
+ rx: "1.5",
12871
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12872
+ fill: "#D4D4D8"
12873
+ }
12874
+ ),
12875
+ /* @__PURE__ */ jsx(
12876
+ "rect",
12877
+ {
12878
+ width: "12",
12879
+ height: "3",
12880
+ rx: "1.5",
12881
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12882
+ fill: "#D4D4D8"
12883
+ }
12884
+ ),
12885
+ /* @__PURE__ */ jsx(
12886
+ "path",
12887
+ {
12888
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12889
+ fill: "#A1A1AA"
12890
+ }
12891
+ ),
12892
+ /* @__PURE__ */ jsx(
12893
+ "rect",
12894
+ {
12895
+ width: "17",
12896
+ height: "3",
12897
+ rx: "1.5",
12898
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12899
+ fill: "#A1A1AA"
12900
+ }
12901
+ ),
12902
+ /* @__PURE__ */ jsx(
12903
+ "rect",
12904
+ {
12905
+ width: "12",
12906
+ height: "3",
12907
+ rx: "1.5",
12908
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12909
+ fill: "#A1A1AA"
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ "path",
12914
+ {
12915
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12916
+ fill: "#52525B"
12917
+ }
12918
+ ),
12919
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12920
+ "path",
12921
+ {
12922
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12923
+ stroke: "#A1A1AA",
12924
+ strokeWidth: "1.5",
12925
+ strokeLinecap: "round",
12926
+ strokeLinejoin: "round"
12927
+ }
12928
+ ) }),
12929
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12930
+ "path",
12931
+ {
12932
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12933
+ stroke: "#A1A1AA",
12934
+ strokeWidth: "1.5",
12935
+ strokeLinecap: "round",
12936
+ strokeLinejoin: "round"
12937
+ }
12938
+ ) }),
12939
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12940
+ "path",
12941
+ {
12942
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12943
+ stroke: "#A1A1AA",
12944
+ strokeWidth: "1.5",
12945
+ strokeLinecap: "round",
12946
+ strokeLinejoin: "round"
12947
+ }
12948
+ ) }),
12949
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12950
+ "path",
12951
+ {
12952
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12953
+ stroke: "#A1A1AA",
12954
+ strokeWidth: "1.5",
12955
+ strokeLinecap: "round",
12956
+ strokeLinejoin: "round"
12957
+ }
12958
+ ) }),
12959
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
+ "path",
12961
+ {
12962
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
+ stroke: "#A1A1AA",
12964
+ strokeWidth: "1.5",
12965
+ strokeLinecap: "round",
12966
+ strokeLinejoin: "round"
12967
+ }
12968
+ ) }),
12969
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
+ "path",
12971
+ {
12972
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
+ stroke: "#A1A1AA",
12974
+ strokeWidth: "1.5",
12975
+ strokeLinecap: "round",
12976
+ strokeLinejoin: "round"
12977
+ }
12978
+ ) }),
12979
+ /* @__PURE__ */ jsxs("defs", { children: [
12980
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
+ "rect",
12921
12982
  {
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
12983
+ width: "12",
12984
+ height: "12",
12985
+ fill: "white",
12986
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12936
12987
  }
12937
- ) })
12938
- ] }) });
12939
- }
12940
- }
12941
- );
12942
- };
12943
- const ShippingOptionField = ({
12944
- shippingProfileId,
12945
- preview,
12946
- control
12947
- }) => {
12948
- var _a;
12949
- const locationId = useWatch({ control, name: "location_id" });
12950
- const shippingOptions = useComboboxData({
12951
- queryKey: ["shipping_options", locationId, shippingProfileId],
12952
- queryFn: async (params) => {
12953
- return await sdk.admin.shippingOption.list({
12954
- ...params,
12955
- stock_location_id: locationId,
12956
- shipping_profile_id: shippingProfileId
12957
- });
12958
- },
12959
- getOptions: (data) => {
12960
- return data.shipping_options.map((option) => {
12961
- var _a2;
12962
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12963
- (r) => r.attribute === "is_return" && r.value === "true"
12964
- )) {
12965
- return void 0;
12966
- }
12967
- return {
12968
- label: option.name,
12969
- value: option.id
12970
- };
12971
- }).filter(Boolean);
12972
- },
12973
- enabled: !!locationId && !!shippingProfileId,
12974
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12975
- });
12976
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12977
- return /* @__PURE__ */ jsx(
12978
- Form$2.Field,
12979
- {
12980
- control,
12981
- name: "shipping_option_id",
12982
- render: ({ field }) => {
12983
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12984
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12985
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12986
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12987
- ] }),
12988
- /* @__PURE__ */ jsx(
12989
- ConditionalTooltip,
12988
+ ) }),
12989
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
+ "rect",
12990
12991
  {
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
- ) }) })
12992
+ width: "12",
12993
+ height: "12",
12994
+ fill: "white",
12995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13006
12996
  }
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
- ] }),
13028
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13029
- CurrencyInput,
12997
+ ) }),
12998
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
+ "rect",
13030
13000
  {
13031
- ...field,
13032
- onValueChange: (value) => onChange(value),
13033
- symbol: getNativeSymbol(currencyCode),
13034
- code: currencyCode
13001
+ width: "12",
13002
+ height: "12",
13003
+ fill: "white",
13004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13005
+ }
13006
+ ) }),
13007
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
+ "rect",
13009
+ {
13010
+ width: "12",
13011
+ height: "12",
13012
+ fill: "white",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13014
+ }
13015
+ ) }),
13016
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
+ "rect",
13018
+ {
13019
+ width: "12",
13020
+ height: "12",
13021
+ fill: "white",
13022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13023
+ }
13024
+ ) }),
13025
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
+ "rect",
13027
+ {
13028
+ width: "12",
13029
+ height: "12",
13030
+ fill: "white",
13031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13035
13032
  }
13036
13033
  ) })
13037
- ] });
13038
- }
13034
+ ] })
13035
+ ]
13039
13036
  }
13040
13037
  );
13041
13038
  };
13039
+ const schema = objectType({
13040
+ customer_id: stringType().min(1)
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13063,14 +13063,14 @@ const routeModule = {
13063
13063
  Component: BillingAddress,
13064
13064
  path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
- {
13067
- Component: Email,
13068
- path: "/draft-orders/:id/email"
13069
- },
13070
13066
  {
13071
13067
  Component: CustomItems,
13072
13068
  path: "/draft-orders/:id/custom-items"
13073
13069
  },
13070
+ {
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13073
+ },
13074
13074
  {
13075
13075
  Component: Items,
13076
13076
  path: "/draft-orders/:id/items"
@@ -13083,21 +13083,21 @@ const routeModule = {
13083
13083
  Component: Promotions,
13084
13084
  path: "/draft-orders/:id/promotions"
13085
13085
  },
13086
- {
13087
- Component: ShippingAddress,
13088
- path: "/draft-orders/:id/shipping-address"
13089
- },
13090
- {
13091
- Component: TransferOwnership,
13092
- path: "/draft-orders/:id/transfer-ownership"
13093
- },
13094
13086
  {
13095
13087
  Component: SalesChannel,
13096
13088
  path: "/draft-orders/:id/sales-channel"
13097
13089
  },
13090
+ {
13091
+ Component: ShippingAddress,
13092
+ path: "/draft-orders/:id/shipping-address"
13093
+ },
13098
13094
  {
13099
13095
  Component: Shipping,
13100
13096
  path: "/draft-orders/:id/shipping"
13097
+ },
13098
+ {
13099
+ Component: TransferOwnership,
13100
+ path: "/draft-orders/:id/transfer-ownership"
13101
13101
  }
13102
13102
  ]
13103
13103
  }