@medusajs/draft-order 2.11.0-preview-20251018150154 → 2.11.0-preview-20251018180153

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.
@@ -9784,74 +9784,6 @@ const CustomItemsForm = () => {
9784
9784
  const schema$4 = objectType({
9785
9785
  email: stringType().email()
9786
9786
  });
9787
- const Email = () => {
9788
- const { id } = reactRouterDom.useParams();
9789
- const { order, isPending, isError, error } = useOrder(id, {
9790
- fields: "+email"
9791
- });
9792
- if (isError) {
9793
- throw error;
9794
- }
9795
- const isReady = !isPending && !!order;
9796
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9797
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9799
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9800
- ] }),
9801
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9802
- ] });
9803
- };
9804
- const EmailForm = ({ order }) => {
9805
- const form = reactHookForm.useForm({
9806
- defaultValues: {
9807
- email: order.email ?? ""
9808
- },
9809
- resolver: zod.zodResolver(schema$3)
9810
- });
9811
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
- const { handleSuccess } = useRouteModal();
9813
- const onSubmit = form.handleSubmit(async (data) => {
9814
- await mutateAsync(
9815
- { email: data.email },
9816
- {
9817
- onSuccess: () => {
9818
- handleSuccess();
9819
- },
9820
- onError: (error) => {
9821
- ui.toast.error(error.message);
9822
- }
9823
- }
9824
- );
9825
- });
9826
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9827
- KeyboundForm,
9828
- {
9829
- className: "flex flex-1 flex-col overflow-hidden",
9830
- onSubmit,
9831
- children: [
9832
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9833
- Form$2.Field,
9834
- {
9835
- control: form.control,
9836
- name: "email",
9837
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9840
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9841
- ] })
9842
- }
9843
- ) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
- ] }) })
9848
- ]
9849
- }
9850
- ) });
9851
- };
9852
- const schema$3 = objectType({
9853
- email: stringType().email()
9854
- });
9855
9787
  const NumberInput = React.forwardRef(
9856
9788
  ({
9857
9789
  value,
@@ -11481,7 +11413,7 @@ const SalesChannelForm = ({ order }) => {
11481
11413
  defaultValues: {
11482
11414
  sales_channel_id: order.sales_channel_id || ""
11483
11415
  },
11484
- resolver: zod.zodResolver(schema$2)
11416
+ resolver: zod.zodResolver(schema$3)
11485
11417
  });
11486
11418
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11487
11419
  const { handleSuccess } = useRouteModal();
@@ -11556,7 +11488,7 @@ const SalesChannelField = ({ control, order }) => {
11556
11488
  }
11557
11489
  );
11558
11490
  };
11559
- const schema$2 = objectType({
11491
+ const schema$3 = objectType({
11560
11492
  sales_channel_id: stringType().min(1)
11561
11493
  });
11562
11494
  const ShippingAddress = () => {
@@ -11591,7 +11523,7 @@ const ShippingAddressForm = ({ order }) => {
11591
11523
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11592
11524
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11593
11525
  },
11594
- resolver: zod.zodResolver(schema$1)
11526
+ resolver: zod.zodResolver(schema$2)
11595
11527
  });
11596
11528
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11597
11529
  const { handleSuccess } = useRouteModal();
@@ -11761,531 +11693,55 @@ const ShippingAddressForm = ({ order }) => {
11761
11693
  }
11762
11694
  ) });
11763
11695
  };
11764
- const schema$1 = addressSchema;
11765
- const TransferOwnership = () => {
11696
+ const schema$2 = addressSchema;
11697
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11698
+ const Shipping = () => {
11699
+ var _a;
11766
11700
  const { id } = reactRouterDom.useParams();
11767
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11768
- fields: "id,customer_id,customer.*"
11701
+ const { order, isPending, isError, error } = useOrder(id, {
11702
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11769
11703
  });
11704
+ const {
11705
+ order: preview,
11706
+ isPending: isPreviewPending,
11707
+ isError: isPreviewError,
11708
+ error: previewError
11709
+ } = useOrderPreview(id);
11710
+ useInitiateOrderEdit({ preview });
11711
+ const { onCancel } = useCancelOrderEdit({ preview });
11770
11712
  if (isError) {
11771
11713
  throw error;
11772
11714
  }
11773
- const isReady = !isPending && !!draft_order;
11774
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11775
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11776
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11778
- ] }),
11779
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11780
- ] });
11715
+ if (isPreviewError) {
11716
+ throw previewError;
11717
+ }
11718
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11719
+ const isReady = preview && !isPreviewPending && order && !isPending;
11720
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11721
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11722
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11723
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11724
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11725
+ ] }) }) }),
11726
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11727
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11728
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11729
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11730
+ ] }) });
11781
11731
  };
11782
- const TransferOwnershipForm = ({ order }) => {
11783
- var _a, _b;
11784
- const form = reactHookForm.useForm({
11785
- defaultValues: {
11786
- customer_id: order.customer_id || ""
11787
- },
11788
- resolver: zod.zodResolver(schema)
11789
- });
11790
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11791
- const { handleSuccess } = useRouteModal();
11792
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11793
- const currentCustomer = order.customer ? {
11794
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11795
- value: order.customer.id
11796
- } : null;
11797
- const onSubmit = form.handleSubmit(async (data) => {
11798
- await mutateAsync(
11799
- { customer_id: data.customer_id },
11800
- {
11801
- onSuccess: () => {
11802
- ui.toast.success("Customer updated");
11803
- handleSuccess();
11804
- },
11805
- onError: (error) => {
11806
- ui.toast.error(error.message);
11807
- }
11808
- }
11809
- );
11810
- });
11811
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11812
- KeyboundForm,
11732
+ const ShippingForm = ({ preview, order }) => {
11733
+ var _a;
11734
+ const { setIsOpen } = useStackedModal();
11735
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11736
+ const [data, setData] = React.useState(null);
11737
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11738
+ const { shipping_options } = useShippingOptions(
11813
11739
  {
11814
- className: "flex flex-1 flex-col overflow-hidden",
11815
- onSubmit,
11816
- children: [
11817
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11818
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11819
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11820
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11821
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11822
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11823
- ] }),
11824
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11825
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11826
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11827
- ] })
11828
- ] }),
11829
- /* @__PURE__ */ jsxRuntime.jsx(
11830
- CustomerField,
11831
- {
11832
- control: form.control,
11833
- currentCustomerId: order.customer_id
11834
- }
11835
- )
11836
- ] }),
11837
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11838
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11839
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11840
- ] }) })
11841
- ]
11842
- }
11843
- ) });
11844
- };
11845
- const CustomerField = ({ control, currentCustomerId }) => {
11846
- const customers = useComboboxData({
11847
- queryFn: async (params) => {
11848
- return await sdk.admin.customer.list({
11849
- ...params,
11850
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11851
- });
11740
+ id: appliedShippingOptionIds,
11741
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11852
11742
  },
11853
- queryKey: ["customers"],
11854
- getOptions: (data) => {
11855
- return data.customers.map((customer) => {
11856
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11857
- return {
11858
- label: name ? `${name} (${customer.email})` : customer.email,
11859
- value: customer.id
11860
- };
11861
- });
11862
- }
11863
- });
11864
- return /* @__PURE__ */ jsxRuntime.jsx(
11865
- Form$2.Field,
11866
11743
  {
11867
- name: "customer_id",
11868
- control,
11869
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11870
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11871
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11872
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11873
- ] }),
11874
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11875
- Combobox,
11876
- {
11877
- options: customers.options,
11878
- fetchNextPage: customers.fetchNextPage,
11879
- isFetchingNextPage: customers.isFetchingNextPage,
11880
- searchValue: customers.searchValue,
11881
- onSearchValueChange: customers.onSearchValueChange,
11882
- placeholder: "Select customer",
11883
- ...field
11884
- }
11885
- ) }),
11886
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11887
- ] })
11888
- }
11889
- );
11890
- };
11891
- const Illustration = () => {
11892
- return /* @__PURE__ */ jsxRuntime.jsxs(
11893
- "svg",
11894
- {
11895
- width: "280",
11896
- height: "180",
11897
- viewBox: "0 0 280 180",
11898
- fill: "none",
11899
- xmlns: "http://www.w3.org/2000/svg",
11900
- children: [
11901
- /* @__PURE__ */ jsxRuntime.jsx(
11902
- "rect",
11903
- {
11904
- x: "0.00428286",
11905
- y: "-0.742904",
11906
- width: "33.5",
11907
- height: "65.5",
11908
- rx: "6.75",
11909
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11910
- fill: "#D4D4D8",
11911
- stroke: "#52525B",
11912
- strokeWidth: "1.5"
11913
- }
11914
- ),
11915
- /* @__PURE__ */ jsxRuntime.jsx(
11916
- "rect",
11917
- {
11918
- x: "0.00428286",
11919
- y: "-0.742904",
11920
- width: "33.5",
11921
- height: "65.5",
11922
- rx: "6.75",
11923
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11924
- fill: "white",
11925
- stroke: "#52525B",
11926
- strokeWidth: "1.5"
11927
- }
11928
- ),
11929
- /* @__PURE__ */ jsxRuntime.jsx(
11930
- "path",
11931
- {
11932
- d: "M180.579 107.142L179.126 107.959",
11933
- stroke: "#52525B",
11934
- strokeWidth: "1.5",
11935
- strokeLinecap: "round",
11936
- strokeLinejoin: "round"
11937
- }
11938
- ),
11939
- /* @__PURE__ */ jsxRuntime.jsx(
11940
- "path",
11941
- {
11942
- opacity: "0.88",
11943
- d: "M182.305 109.546L180.257 109.534",
11944
- stroke: "#52525B",
11945
- strokeWidth: "1.5",
11946
- strokeLinecap: "round",
11947
- strokeLinejoin: "round"
11948
- }
11949
- ),
11950
- /* @__PURE__ */ jsxRuntime.jsx(
11951
- "path",
11952
- {
11953
- opacity: "0.75",
11954
- d: "M180.551 111.93L179.108 111.096",
11955
- stroke: "#52525B",
11956
- strokeWidth: "1.5",
11957
- strokeLinecap: "round",
11958
- strokeLinejoin: "round"
11959
- }
11960
- ),
11961
- /* @__PURE__ */ jsxRuntime.jsx(
11962
- "path",
11963
- {
11964
- opacity: "0.63",
11965
- d: "M176.347 112.897L176.354 111.73",
11966
- stroke: "#52525B",
11967
- strokeWidth: "1.5",
11968
- strokeLinecap: "round",
11969
- strokeLinejoin: "round"
11970
- }
11971
- ),
11972
- /* @__PURE__ */ jsxRuntime.jsx(
11973
- "path",
11974
- {
11975
- opacity: "0.5",
11976
- d: "M172.153 111.881L173.606 111.064",
11977
- stroke: "#52525B",
11978
- strokeWidth: "1.5",
11979
- strokeLinecap: "round",
11980
- strokeLinejoin: "round"
11981
- }
11982
- ),
11983
- /* @__PURE__ */ jsxRuntime.jsx(
11984
- "path",
11985
- {
11986
- opacity: "0.38",
11987
- d: "M170.428 109.478L172.476 109.489",
11988
- stroke: "#52525B",
11989
- strokeWidth: "1.5",
11990
- strokeLinecap: "round",
11991
- strokeLinejoin: "round"
11992
- }
11993
- ),
11994
- /* @__PURE__ */ jsxRuntime.jsx(
11995
- "path",
11996
- {
11997
- opacity: "0.25",
11998
- d: "M172.181 107.094L173.624 107.928",
11999
- stroke: "#52525B",
12000
- strokeWidth: "1.5",
12001
- strokeLinecap: "round",
12002
- strokeLinejoin: "round"
12003
- }
12004
- ),
12005
- /* @__PURE__ */ jsxRuntime.jsx(
12006
- "path",
12007
- {
12008
- opacity: "0.13",
12009
- d: "M176.386 106.126L176.379 107.294",
12010
- stroke: "#52525B",
12011
- strokeWidth: "1.5",
12012
- strokeLinecap: "round",
12013
- strokeLinejoin: "round"
12014
- }
12015
- ),
12016
- /* @__PURE__ */ jsxRuntime.jsx(
12017
- "rect",
12018
- {
12019
- width: "12",
12020
- height: "3",
12021
- rx: "1.5",
12022
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12023
- fill: "#D4D4D8"
12024
- }
12025
- ),
12026
- /* @__PURE__ */ jsxRuntime.jsx(
12027
- "rect",
12028
- {
12029
- x: "0.00428286",
12030
- y: "-0.742904",
12031
- width: "33.5",
12032
- height: "65.5",
12033
- rx: "6.75",
12034
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12035
- fill: "#D4D4D8",
12036
- stroke: "#52525B",
12037
- strokeWidth: "1.5"
12038
- }
12039
- ),
12040
- /* @__PURE__ */ jsxRuntime.jsx(
12041
- "rect",
12042
- {
12043
- x: "0.00428286",
12044
- y: "-0.742904",
12045
- width: "33.5",
12046
- height: "65.5",
12047
- rx: "6.75",
12048
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12049
- fill: "white",
12050
- stroke: "#52525B",
12051
- strokeWidth: "1.5"
12052
- }
12053
- ),
12054
- /* @__PURE__ */ jsxRuntime.jsx(
12055
- "rect",
12056
- {
12057
- width: "12",
12058
- height: "3",
12059
- rx: "1.5",
12060
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12061
- fill: "#D4D4D8"
12062
- }
12063
- ),
12064
- /* @__PURE__ */ jsxRuntime.jsx(
12065
- "rect",
12066
- {
12067
- width: "17",
12068
- height: "3",
12069
- rx: "1.5",
12070
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12071
- fill: "#D4D4D8"
12072
- }
12073
- ),
12074
- /* @__PURE__ */ jsxRuntime.jsx(
12075
- "rect",
12076
- {
12077
- width: "12",
12078
- height: "3",
12079
- rx: "1.5",
12080
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12081
- fill: "#D4D4D8"
12082
- }
12083
- ),
12084
- /* @__PURE__ */ jsxRuntime.jsx(
12085
- "path",
12086
- {
12087
- 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",
12088
- fill: "#A1A1AA"
12089
- }
12090
- ),
12091
- /* @__PURE__ */ jsxRuntime.jsx(
12092
- "rect",
12093
- {
12094
- width: "17",
12095
- height: "3",
12096
- rx: "1.5",
12097
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12098
- fill: "#A1A1AA"
12099
- }
12100
- ),
12101
- /* @__PURE__ */ jsxRuntime.jsx(
12102
- "rect",
12103
- {
12104
- width: "12",
12105
- height: "3",
12106
- rx: "1.5",
12107
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12108
- fill: "#A1A1AA"
12109
- }
12110
- ),
12111
- /* @__PURE__ */ jsxRuntime.jsx(
12112
- "path",
12113
- {
12114
- 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",
12115
- fill: "#52525B"
12116
- }
12117
- ),
12118
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12119
- "path",
12120
- {
12121
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12122
- stroke: "#A1A1AA",
12123
- strokeWidth: "1.5",
12124
- strokeLinecap: "round",
12125
- strokeLinejoin: "round"
12126
- }
12127
- ) }),
12128
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12129
- "path",
12130
- {
12131
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12132
- stroke: "#A1A1AA",
12133
- strokeWidth: "1.5",
12134
- strokeLinecap: "round",
12135
- strokeLinejoin: "round"
12136
- }
12137
- ) }),
12138
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12139
- "path",
12140
- {
12141
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12142
- stroke: "#A1A1AA",
12143
- strokeWidth: "1.5",
12144
- strokeLinecap: "round",
12145
- strokeLinejoin: "round"
12146
- }
12147
- ) }),
12148
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12149
- "path",
12150
- {
12151
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12152
- stroke: "#A1A1AA",
12153
- strokeWidth: "1.5",
12154
- strokeLinecap: "round",
12155
- strokeLinejoin: "round"
12156
- }
12157
- ) }),
12158
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12159
- "path",
12160
- {
12161
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12162
- stroke: "#A1A1AA",
12163
- strokeWidth: "1.5",
12164
- strokeLinecap: "round",
12165
- strokeLinejoin: "round"
12166
- }
12167
- ) }),
12168
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12169
- "path",
12170
- {
12171
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12172
- stroke: "#A1A1AA",
12173
- strokeWidth: "1.5",
12174
- strokeLinecap: "round",
12175
- strokeLinejoin: "round"
12176
- }
12177
- ) }),
12178
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12179
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12180
- "rect",
12181
- {
12182
- width: "12",
12183
- height: "12",
12184
- fill: "white",
12185
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12186
- }
12187
- ) }),
12188
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12189
- "rect",
12190
- {
12191
- width: "12",
12192
- height: "12",
12193
- fill: "white",
12194
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12195
- }
12196
- ) }),
12197
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12198
- "rect",
12199
- {
12200
- width: "12",
12201
- height: "12",
12202
- fill: "white",
12203
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12204
- }
12205
- ) }),
12206
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12207
- "rect",
12208
- {
12209
- width: "12",
12210
- height: "12",
12211
- fill: "white",
12212
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12213
- }
12214
- ) }),
12215
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12216
- "rect",
12217
- {
12218
- width: "12",
12219
- height: "12",
12220
- fill: "white",
12221
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12222
- }
12223
- ) }),
12224
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12225
- "rect",
12226
- {
12227
- width: "12",
12228
- height: "12",
12229
- fill: "white",
12230
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12231
- }
12232
- ) })
12233
- ] })
12234
- ]
12235
- }
12236
- );
12237
- };
12238
- const schema = objectType({
12239
- customer_id: stringType().min(1)
12240
- });
12241
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12242
- const Shipping = () => {
12243
- var _a;
12244
- const { id } = reactRouterDom.useParams();
12245
- const { order, isPending, isError, error } = useOrder(id, {
12246
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12247
- });
12248
- const {
12249
- order: preview,
12250
- isPending: isPreviewPending,
12251
- isError: isPreviewError,
12252
- error: previewError
12253
- } = useOrderPreview(id);
12254
- useInitiateOrderEdit({ preview });
12255
- const { onCancel } = useCancelOrderEdit({ preview });
12256
- if (isError) {
12257
- throw error;
12258
- }
12259
- if (isPreviewError) {
12260
- throw previewError;
12261
- }
12262
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12263
- const isReady = preview && !isPreviewPending && order && !isPending;
12264
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12266
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12267
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12268
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12269
- ] }) }) }),
12270
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12271
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12272
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12273
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12274
- ] }) });
12275
- };
12276
- const ShippingForm = ({ preview, order }) => {
12277
- var _a;
12278
- const { setIsOpen } = useStackedModal();
12279
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12280
- const [data, setData] = React.useState(null);
12281
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12282
- const { shipping_options } = useShippingOptions(
12283
- {
12284
- id: appliedShippingOptionIds,
12285
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12286
- },
12287
- {
12288
- enabled: appliedShippingOptionIds.length > 0
11744
+ enabled: appliedShippingOptionIds.length > 0
12289
11745
  }
12290
11746
  );
12291
11747
  const uniqueShippingProfiles = React.useMemo(() => {
@@ -12626,425 +12082,969 @@ const ShippingForm = ({ preview, order }) => {
12626
12082
  );
12627
12083
  }) })
12628
12084
  ] }) })
12629
- ] }) }),
12630
- /* @__PURE__ */ jsxRuntime.jsx(
12631
- StackedFocusModal,
12085
+ ] }) }),
12086
+ /* @__PURE__ */ jsxRuntime.jsx(
12087
+ StackedFocusModal,
12088
+ {
12089
+ id: STACKED_FOCUS_MODAL_ID,
12090
+ onOpenChangeCallback: (open) => {
12091
+ if (!open) {
12092
+ setData(null);
12093
+ }
12094
+ return open;
12095
+ },
12096
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12097
+ }
12098
+ )
12099
+ ] }),
12100
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12101
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12102
+ /* @__PURE__ */ jsxRuntime.jsx(
12103
+ ui.Button,
12104
+ {
12105
+ size: "small",
12106
+ type: "button",
12107
+ isLoading: isSubmitting,
12108
+ onClick: onSubmit,
12109
+ children: "Save"
12110
+ }
12111
+ )
12112
+ ] }) })
12113
+ ] });
12114
+ };
12115
+ const StackedModalTrigger = ({
12116
+ shippingProfileId,
12117
+ shippingOption,
12118
+ shippingMethod,
12119
+ setData,
12120
+ children
12121
+ }) => {
12122
+ const { setIsOpen, getIsOpen } = useStackedModal();
12123
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12124
+ const onToggle = () => {
12125
+ if (isOpen) {
12126
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12127
+ setData(null);
12128
+ } else {
12129
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12130
+ setData({
12131
+ shippingProfileId,
12132
+ shippingOption,
12133
+ shippingMethod
12134
+ });
12135
+ }
12136
+ };
12137
+ return /* @__PURE__ */ jsxRuntime.jsx(
12138
+ ui.Button,
12139
+ {
12140
+ size: "small",
12141
+ variant: "secondary",
12142
+ onClick: onToggle,
12143
+ className: "text-ui-fg-primary shrink-0",
12144
+ children
12145
+ }
12146
+ );
12147
+ };
12148
+ const ShippingProfileForm = ({
12149
+ data,
12150
+ order,
12151
+ preview
12152
+ }) => {
12153
+ var _a, _b, _c, _d, _e, _f;
12154
+ const { setIsOpen } = useStackedModal();
12155
+ const form = reactHookForm.useForm({
12156
+ resolver: zod.zodResolver(shippingMethodSchema),
12157
+ defaultValues: {
12158
+ 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,
12159
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12160
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12161
+ }
12162
+ });
12163
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12164
+ const {
12165
+ mutateAsync: updateShippingMethod,
12166
+ isPending: isUpdatingShippingMethod
12167
+ } = useDraftOrderUpdateShippingMethod(order.id);
12168
+ const onSubmit = form.handleSubmit(async (values) => {
12169
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12170
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12171
+ return;
12172
+ }
12173
+ if (data.shippingMethod) {
12174
+ await updateShippingMethod(
12175
+ {
12176
+ method_id: data.shippingMethod.id,
12177
+ shipping_option_id: values.shipping_option_id,
12178
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12179
+ },
12180
+ {
12181
+ onError: (e) => {
12182
+ ui.toast.error(e.message);
12183
+ },
12184
+ onSuccess: () => {
12185
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12186
+ }
12187
+ }
12188
+ );
12189
+ return;
12190
+ }
12191
+ await addShippingMethod(
12192
+ {
12193
+ shipping_option_id: values.shipping_option_id,
12194
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12195
+ },
12196
+ {
12197
+ onError: (e) => {
12198
+ ui.toast.error(e.message);
12199
+ },
12200
+ onSuccess: () => {
12201
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12202
+ }
12203
+ }
12204
+ );
12205
+ });
12206
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12207
+ KeyboundForm,
12208
+ {
12209
+ className: "flex h-full flex-col overflow-hidden",
12210
+ onSubmit,
12211
+ children: [
12212
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12213
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12214
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12215
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12216
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12217
+ ] }),
12218
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12219
+ /* @__PURE__ */ jsxRuntime.jsx(
12220
+ LocationField,
12221
+ {
12222
+ control: form.control,
12223
+ setValue: form.setValue
12224
+ }
12225
+ ),
12226
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12227
+ /* @__PURE__ */ jsxRuntime.jsx(
12228
+ ShippingOptionField,
12229
+ {
12230
+ shippingProfileId: data.shippingProfileId,
12231
+ preview,
12232
+ control: form.control
12233
+ }
12234
+ ),
12235
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12236
+ /* @__PURE__ */ jsxRuntime.jsx(
12237
+ CustomAmountField,
12238
+ {
12239
+ control: form.control,
12240
+ currencyCode: order.currency_code
12241
+ }
12242
+ ),
12243
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12244
+ /* @__PURE__ */ jsxRuntime.jsx(
12245
+ ItemsPreview,
12246
+ {
12247
+ order,
12248
+ shippingProfileId: data.shippingProfileId
12249
+ }
12250
+ )
12251
+ ] }) }) }),
12252
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12253
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12254
+ /* @__PURE__ */ jsxRuntime.jsx(
12255
+ ui.Button,
12256
+ {
12257
+ size: "small",
12258
+ type: "submit",
12259
+ isLoading: isPending || isUpdatingShippingMethod,
12260
+ children: data.shippingMethod ? "Update" : "Add"
12261
+ }
12262
+ )
12263
+ ] }) })
12264
+ ]
12265
+ }
12266
+ ) }) });
12267
+ };
12268
+ const shippingMethodSchema = objectType({
12269
+ location_id: stringType(),
12270
+ shipping_option_id: stringType(),
12271
+ custom_amount: unionType([numberType(), stringType()]).optional()
12272
+ });
12273
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12274
+ const matches = order.items.filter(
12275
+ (item) => {
12276
+ var _a, _b, _c;
12277
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12278
+ }
12279
+ );
12280
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12281
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12282
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12283
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12284
+ ] }) }),
12285
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12286
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12287
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12288
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12289
+ ] }),
12290
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12291
+ "div",
12632
12292
  {
12633
- id: STACKED_FOCUS_MODAL_ID,
12634
- onOpenChangeCallback: (open) => {
12635
- if (!open) {
12636
- setData(null);
12293
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12294
+ children: [
12295
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12296
+ /* @__PURE__ */ jsxRuntime.jsx(
12297
+ Thumbnail,
12298
+ {
12299
+ thumbnail: item.thumbnail,
12300
+ alt: item.product_title ?? void 0
12301
+ }
12302
+ ),
12303
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12304
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12305
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12306
+ /* @__PURE__ */ jsxRuntime.jsxs(
12307
+ ui.Text,
12308
+ {
12309
+ size: "small",
12310
+ leading: "compact",
12311
+ className: "text-ui-fg-subtle",
12312
+ children: [
12313
+ "(",
12314
+ item.variant_title,
12315
+ ")"
12316
+ ]
12317
+ }
12318
+ )
12319
+ ] }),
12320
+ /* @__PURE__ */ jsxRuntime.jsx(
12321
+ ui.Text,
12322
+ {
12323
+ size: "small",
12324
+ leading: "compact",
12325
+ className: "text-ui-fg-subtle",
12326
+ children: item.variant_sku
12327
+ }
12328
+ )
12329
+ ] })
12330
+ ] }),
12331
+ /* @__PURE__ */ jsxRuntime.jsxs(
12332
+ ui.Text,
12333
+ {
12334
+ size: "small",
12335
+ leading: "compact",
12336
+ className: "text-ui-fg-subtle",
12337
+ children: [
12338
+ item.quantity,
12339
+ "x"
12340
+ ]
12341
+ }
12342
+ )
12343
+ ]
12344
+ },
12345
+ item.id
12346
+ )) : /* @__PURE__ */ jsxRuntime.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: [
12347
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12348
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12349
+ 'No items found for "',
12350
+ query,
12351
+ '".'
12352
+ ] })
12353
+ ] }) })
12354
+ ] })
12355
+ ] });
12356
+ };
12357
+ const LocationField = ({ control, setValue }) => {
12358
+ const locations = useComboboxData({
12359
+ queryKey: ["locations"],
12360
+ queryFn: async (params) => {
12361
+ return await sdk.admin.stockLocation.list(params);
12362
+ },
12363
+ getOptions: (data) => {
12364
+ return data.stock_locations.map((location) => ({
12365
+ label: location.name,
12366
+ value: location.id
12367
+ }));
12368
+ }
12369
+ });
12370
+ return /* @__PURE__ */ jsxRuntime.jsx(
12371
+ Form$2.Field,
12372
+ {
12373
+ control,
12374
+ name: "location_id",
12375
+ render: ({ field: { onChange, ...field } }) => {
12376
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12377
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12378
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12379
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12380
+ ] }),
12381
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12382
+ Combobox,
12383
+ {
12384
+ options: locations.options,
12385
+ fetchNextPage: locations.fetchNextPage,
12386
+ isFetchingNextPage: locations.isFetchingNextPage,
12387
+ searchValue: locations.searchValue,
12388
+ onSearchValueChange: locations.onSearchValueChange,
12389
+ placeholder: "Select location",
12390
+ onChange: (value) => {
12391
+ setValue("shipping_option_id", "", {
12392
+ shouldDirty: true,
12393
+ shouldTouch: true
12394
+ });
12395
+ onChange(value);
12396
+ },
12397
+ ...field
12637
12398
  }
12638
- return open;
12639
- },
12640
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12399
+ ) })
12400
+ ] }) });
12401
+ }
12402
+ }
12403
+ );
12404
+ };
12405
+ const ShippingOptionField = ({
12406
+ shippingProfileId,
12407
+ preview,
12408
+ control
12409
+ }) => {
12410
+ var _a;
12411
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12412
+ const shippingOptions = useComboboxData({
12413
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12414
+ queryFn: async (params) => {
12415
+ return await sdk.admin.shippingOption.list({
12416
+ ...params,
12417
+ stock_location_id: locationId,
12418
+ shipping_profile_id: shippingProfileId
12419
+ });
12420
+ },
12421
+ getOptions: (data) => {
12422
+ return data.shipping_options.map((option) => {
12423
+ var _a2;
12424
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12425
+ (r) => r.attribute === "is_return" && r.value === "true"
12426
+ )) {
12427
+ return void 0;
12641
12428
  }
12642
- )
12429
+ return {
12430
+ label: option.name,
12431
+ value: option.id
12432
+ };
12433
+ }).filter(Boolean);
12434
+ },
12435
+ enabled: !!locationId && !!shippingProfileId,
12436
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12437
+ });
12438
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12439
+ return /* @__PURE__ */ jsxRuntime.jsx(
12440
+ Form$2.Field,
12441
+ {
12442
+ control,
12443
+ name: "shipping_option_id",
12444
+ render: ({ field }) => {
12445
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12446
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12447
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12448
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12449
+ ] }),
12450
+ /* @__PURE__ */ jsxRuntime.jsx(
12451
+ ConditionalTooltip,
12452
+ {
12453
+ content: tooltipContent,
12454
+ showTooltip: !locationId || !shippingProfileId,
12455
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12456
+ Combobox,
12457
+ {
12458
+ options: shippingOptions.options,
12459
+ fetchNextPage: shippingOptions.fetchNextPage,
12460
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12461
+ searchValue: shippingOptions.searchValue,
12462
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12463
+ placeholder: "Select shipping option",
12464
+ ...field,
12465
+ disabled: !locationId || !shippingProfileId
12466
+ }
12467
+ ) }) })
12468
+ }
12469
+ )
12470
+ ] }) });
12471
+ }
12472
+ }
12473
+ );
12474
+ };
12475
+ const CustomAmountField = ({
12476
+ control,
12477
+ currencyCode
12478
+ }) => {
12479
+ return /* @__PURE__ */ jsxRuntime.jsx(
12480
+ Form$2.Field,
12481
+ {
12482
+ control,
12483
+ name: "custom_amount",
12484
+ render: ({ field: { onChange, ...field } }) => {
12485
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12486
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12487
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12488
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12489
+ ] }),
12490
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12491
+ ui.CurrencyInput,
12492
+ {
12493
+ ...field,
12494
+ onValueChange: (value) => onChange(value),
12495
+ symbol: getNativeSymbol(currencyCode),
12496
+ code: currencyCode
12497
+ }
12498
+ ) })
12499
+ ] });
12500
+ }
12501
+ }
12502
+ );
12503
+ };
12504
+ const TransferOwnership = () => {
12505
+ const { id } = reactRouterDom.useParams();
12506
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12507
+ fields: "id,customer_id,customer.*"
12508
+ });
12509
+ if (isError) {
12510
+ throw error;
12511
+ }
12512
+ const isReady = !isPending && !!draft_order;
12513
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12514
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12515
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12516
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12643
12517
  ] }),
12644
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12645
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12646
- /* @__PURE__ */ jsxRuntime.jsx(
12647
- ui.Button,
12648
- {
12649
- size: "small",
12650
- type: "button",
12651
- isLoading: isSubmitting,
12652
- onClick: onSubmit,
12653
- children: "Save"
12654
- }
12655
- )
12656
- ] }) })
12518
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12657
12519
  ] });
12658
12520
  };
12659
- const StackedModalTrigger = ({
12660
- shippingProfileId,
12661
- shippingOption,
12662
- shippingMethod,
12663
- setData,
12664
- children
12665
- }) => {
12666
- const { setIsOpen, getIsOpen } = useStackedModal();
12667
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12668
- const onToggle = () => {
12669
- if (isOpen) {
12670
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12671
- setData(null);
12672
- } else {
12673
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12674
- setData({
12675
- shippingProfileId,
12676
- shippingOption,
12677
- shippingMethod
12521
+ const TransferOwnershipForm = ({ order }) => {
12522
+ var _a, _b;
12523
+ const form = reactHookForm.useForm({
12524
+ defaultValues: {
12525
+ customer_id: order.customer_id || ""
12526
+ },
12527
+ resolver: zod.zodResolver(schema$1)
12528
+ });
12529
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12530
+ const { handleSuccess } = useRouteModal();
12531
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12532
+ const currentCustomer = order.customer ? {
12533
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12534
+ value: order.customer.id
12535
+ } : null;
12536
+ const onSubmit = form.handleSubmit(async (data) => {
12537
+ await mutateAsync(
12538
+ { customer_id: data.customer_id },
12539
+ {
12540
+ onSuccess: () => {
12541
+ ui.toast.success("Customer updated");
12542
+ handleSuccess();
12543
+ },
12544
+ onError: (error) => {
12545
+ ui.toast.error(error.message);
12546
+ }
12547
+ }
12548
+ );
12549
+ });
12550
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12551
+ KeyboundForm,
12552
+ {
12553
+ className: "flex flex-1 flex-col overflow-hidden",
12554
+ onSubmit,
12555
+ children: [
12556
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12557
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12558
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12559
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12560
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12561
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12562
+ ] }),
12563
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12564
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12565
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12566
+ ] })
12567
+ ] }),
12568
+ /* @__PURE__ */ jsxRuntime.jsx(
12569
+ CustomerField,
12570
+ {
12571
+ control: form.control,
12572
+ currentCustomerId: order.customer_id
12573
+ }
12574
+ )
12575
+ ] }),
12576
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12577
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12578
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12579
+ ] }) })
12580
+ ]
12581
+ }
12582
+ ) });
12583
+ };
12584
+ const CustomerField = ({ control, currentCustomerId }) => {
12585
+ const customers = useComboboxData({
12586
+ queryFn: async (params) => {
12587
+ return await sdk.admin.customer.list({
12588
+ ...params,
12589
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12590
+ });
12591
+ },
12592
+ queryKey: ["customers"],
12593
+ getOptions: (data) => {
12594
+ return data.customers.map((customer) => {
12595
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12596
+ return {
12597
+ label: name ? `${name} (${customer.email})` : customer.email,
12598
+ value: customer.id
12599
+ };
12678
12600
  });
12679
12601
  }
12680
- };
12602
+ });
12681
12603
  return /* @__PURE__ */ jsxRuntime.jsx(
12682
- ui.Button,
12604
+ Form$2.Field,
12683
12605
  {
12684
- size: "small",
12685
- variant: "secondary",
12686
- onClick: onToggle,
12687
- className: "text-ui-fg-primary shrink-0",
12688
- children
12606
+ name: "customer_id",
12607
+ control,
12608
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12609
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12610
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12611
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12612
+ ] }),
12613
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12614
+ Combobox,
12615
+ {
12616
+ options: customers.options,
12617
+ fetchNextPage: customers.fetchNextPage,
12618
+ isFetchingNextPage: customers.isFetchingNextPage,
12619
+ searchValue: customers.searchValue,
12620
+ onSearchValueChange: customers.onSearchValueChange,
12621
+ placeholder: "Select customer",
12622
+ ...field
12623
+ }
12624
+ ) }),
12625
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12626
+ ] })
12689
12627
  }
12690
12628
  );
12691
12629
  };
12692
- const ShippingProfileForm = ({
12693
- data,
12694
- order,
12695
- preview
12696
- }) => {
12697
- var _a, _b, _c, _d, _e, _f;
12698
- const { setIsOpen } = useStackedModal();
12699
- const form = reactHookForm.useForm({
12700
- resolver: zod.zodResolver(shippingMethodSchema),
12701
- defaultValues: {
12702
- 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,
12703
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12704
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12705
- }
12706
- });
12707
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12708
- const {
12709
- mutateAsync: updateShippingMethod,
12710
- isPending: isUpdatingShippingMethod
12711
- } = useDraftOrderUpdateShippingMethod(order.id);
12712
- const onSubmit = form.handleSubmit(async (values) => {
12713
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12714
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12715
- return;
12716
- }
12717
- if (data.shippingMethod) {
12718
- await updateShippingMethod(
12719
- {
12720
- method_id: data.shippingMethod.id,
12721
- shipping_option_id: values.shipping_option_id,
12722
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12723
- },
12724
- {
12725
- onError: (e) => {
12726
- ui.toast.error(e.message);
12727
- },
12728
- onSuccess: () => {
12729
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12630
+ const Illustration = () => {
12631
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12632
+ "svg",
12633
+ {
12634
+ width: "280",
12635
+ height: "180",
12636
+ viewBox: "0 0 280 180",
12637
+ fill: "none",
12638
+ xmlns: "http://www.w3.org/2000/svg",
12639
+ children: [
12640
+ /* @__PURE__ */ jsxRuntime.jsx(
12641
+ "rect",
12642
+ {
12643
+ x: "0.00428286",
12644
+ y: "-0.742904",
12645
+ width: "33.5",
12646
+ height: "65.5",
12647
+ rx: "6.75",
12648
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12649
+ fill: "#D4D4D8",
12650
+ stroke: "#52525B",
12651
+ strokeWidth: "1.5"
12652
+ }
12653
+ ),
12654
+ /* @__PURE__ */ jsxRuntime.jsx(
12655
+ "rect",
12656
+ {
12657
+ x: "0.00428286",
12658
+ y: "-0.742904",
12659
+ width: "33.5",
12660
+ height: "65.5",
12661
+ rx: "6.75",
12662
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12663
+ fill: "white",
12664
+ stroke: "#52525B",
12665
+ strokeWidth: "1.5"
12666
+ }
12667
+ ),
12668
+ /* @__PURE__ */ jsxRuntime.jsx(
12669
+ "path",
12670
+ {
12671
+ d: "M180.579 107.142L179.126 107.959",
12672
+ stroke: "#52525B",
12673
+ strokeWidth: "1.5",
12674
+ strokeLinecap: "round",
12675
+ strokeLinejoin: "round"
12676
+ }
12677
+ ),
12678
+ /* @__PURE__ */ jsxRuntime.jsx(
12679
+ "path",
12680
+ {
12681
+ opacity: "0.88",
12682
+ d: "M182.305 109.546L180.257 109.534",
12683
+ stroke: "#52525B",
12684
+ strokeWidth: "1.5",
12685
+ strokeLinecap: "round",
12686
+ strokeLinejoin: "round"
12687
+ }
12688
+ ),
12689
+ /* @__PURE__ */ jsxRuntime.jsx(
12690
+ "path",
12691
+ {
12692
+ opacity: "0.75",
12693
+ d: "M180.551 111.93L179.108 111.096",
12694
+ stroke: "#52525B",
12695
+ strokeWidth: "1.5",
12696
+ strokeLinecap: "round",
12697
+ strokeLinejoin: "round"
12698
+ }
12699
+ ),
12700
+ /* @__PURE__ */ jsxRuntime.jsx(
12701
+ "path",
12702
+ {
12703
+ opacity: "0.63",
12704
+ d: "M176.347 112.897L176.354 111.73",
12705
+ stroke: "#52525B",
12706
+ strokeWidth: "1.5",
12707
+ strokeLinecap: "round",
12708
+ strokeLinejoin: "round"
12709
+ }
12710
+ ),
12711
+ /* @__PURE__ */ jsxRuntime.jsx(
12712
+ "path",
12713
+ {
12714
+ opacity: "0.5",
12715
+ d: "M172.153 111.881L173.606 111.064",
12716
+ stroke: "#52525B",
12717
+ strokeWidth: "1.5",
12718
+ strokeLinecap: "round",
12719
+ strokeLinejoin: "round"
12720
+ }
12721
+ ),
12722
+ /* @__PURE__ */ jsxRuntime.jsx(
12723
+ "path",
12724
+ {
12725
+ opacity: "0.38",
12726
+ d: "M170.428 109.478L172.476 109.489",
12727
+ stroke: "#52525B",
12728
+ strokeWidth: "1.5",
12729
+ strokeLinecap: "round",
12730
+ strokeLinejoin: "round"
12731
+ }
12732
+ ),
12733
+ /* @__PURE__ */ jsxRuntime.jsx(
12734
+ "path",
12735
+ {
12736
+ opacity: "0.25",
12737
+ d: "M172.181 107.094L173.624 107.928",
12738
+ stroke: "#52525B",
12739
+ strokeWidth: "1.5",
12740
+ strokeLinecap: "round",
12741
+ strokeLinejoin: "round"
12742
+ }
12743
+ ),
12744
+ /* @__PURE__ */ jsxRuntime.jsx(
12745
+ "path",
12746
+ {
12747
+ opacity: "0.13",
12748
+ d: "M176.386 106.126L176.379 107.294",
12749
+ stroke: "#52525B",
12750
+ strokeWidth: "1.5",
12751
+ strokeLinecap: "round",
12752
+ strokeLinejoin: "round"
12753
+ }
12754
+ ),
12755
+ /* @__PURE__ */ jsxRuntime.jsx(
12756
+ "rect",
12757
+ {
12758
+ width: "12",
12759
+ height: "3",
12760
+ rx: "1.5",
12761
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12762
+ fill: "#D4D4D8"
12763
+ }
12764
+ ),
12765
+ /* @__PURE__ */ jsxRuntime.jsx(
12766
+ "rect",
12767
+ {
12768
+ x: "0.00428286",
12769
+ y: "-0.742904",
12770
+ width: "33.5",
12771
+ height: "65.5",
12772
+ rx: "6.75",
12773
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12774
+ fill: "#D4D4D8",
12775
+ stroke: "#52525B",
12776
+ strokeWidth: "1.5"
12777
+ }
12778
+ ),
12779
+ /* @__PURE__ */ jsxRuntime.jsx(
12780
+ "rect",
12781
+ {
12782
+ x: "0.00428286",
12783
+ y: "-0.742904",
12784
+ width: "33.5",
12785
+ height: "65.5",
12786
+ rx: "6.75",
12787
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12788
+ fill: "white",
12789
+ stroke: "#52525B",
12790
+ strokeWidth: "1.5"
12791
+ }
12792
+ ),
12793
+ /* @__PURE__ */ jsxRuntime.jsx(
12794
+ "rect",
12795
+ {
12796
+ width: "12",
12797
+ height: "3",
12798
+ rx: "1.5",
12799
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12800
+ fill: "#D4D4D8"
12801
+ }
12802
+ ),
12803
+ /* @__PURE__ */ jsxRuntime.jsx(
12804
+ "rect",
12805
+ {
12806
+ width: "17",
12807
+ height: "3",
12808
+ rx: "1.5",
12809
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12810
+ fill: "#D4D4D8"
12811
+ }
12812
+ ),
12813
+ /* @__PURE__ */ jsxRuntime.jsx(
12814
+ "rect",
12815
+ {
12816
+ width: "12",
12817
+ height: "3",
12818
+ rx: "1.5",
12819
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12820
+ fill: "#D4D4D8"
12821
+ }
12822
+ ),
12823
+ /* @__PURE__ */ jsxRuntime.jsx(
12824
+ "path",
12825
+ {
12826
+ 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",
12827
+ fill: "#A1A1AA"
12828
+ }
12829
+ ),
12830
+ /* @__PURE__ */ jsxRuntime.jsx(
12831
+ "rect",
12832
+ {
12833
+ width: "17",
12834
+ height: "3",
12835
+ rx: "1.5",
12836
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12837
+ fill: "#A1A1AA"
12838
+ }
12839
+ ),
12840
+ /* @__PURE__ */ jsxRuntime.jsx(
12841
+ "rect",
12842
+ {
12843
+ width: "12",
12844
+ height: "3",
12845
+ rx: "1.5",
12846
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12847
+ fill: "#A1A1AA"
12730
12848
  }
12731
- }
12732
- );
12733
- return;
12734
- }
12735
- await addShippingMethod(
12736
- {
12737
- shipping_option_id: values.shipping_option_id,
12738
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12739
- },
12740
- {
12741
- onError: (e) => {
12742
- ui.toast.error(e.message);
12743
- },
12744
- onSuccess: () => {
12745
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12746
- }
12747
- }
12748
- );
12749
- });
12750
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12751
- KeyboundForm,
12752
- {
12753
- className: "flex h-full flex-col overflow-hidden",
12754
- onSubmit,
12755
- children: [
12756
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12757
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12758
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12759
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12760
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12761
- ] }),
12762
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12763
- /* @__PURE__ */ jsxRuntime.jsx(
12764
- LocationField,
12765
- {
12766
- control: form.control,
12767
- setValue: form.setValue
12768
- }
12769
- ),
12770
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12771
- /* @__PURE__ */ jsxRuntime.jsx(
12772
- ShippingOptionField,
12773
- {
12774
- shippingProfileId: data.shippingProfileId,
12775
- preview,
12776
- control: form.control
12777
- }
12778
- ),
12779
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12780
- /* @__PURE__ */ jsxRuntime.jsx(
12781
- CustomAmountField,
12782
- {
12783
- control: form.control,
12784
- currencyCode: order.currency_code
12785
- }
12786
- ),
12787
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12788
- /* @__PURE__ */ jsxRuntime.jsx(
12789
- ItemsPreview,
12790
- {
12791
- order,
12792
- shippingProfileId: data.shippingProfileId
12793
- }
12794
- )
12795
- ] }) }) }),
12796
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12797
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12798
- /* @__PURE__ */ jsxRuntime.jsx(
12799
- ui.Button,
12800
- {
12801
- size: "small",
12802
- type: "submit",
12803
- isLoading: isPending || isUpdatingShippingMethod,
12804
- children: data.shippingMethod ? "Update" : "Add"
12805
- }
12806
- )
12807
- ] }) })
12808
- ]
12809
- }
12810
- ) }) });
12811
- };
12812
- const shippingMethodSchema = objectType({
12813
- location_id: stringType(),
12814
- shipping_option_id: stringType(),
12815
- custom_amount: unionType([numberType(), stringType()]).optional()
12816
- });
12817
- const ItemsPreview = ({ order, shippingProfileId }) => {
12818
- const matches = order.items.filter(
12819
- (item) => {
12820
- var _a, _b, _c;
12821
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12822
- }
12823
- );
12824
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12825
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12826
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12827
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12828
- ] }) }),
12829
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12830
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12831
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12832
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12833
- ] }),
12834
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12835
- "div",
12836
- {
12837
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12838
- children: [
12839
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12840
- /* @__PURE__ */ jsxRuntime.jsx(
12841
- Thumbnail,
12842
- {
12843
- thumbnail: item.thumbnail,
12844
- alt: item.product_title ?? void 0
12845
- }
12846
- ),
12847
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12848
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12849
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12850
- /* @__PURE__ */ jsxRuntime.jsxs(
12851
- ui.Text,
12852
- {
12853
- size: "small",
12854
- leading: "compact",
12855
- className: "text-ui-fg-subtle",
12856
- children: [
12857
- "(",
12858
- item.variant_title,
12859
- ")"
12860
- ]
12861
- }
12862
- )
12863
- ] }),
12864
- /* @__PURE__ */ jsxRuntime.jsx(
12865
- ui.Text,
12866
- {
12867
- size: "small",
12868
- leading: "compact",
12869
- className: "text-ui-fg-subtle",
12870
- children: item.variant_sku
12871
- }
12872
- )
12873
- ] })
12874
- ] }),
12875
- /* @__PURE__ */ jsxRuntime.jsxs(
12876
- ui.Text,
12877
- {
12878
- size: "small",
12879
- leading: "compact",
12880
- className: "text-ui-fg-subtle",
12881
- children: [
12882
- item.quantity,
12883
- "x"
12884
- ]
12885
- }
12886
- )
12887
- ]
12888
- },
12889
- item.id
12890
- )) : /* @__PURE__ */ jsxRuntime.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: [
12891
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12892
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12893
- 'No items found for "',
12894
- query,
12895
- '".'
12896
- ] })
12897
- ] }) })
12898
- ] })
12899
- ] });
12900
- };
12901
- const LocationField = ({ control, setValue }) => {
12902
- const locations = useComboboxData({
12903
- queryKey: ["locations"],
12904
- queryFn: async (params) => {
12905
- return await sdk.admin.stockLocation.list(params);
12906
- },
12907
- getOptions: (data) => {
12908
- return data.stock_locations.map((location) => ({
12909
- label: location.name,
12910
- value: location.id
12911
- }));
12912
- }
12913
- });
12914
- return /* @__PURE__ */ jsxRuntime.jsx(
12915
- Form$2.Field,
12916
- {
12917
- control,
12918
- name: "location_id",
12919
- render: ({ field: { onChange, ...field } }) => {
12920
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12921
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12922
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12923
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12924
- ] }),
12925
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12926
- Combobox,
12849
+ ),
12850
+ /* @__PURE__ */ jsxRuntime.jsx(
12851
+ "path",
12852
+ {
12853
+ 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",
12854
+ fill: "#52525B"
12855
+ }
12856
+ ),
12857
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12858
+ "path",
12859
+ {
12860
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12861
+ stroke: "#A1A1AA",
12862
+ strokeWidth: "1.5",
12863
+ strokeLinecap: "round",
12864
+ strokeLinejoin: "round"
12865
+ }
12866
+ ) }),
12867
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12868
+ "path",
12869
+ {
12870
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12871
+ stroke: "#A1A1AA",
12872
+ strokeWidth: "1.5",
12873
+ strokeLinecap: "round",
12874
+ strokeLinejoin: "round"
12875
+ }
12876
+ ) }),
12877
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12878
+ "path",
12879
+ {
12880
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12881
+ stroke: "#A1A1AA",
12882
+ strokeWidth: "1.5",
12883
+ strokeLinecap: "round",
12884
+ strokeLinejoin: "round"
12885
+ }
12886
+ ) }),
12887
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12888
+ "path",
12889
+ {
12890
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12891
+ stroke: "#A1A1AA",
12892
+ strokeWidth: "1.5",
12893
+ strokeLinecap: "round",
12894
+ strokeLinejoin: "round"
12895
+ }
12896
+ ) }),
12897
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12898
+ "path",
12899
+ {
12900
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12901
+ stroke: "#A1A1AA",
12902
+ strokeWidth: "1.5",
12903
+ strokeLinecap: "round",
12904
+ strokeLinejoin: "round"
12905
+ }
12906
+ ) }),
12907
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12908
+ "path",
12909
+ {
12910
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12911
+ stroke: "#A1A1AA",
12912
+ strokeWidth: "1.5",
12913
+ strokeLinecap: "round",
12914
+ strokeLinejoin: "round"
12915
+ }
12916
+ ) }),
12917
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12918
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12919
+ "rect",
12927
12920
  {
12928
- options: locations.options,
12929
- fetchNextPage: locations.fetchNextPage,
12930
- isFetchingNextPage: locations.isFetchingNextPage,
12931
- searchValue: locations.searchValue,
12932
- onSearchValueChange: locations.onSearchValueChange,
12933
- placeholder: "Select location",
12934
- onChange: (value) => {
12935
- setValue("shipping_option_id", "", {
12936
- shouldDirty: true,
12937
- shouldTouch: true
12938
- });
12939
- onChange(value);
12940
- },
12941
- ...field
12921
+ width: "12",
12922
+ height: "12",
12923
+ fill: "white",
12924
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12925
+ }
12926
+ ) }),
12927
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12928
+ "rect",
12929
+ {
12930
+ width: "12",
12931
+ height: "12",
12932
+ fill: "white",
12933
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12934
+ }
12935
+ ) }),
12936
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12937
+ "rect",
12938
+ {
12939
+ width: "12",
12940
+ height: "12",
12941
+ fill: "white",
12942
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12943
+ }
12944
+ ) }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12946
+ "rect",
12947
+ {
12948
+ width: "12",
12949
+ height: "12",
12950
+ fill: "white",
12951
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12952
+ }
12953
+ ) }),
12954
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12955
+ "rect",
12956
+ {
12957
+ width: "12",
12958
+ height: "12",
12959
+ fill: "white",
12960
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12961
+ }
12962
+ ) }),
12963
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12964
+ "rect",
12965
+ {
12966
+ width: "12",
12967
+ height: "12",
12968
+ fill: "white",
12969
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12942
12970
  }
12943
12971
  ) })
12944
- ] }) });
12945
- }
12972
+ ] })
12973
+ ]
12946
12974
  }
12947
12975
  );
12948
12976
  };
12949
- const ShippingOptionField = ({
12950
- shippingProfileId,
12951
- preview,
12952
- control
12953
- }) => {
12954
- var _a;
12955
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12956
- const shippingOptions = useComboboxData({
12957
- queryKey: ["shipping_options", locationId, shippingProfileId],
12958
- queryFn: async (params) => {
12959
- return await sdk.admin.shippingOption.list({
12960
- ...params,
12961
- stock_location_id: locationId,
12962
- shipping_profile_id: shippingProfileId
12963
- });
12964
- },
12965
- getOptions: (data) => {
12966
- return data.shipping_options.map((option) => {
12967
- var _a2;
12968
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12969
- (r) => r.attribute === "is_return" && r.value === "true"
12970
- )) {
12971
- return void 0;
12972
- }
12973
- return {
12974
- label: option.name,
12975
- value: option.id
12976
- };
12977
- }).filter(Boolean);
12977
+ const schema$1 = objectType({
12978
+ customer_id: stringType().min(1)
12979
+ });
12980
+ const Email = () => {
12981
+ const { id } = reactRouterDom.useParams();
12982
+ const { order, isPending, isError, error } = useOrder(id, {
12983
+ fields: "+email"
12984
+ });
12985
+ if (isError) {
12986
+ throw error;
12987
+ }
12988
+ const isReady = !isPending && !!order;
12989
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12990
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12991
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12992
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12993
+ ] }),
12994
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12995
+ ] });
12996
+ };
12997
+ const EmailForm = ({ order }) => {
12998
+ const form = reactHookForm.useForm({
12999
+ defaultValues: {
13000
+ email: order.email ?? ""
12978
13001
  },
12979
- enabled: !!locationId && !!shippingProfileId,
12980
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
13002
+ resolver: zod.zodResolver(schema)
12981
13003
  });
12982
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12983
- return /* @__PURE__ */ jsxRuntime.jsx(
12984
- Form$2.Field,
12985
- {
12986
- control,
12987
- name: "shipping_option_id",
12988
- render: ({ field }) => {
12989
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12990
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12991
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12992
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12993
- ] }),
12994
- /* @__PURE__ */ jsxRuntime.jsx(
12995
- ConditionalTooltip,
12996
- {
12997
- content: tooltipContent,
12998
- showTooltip: !locationId || !shippingProfileId,
12999
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13000
- Combobox,
13001
- {
13002
- options: shippingOptions.options,
13003
- fetchNextPage: shippingOptions.fetchNextPage,
13004
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
13005
- searchValue: shippingOptions.searchValue,
13006
- onSearchValueChange: shippingOptions.onSearchValueChange,
13007
- placeholder: "Select shipping option",
13008
- ...field,
13009
- disabled: !locationId || !shippingProfileId
13010
- }
13011
- ) }) })
13012
- }
13013
- )
13014
- ] }) });
13004
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
13005
+ const { handleSuccess } = useRouteModal();
13006
+ const onSubmit = form.handleSubmit(async (data) => {
13007
+ await mutateAsync(
13008
+ { email: data.email },
13009
+ {
13010
+ onSuccess: () => {
13011
+ handleSuccess();
13012
+ },
13013
+ onError: (error) => {
13014
+ ui.toast.error(error.message);
13015
+ }
13015
13016
  }
13016
- }
13017
- );
13018
- };
13019
- const CustomAmountField = ({
13020
- control,
13021
- currencyCode
13022
- }) => {
13023
- return /* @__PURE__ */ jsxRuntime.jsx(
13024
- Form$2.Field,
13017
+ );
13018
+ });
13019
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13020
+ KeyboundForm,
13025
13021
  {
13026
- control,
13027
- name: "custom_amount",
13028
- render: ({ field: { onChange, ...field } }) => {
13029
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13030
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
13033
- ] }),
13034
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13035
- ui.CurrencyInput,
13036
- {
13037
- ...field,
13038
- onValueChange: (value) => onChange(value),
13039
- symbol: getNativeSymbol(currencyCode),
13040
- code: currencyCode
13041
- }
13042
- ) })
13043
- ] });
13044
- }
13022
+ className: "flex flex-1 flex-col overflow-hidden",
13023
+ onSubmit,
13024
+ children: [
13025
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Form$2.Field,
13027
+ {
13028
+ control: form.control,
13029
+ name: "email",
13030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
+ ] })
13035
+ }
13036
+ ) }),
13037
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13040
+ ] }) })
13041
+ ]
13045
13042
  }
13046
- );
13043
+ ) });
13047
13044
  };
13045
+ const schema = objectType({
13046
+ email: stringType().email()
13047
+ });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13073,10 +13073,6 @@ const routeModule = {
13073
13073
  Component: CustomItems,
13074
13074
  path: "/draft-orders/:id/custom-items"
13075
13075
  },
13076
- {
13077
- Component: Email,
13078
- path: "/draft-orders/:id/email"
13079
- },
13080
13076
  {
13081
13077
  Component: Items,
13082
13078
  path: "/draft-orders/:id/items"
@@ -13097,13 +13093,17 @@ const routeModule = {
13097
13093
  Component: ShippingAddress,
13098
13094
  path: "/draft-orders/:id/shipping-address"
13099
13095
  },
13096
+ {
13097
+ Component: Shipping,
13098
+ path: "/draft-orders/:id/shipping"
13099
+ },
13100
13100
  {
13101
13101
  Component: TransferOwnership,
13102
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
13103
  },
13104
13104
  {
13105
- Component: Shipping,
13106
- path: "/draft-orders/:id/shipping"
13105
+ Component: Email,
13106
+ path: "/draft-orders/:id/email"
13107
13107
  }
13108
13108
  ]
13109
13109
  }