@medusajs/draft-order 2.21.0 → 2.21.1-preview-20260916094546

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.
@@ -6161,95 +6161,6 @@ const BillingAddressForm = ({ order }) => {
6161
6161
  ) });
6162
6162
  };
6163
6163
  const schema$5 = addressSchema;
6164
- const CustomItems = () => {
6165
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
6166
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
6167
- /* @__PURE__ */ jsx(CustomItemsForm, {})
6168
- ] });
6169
- };
6170
- const CustomItemsForm = () => {
6171
- const form = useForm({
6172
- resolver: zodResolver(schema$4)
6173
- });
6174
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
6175
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
6176
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
6177
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
6178
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
6179
- ] }) })
6180
- ] }) });
6181
- };
6182
- const schema$4 = z.object({
6183
- email: z.string().email()
6184
- });
6185
- const Email = () => {
6186
- const { id } = useParams();
6187
- const { order, isPending, isError, error } = useOrder(id, {
6188
- fields: "+email"
6189
- });
6190
- if (isError) {
6191
- throw error;
6192
- }
6193
- const isReady = !isPending && !!order;
6194
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
6195
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
6196
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
6197
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
6198
- ] }),
6199
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
6200
- ] });
6201
- };
6202
- const EmailForm = ({ order }) => {
6203
- const form = useForm({
6204
- defaultValues: {
6205
- email: order.email ?? ""
6206
- },
6207
- resolver: zodResolver(schema$3)
6208
- });
6209
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
6210
- const { handleSuccess } = useRouteModal();
6211
- const onSubmit = form.handleSubmit(async (data) => {
6212
- await mutateAsync(
6213
- { email: data.email },
6214
- {
6215
- onSuccess: () => {
6216
- handleSuccess();
6217
- },
6218
- onError: (error) => {
6219
- toast.error(error.message);
6220
- }
6221
- }
6222
- );
6223
- });
6224
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
6225
- KeyboundForm,
6226
- {
6227
- className: "flex flex-1 flex-col overflow-hidden",
6228
- onSubmit,
6229
- children: [
6230
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
6231
- Form$2.Field,
6232
- {
6233
- control: form.control,
6234
- name: "email",
6235
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
6236
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
6237
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
6238
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
6239
- ] })
6240
- }
6241
- ) }),
6242
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
6243
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
6244
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
6245
- ] }) })
6246
- ]
6247
- }
6248
- ) });
6249
- };
6250
- const schema$3 = z.object({
6251
- email: z.string().email()
6252
- });
6253
6164
  const NumberInput = forwardRef(
6254
6165
  ({
6255
6166
  value,
@@ -7269,6 +7180,95 @@ const customItemSchema = z.object({
7269
7180
  quantity: z.number(),
7270
7181
  unit_price: z.union([z.number(), z.string()])
7271
7182
  });
7183
+ const Email = () => {
7184
+ const { id } = useParams();
7185
+ const { order, isPending, isError, error } = useOrder(id, {
7186
+ fields: "+email"
7187
+ });
7188
+ if (isError) {
7189
+ throw error;
7190
+ }
7191
+ const isReady = !isPending && !!order;
7192
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7193
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
7194
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
7195
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
7196
+ ] }),
7197
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
7198
+ ] });
7199
+ };
7200
+ const EmailForm = ({ order }) => {
7201
+ const form = useForm({
7202
+ defaultValues: {
7203
+ email: order.email ?? ""
7204
+ },
7205
+ resolver: zodResolver(schema$4)
7206
+ });
7207
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7208
+ const { handleSuccess } = useRouteModal();
7209
+ const onSubmit = form.handleSubmit(async (data) => {
7210
+ await mutateAsync(
7211
+ { email: data.email },
7212
+ {
7213
+ onSuccess: () => {
7214
+ handleSuccess();
7215
+ },
7216
+ onError: (error) => {
7217
+ toast.error(error.message);
7218
+ }
7219
+ }
7220
+ );
7221
+ });
7222
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
7223
+ KeyboundForm,
7224
+ {
7225
+ className: "flex flex-1 flex-col overflow-hidden",
7226
+ onSubmit,
7227
+ children: [
7228
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
7229
+ Form$2.Field,
7230
+ {
7231
+ control: form.control,
7232
+ name: "email",
7233
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7234
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
7235
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
7236
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7237
+ ] })
7238
+ }
7239
+ ) }),
7240
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7241
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7242
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7243
+ ] }) })
7244
+ ]
7245
+ }
7246
+ ) });
7247
+ };
7248
+ const schema$4 = z.object({
7249
+ email: z.string().email()
7250
+ });
7251
+ const CustomItems = () => {
7252
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7253
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
7254
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
7255
+ ] });
7256
+ };
7257
+ const CustomItemsForm = () => {
7258
+ const form = useForm({
7259
+ resolver: zodResolver(schema$3)
7260
+ });
7261
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
7262
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
7263
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7264
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7265
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
7266
+ ] }) })
7267
+ ] }) });
7268
+ };
7269
+ const schema$3 = z.object({
7270
+ email: z.string().email()
7271
+ });
7272
7272
  const InlineTip = forwardRef(
7273
7273
  ({ variant = "tip", label, className, children, ...props }, ref) => {
7274
7274
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -7894,170 +7894,64 @@ function getPromotionIds(items, shippingMethods) {
7894
7894
  }
7895
7895
  return Array.from(promotionIds);
7896
7896
  }
7897
- const SalesChannel = () => {
7897
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
7898
+ const Shipping = () => {
7898
7899
  const { id } = useParams();
7899
- const { draft_order, isPending, isError, error } = useDraftOrder(
7900
- id,
7901
- {
7902
- fields: "+sales_channel_id"
7903
- },
7904
- {
7905
- enabled: !!id
7906
- }
7907
- );
7900
+ const { order, isPending, isError, error } = useOrder(id, {
7901
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
7902
+ });
7903
+ const {
7904
+ order: preview,
7905
+ isPending: isPreviewPending,
7906
+ isError: isPreviewError,
7907
+ error: previewError
7908
+ } = useOrderPreview(id);
7909
+ useInitiateOrderEdit({ preview });
7910
+ const { onCancel } = useCancelOrderEdit({ preview });
7908
7911
  if (isError) {
7909
7912
  throw error;
7910
7913
  }
7911
- const ISrEADY = !!draft_order && !isPending;
7912
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
7913
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
7914
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
7915
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
7916
- ] }),
7917
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
7918
- ] });
7914
+ if (isPreviewError) {
7915
+ throw previewError;
7916
+ }
7917
+ const orderHasItems = (order?.items?.length || 0) > 0;
7918
+ const isReady = preview && !isPreviewPending && order && !isPending;
7919
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
7920
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
7921
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
7922
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
7923
+ /* @__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." }) })
7924
+ ] }) }) }),
7925
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
7926
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
7927
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
7928
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
7929
+ ] }) });
7919
7930
  };
7920
- const SalesChannelForm = ({ order }) => {
7921
- const form = useForm({
7922
- defaultValues: {
7923
- sales_channel_id: order.sales_channel_id || ""
7931
+ const ShippingForm = ({ preview, order }) => {
7932
+ const { setIsOpen } = useStackedModal();
7933
+ const [isSubmitting, setIsSubmitting] = useState(false);
7934
+ const [data, setData] = useState(null);
7935
+ const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
7936
+ const { shipping_options } = useShippingOptions(
7937
+ {
7938
+ id: appliedShippingOptionIds,
7939
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
7924
7940
  },
7925
- resolver: zodResolver(schema$2)
7926
- });
7927
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
7928
- const { handleSuccess } = useRouteModal();
7929
- const onSubmit = form.handleSubmit(async (data) => {
7930
- await mutateAsync(
7931
- {
7932
- sales_channel_id: data.sales_channel_id
7933
- },
7934
- {
7935
- onSuccess: () => {
7936
- toast.success("Sales channel updated");
7937
- handleSuccess();
7938
- },
7939
- onError: (error) => {
7940
- toast.error(error.message);
7941
- }
7942
- }
7943
- );
7944
- });
7945
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
7946
- KeyboundForm,
7947
- {
7948
- className: "flex flex-1 flex-col overflow-hidden",
7949
- onSubmit,
7950
- children: [
7951
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
7952
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
7953
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
7954
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
7955
- ] }) })
7956
- ]
7957
- }
7958
- ) });
7959
- };
7960
- const SalesChannelField = ({ control, order }) => {
7961
- const salesChannels = useComboboxData({
7962
- queryFn: async (params) => {
7963
- return await sdk.admin.salesChannel.list(params);
7964
- },
7965
- queryKey: ["sales-channels"],
7966
- getOptions: (data) => {
7967
- return data.sales_channels.map((salesChannel) => ({
7968
- label: salesChannel.name,
7969
- value: salesChannel.id
7970
- }));
7971
- },
7972
- defaultValue: order.sales_channel_id || void 0
7973
- });
7974
- return /* @__PURE__ */ jsx(
7975
- Form$2.Field,
7976
- {
7977
- control,
7978
- name: "sales_channel_id",
7979
- render: ({ field }) => {
7980
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
7981
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
7982
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
7983
- Combobox,
7984
- {
7985
- options: salesChannels.options,
7986
- fetchNextPage: salesChannels.fetchNextPage,
7987
- isFetchingNextPage: salesChannels.isFetchingNextPage,
7988
- searchValue: salesChannels.searchValue,
7989
- onSearchValueChange: salesChannels.onSearchValueChange,
7990
- placeholder: "Select sales channel",
7991
- ...field
7992
- }
7993
- ) }),
7994
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
7995
- ] });
7996
- }
7997
- }
7998
- );
7999
- };
8000
- const schema$2 = z.object({
8001
- sales_channel_id: z.string().min(1)
8002
- });
8003
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
8004
- const Shipping = () => {
8005
- const { id } = useParams();
8006
- const { order, isPending, isError, error } = useOrder(id, {
8007
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
8008
- });
8009
- const {
8010
- order: preview,
8011
- isPending: isPreviewPending,
8012
- isError: isPreviewError,
8013
- error: previewError
8014
- } = useOrderPreview(id);
8015
- useInitiateOrderEdit({ preview });
8016
- const { onCancel } = useCancelOrderEdit({ preview });
8017
- if (isError) {
8018
- throw error;
8019
- }
8020
- if (isPreviewError) {
8021
- throw previewError;
8022
- }
8023
- const orderHasItems = (order?.items?.length || 0) > 0;
8024
- const isReady = preview && !isPreviewPending && order && !isPending;
8025
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
8026
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
8027
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
8028
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
8029
- /* @__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." }) })
8030
- ] }) }) }),
8031
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
8032
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
8033
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
8034
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
8035
- ] }) });
8036
- };
8037
- const ShippingForm = ({ preview, order }) => {
8038
- const { setIsOpen } = useStackedModal();
8039
- const [isSubmitting, setIsSubmitting] = useState(false);
8040
- const [data, setData] = useState(null);
8041
- const appliedShippingOptionIds = preview.shipping_methods?.map((method) => method.shipping_option_id).filter(Boolean);
8042
- const { shipping_options } = useShippingOptions(
8043
- {
8044
- id: appliedShippingOptionIds,
8045
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
8046
- },
8047
- {
8048
- enabled: appliedShippingOptionIds.length > 0
8049
- }
8050
- );
8051
- const uniqueShippingProfiles = useMemo(() => {
8052
- const profiles = /* @__PURE__ */ new Map();
8053
- getUniqueShippingProfiles(order.items).forEach((profile) => {
8054
- profiles.set(profile.id, profile);
8055
- });
8056
- shipping_options?.forEach((option) => {
8057
- profiles.set(option.shipping_profile_id, option.shipping_profile);
8058
- });
8059
- return Array.from(profiles.values());
8060
- }, [order.items, shipping_options]);
7941
+ {
7942
+ enabled: appliedShippingOptionIds.length > 0
7943
+ }
7944
+ );
7945
+ const uniqueShippingProfiles = useMemo(() => {
7946
+ const profiles = /* @__PURE__ */ new Map();
7947
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
7948
+ profiles.set(profile.id, profile);
7949
+ });
7950
+ shipping_options?.forEach((option) => {
7951
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
7952
+ });
7953
+ return Array.from(profiles.values());
7954
+ }, [order.items, shipping_options]);
8061
7955
  const { handleSuccess } = useRouteModal();
8062
7956
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
8063
7957
  const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
@@ -8794,59 +8688,43 @@ const CustomAmountField = ({
8794
8688
  }
8795
8689
  );
8796
8690
  };
8797
- const ShippingAddress = () => {
8691
+ const TransferOwnership = () => {
8798
8692
  const { id } = useParams();
8799
- const { order, isPending, isError, error } = useOrder(id, {
8800
- fields: "+shipping_address"
8693
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
8694
+ fields: "id,customer_id,customer.*"
8801
8695
  });
8802
8696
  if (isError) {
8803
8697
  throw error;
8804
8698
  }
8805
- const isReady = !isPending && !!order;
8699
+ const isReady = !isPending && !!draft_order;
8806
8700
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
8807
8701
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
8808
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
8809
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
8702
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
8703
+ /* @__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" }) })
8810
8704
  ] }),
8811
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
8705
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
8812
8706
  ] });
8813
8707
  };
8814
- const ShippingAddressForm = ({ order }) => {
8708
+ const TransferOwnershipForm = ({ order }) => {
8815
8709
  const form = useForm({
8816
8710
  defaultValues: {
8817
- first_name: order.shipping_address?.first_name ?? "",
8818
- last_name: order.shipping_address?.last_name ?? "",
8819
- company: order.shipping_address?.company ?? "",
8820
- address_1: order.shipping_address?.address_1 ?? "",
8821
- address_2: order.shipping_address?.address_2 ?? "",
8822
- city: order.shipping_address?.city ?? "",
8823
- province: order.shipping_address?.province ?? "",
8824
- country_code: order.shipping_address?.country_code ?? "",
8825
- postal_code: order.shipping_address?.postal_code ?? "",
8826
- phone: order.shipping_address?.phone ?? ""
8711
+ customer_id: order.customer_id || ""
8827
8712
  },
8828
- resolver: zodResolver(schema$1)
8713
+ resolver: zodResolver(schema$2)
8829
8714
  });
8830
8715
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
8831
8716
  const { handleSuccess } = useRouteModal();
8717
+ const name = [order.customer?.first_name, order.customer?.last_name].filter(Boolean).join(" ");
8718
+ const currentCustomer = order.customer ? {
8719
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
8720
+ value: order.customer.id
8721
+ } : null;
8832
8722
  const onSubmit = form.handleSubmit(async (data) => {
8833
8723
  await mutateAsync(
8834
- {
8835
- shipping_address: {
8836
- first_name: data.first_name,
8837
- last_name: data.last_name,
8838
- company: data.company,
8839
- address_1: data.address_1,
8840
- address_2: data.address_2,
8841
- city: data.city,
8842
- province: data.province,
8843
- country_code: data.country_code,
8844
- postal_code: data.postal_code,
8845
- phone: data.phone
8846
- }
8847
- },
8724
+ { customer_id: data.customer_id },
8848
8725
  {
8849
8726
  onSuccess: () => {
8727
+ toast.success("Customer updated");
8850
8728
  handleSuccess();
8851
8729
  },
8852
8730
  onError: (error) => {
@@ -8861,209 +8739,23 @@ const ShippingAddressForm = ({ order }) => {
8861
8739
  className: "flex flex-1 flex-col overflow-hidden",
8862
8740
  onSubmit,
8863
8741
  children: [
8864
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
8865
- /* @__PURE__ */ jsx(
8866
- Form$2.Field,
8867
- {
8868
- control: form.control,
8869
- name: "country_code",
8870
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8871
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
8872
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
8873
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8874
- ] })
8875
- }
8876
- ),
8877
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
8878
- /* @__PURE__ */ jsx(
8879
- Form$2.Field,
8880
- {
8881
- control: form.control,
8882
- name: "first_name",
8883
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8884
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
8885
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8886
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8887
- ] })
8888
- }
8889
- ),
8890
- /* @__PURE__ */ jsx(
8891
- Form$2.Field,
8892
- {
8893
- control: form.control,
8894
- name: "last_name",
8895
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8896
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
8897
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8898
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8899
- ] })
8900
- }
8901
- )
8742
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
8743
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
8744
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
8745
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
8746
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
8747
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
8748
+ ] }),
8749
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
8750
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
8751
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
8752
+ ] })
8902
8753
  ] }),
8903
8754
  /* @__PURE__ */ jsx(
8904
- Form$2.Field,
8905
- {
8906
- control: form.control,
8907
- name: "company",
8908
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8909
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
8910
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8911
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8912
- ] })
8913
- }
8914
- ),
8915
- /* @__PURE__ */ jsx(
8916
- Form$2.Field,
8755
+ CustomerField,
8917
8756
  {
8918
8757
  control: form.control,
8919
- name: "address_1",
8920
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8921
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
8922
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8923
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8924
- ] })
8925
- }
8926
- ),
8927
- /* @__PURE__ */ jsx(
8928
- Form$2.Field,
8929
- {
8930
- control: form.control,
8931
- name: "address_2",
8932
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8933
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
8934
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8935
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8936
- ] })
8937
- }
8938
- ),
8939
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
8940
- /* @__PURE__ */ jsx(
8941
- Form$2.Field,
8942
- {
8943
- control: form.control,
8944
- name: "postal_code",
8945
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8946
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
8947
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8948
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8949
- ] })
8950
- }
8951
- ),
8952
- /* @__PURE__ */ jsx(
8953
- Form$2.Field,
8954
- {
8955
- control: form.control,
8956
- name: "city",
8957
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8958
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
8959
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8960
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8961
- ] })
8962
- }
8963
- )
8964
- ] }),
8965
- /* @__PURE__ */ jsx(
8966
- Form$2.Field,
8967
- {
8968
- control: form.control,
8969
- name: "province",
8970
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8971
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
8972
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8973
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8974
- ] })
8975
- }
8976
- ),
8977
- /* @__PURE__ */ jsx(
8978
- Form$2.Field,
8979
- {
8980
- control: form.control,
8981
- name: "phone",
8982
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
8983
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
8984
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
8985
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
8986
- ] })
8987
- }
8988
- )
8989
- ] }) }),
8990
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
8991
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8992
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
8993
- ] }) })
8994
- ]
8995
- }
8996
- ) });
8997
- };
8998
- const schema$1 = addressSchema;
8999
- const TransferOwnership = () => {
9000
- const { id } = useParams();
9001
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
9002
- fields: "id,customer_id,customer.*"
9003
- });
9004
- if (isError) {
9005
- throw error;
9006
- }
9007
- const isReady = !isPending && !!draft_order;
9008
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9009
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9010
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
9011
- /* @__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" }) })
9012
- ] }),
9013
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
9014
- ] });
9015
- };
9016
- const TransferOwnershipForm = ({ order }) => {
9017
- const form = useForm({
9018
- defaultValues: {
9019
- customer_id: order.customer_id || ""
9020
- },
9021
- resolver: zodResolver(schema)
9022
- });
9023
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9024
- const { handleSuccess } = useRouteModal();
9025
- const name = [order.customer?.first_name, order.customer?.last_name].filter(Boolean).join(" ");
9026
- const currentCustomer = order.customer ? {
9027
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
9028
- value: order.customer.id
9029
- } : null;
9030
- const onSubmit = form.handleSubmit(async (data) => {
9031
- await mutateAsync(
9032
- { customer_id: data.customer_id },
9033
- {
9034
- onSuccess: () => {
9035
- toast.success("Customer updated");
9036
- handleSuccess();
9037
- },
9038
- onError: (error) => {
9039
- toast.error(error.message);
9040
- }
9041
- }
9042
- );
9043
- });
9044
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9045
- KeyboundForm,
9046
- {
9047
- className: "flex flex-1 flex-col overflow-hidden",
9048
- onSubmit,
9049
- children: [
9050
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
9051
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
9052
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
9053
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
9054
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
9055
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
9056
- ] }),
9057
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
9058
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
9059
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
9060
- ] })
9061
- ] }),
9062
- /* @__PURE__ */ jsx(
9063
- CustomerField,
9064
- {
9065
- control: form.control,
9066
- currentCustomerId: order.customer_id
8758
+ currentCustomerId: order.customer_id
9067
8759
  }
9068
8760
  )
9069
8761
  ] }),
@@ -9468,9 +9160,317 @@ const Illustration = () => {
9468
9160
  }
9469
9161
  );
9470
9162
  };
9471
- const schema = z.object({
9163
+ const schema$2 = z.object({
9472
9164
  customer_id: z.string().min(1)
9473
9165
  });
9166
+ const ShippingAddress = () => {
9167
+ const { id } = useParams();
9168
+ const { order, isPending, isError, error } = useOrder(id, {
9169
+ fields: "+shipping_address"
9170
+ });
9171
+ if (isError) {
9172
+ throw error;
9173
+ }
9174
+ const isReady = !isPending && !!order;
9175
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9176
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9177
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
9178
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
9179
+ ] }),
9180
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
9181
+ ] });
9182
+ };
9183
+ const ShippingAddressForm = ({ order }) => {
9184
+ const form = useForm({
9185
+ defaultValues: {
9186
+ first_name: order.shipping_address?.first_name ?? "",
9187
+ last_name: order.shipping_address?.last_name ?? "",
9188
+ company: order.shipping_address?.company ?? "",
9189
+ address_1: order.shipping_address?.address_1 ?? "",
9190
+ address_2: order.shipping_address?.address_2 ?? "",
9191
+ city: order.shipping_address?.city ?? "",
9192
+ province: order.shipping_address?.province ?? "",
9193
+ country_code: order.shipping_address?.country_code ?? "",
9194
+ postal_code: order.shipping_address?.postal_code ?? "",
9195
+ phone: order.shipping_address?.phone ?? ""
9196
+ },
9197
+ resolver: zodResolver(schema$1)
9198
+ });
9199
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9200
+ const { handleSuccess } = useRouteModal();
9201
+ const onSubmit = form.handleSubmit(async (data) => {
9202
+ await mutateAsync(
9203
+ {
9204
+ shipping_address: {
9205
+ first_name: data.first_name,
9206
+ last_name: data.last_name,
9207
+ company: data.company,
9208
+ address_1: data.address_1,
9209
+ address_2: data.address_2,
9210
+ city: data.city,
9211
+ province: data.province,
9212
+ country_code: data.country_code,
9213
+ postal_code: data.postal_code,
9214
+ phone: data.phone
9215
+ }
9216
+ },
9217
+ {
9218
+ onSuccess: () => {
9219
+ handleSuccess();
9220
+ },
9221
+ onError: (error) => {
9222
+ toast.error(error.message);
9223
+ }
9224
+ }
9225
+ );
9226
+ });
9227
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9228
+ KeyboundForm,
9229
+ {
9230
+ className: "flex flex-1 flex-col overflow-hidden",
9231
+ onSubmit,
9232
+ children: [
9233
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9234
+ /* @__PURE__ */ jsx(
9235
+ Form$2.Field,
9236
+ {
9237
+ control: form.control,
9238
+ name: "country_code",
9239
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9240
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9241
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9242
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9243
+ ] })
9244
+ }
9245
+ ),
9246
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9247
+ /* @__PURE__ */ jsx(
9248
+ Form$2.Field,
9249
+ {
9250
+ control: form.control,
9251
+ name: "first_name",
9252
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9253
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9254
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9255
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9256
+ ] })
9257
+ }
9258
+ ),
9259
+ /* @__PURE__ */ jsx(
9260
+ Form$2.Field,
9261
+ {
9262
+ control: form.control,
9263
+ name: "last_name",
9264
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9265
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9266
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9267
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9268
+ ] })
9269
+ }
9270
+ )
9271
+ ] }),
9272
+ /* @__PURE__ */ jsx(
9273
+ Form$2.Field,
9274
+ {
9275
+ control: form.control,
9276
+ name: "company",
9277
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9278
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9279
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9280
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9281
+ ] })
9282
+ }
9283
+ ),
9284
+ /* @__PURE__ */ jsx(
9285
+ Form$2.Field,
9286
+ {
9287
+ control: form.control,
9288
+ name: "address_1",
9289
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9290
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9291
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9292
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9293
+ ] })
9294
+ }
9295
+ ),
9296
+ /* @__PURE__ */ jsx(
9297
+ Form$2.Field,
9298
+ {
9299
+ control: form.control,
9300
+ name: "address_2",
9301
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9302
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9303
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9304
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9305
+ ] })
9306
+ }
9307
+ ),
9308
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9309
+ /* @__PURE__ */ jsx(
9310
+ Form$2.Field,
9311
+ {
9312
+ control: form.control,
9313
+ name: "postal_code",
9314
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9315
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9316
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9317
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9318
+ ] })
9319
+ }
9320
+ ),
9321
+ /* @__PURE__ */ jsx(
9322
+ Form$2.Field,
9323
+ {
9324
+ control: form.control,
9325
+ name: "city",
9326
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9327
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9328
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9329
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9330
+ ] })
9331
+ }
9332
+ )
9333
+ ] }),
9334
+ /* @__PURE__ */ jsx(
9335
+ Form$2.Field,
9336
+ {
9337
+ control: form.control,
9338
+ name: "province",
9339
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9340
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9341
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9342
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9343
+ ] })
9344
+ }
9345
+ ),
9346
+ /* @__PURE__ */ jsx(
9347
+ Form$2.Field,
9348
+ {
9349
+ control: form.control,
9350
+ name: "phone",
9351
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9352
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9353
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9354
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9355
+ ] })
9356
+ }
9357
+ )
9358
+ ] }) }),
9359
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9360
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9361
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9362
+ ] }) })
9363
+ ]
9364
+ }
9365
+ ) });
9366
+ };
9367
+ const schema$1 = addressSchema;
9368
+ const SalesChannel = () => {
9369
+ const { id } = useParams();
9370
+ const { draft_order, isPending, isError, error } = useDraftOrder(
9371
+ id,
9372
+ {
9373
+ fields: "+sales_channel_id"
9374
+ },
9375
+ {
9376
+ enabled: !!id
9377
+ }
9378
+ );
9379
+ if (isError) {
9380
+ throw error;
9381
+ }
9382
+ const ISrEADY = !!draft_order && !isPending;
9383
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9384
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9385
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
9386
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
9387
+ ] }),
9388
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
9389
+ ] });
9390
+ };
9391
+ const SalesChannelForm = ({ order }) => {
9392
+ const form = useForm({
9393
+ defaultValues: {
9394
+ sales_channel_id: order.sales_channel_id || ""
9395
+ },
9396
+ resolver: zodResolver(schema)
9397
+ });
9398
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9399
+ const { handleSuccess } = useRouteModal();
9400
+ const onSubmit = form.handleSubmit(async (data) => {
9401
+ await mutateAsync(
9402
+ {
9403
+ sales_channel_id: data.sales_channel_id
9404
+ },
9405
+ {
9406
+ onSuccess: () => {
9407
+ toast.success("Sales channel updated");
9408
+ handleSuccess();
9409
+ },
9410
+ onError: (error) => {
9411
+ toast.error(error.message);
9412
+ }
9413
+ }
9414
+ );
9415
+ });
9416
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9417
+ KeyboundForm,
9418
+ {
9419
+ className: "flex flex-1 flex-col overflow-hidden",
9420
+ onSubmit,
9421
+ children: [
9422
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
9423
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9424
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9425
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9426
+ ] }) })
9427
+ ]
9428
+ }
9429
+ ) });
9430
+ };
9431
+ const SalesChannelField = ({ control, order }) => {
9432
+ const salesChannels = useComboboxData({
9433
+ queryFn: async (params) => {
9434
+ return await sdk.admin.salesChannel.list(params);
9435
+ },
9436
+ queryKey: ["sales-channels"],
9437
+ getOptions: (data) => {
9438
+ return data.sales_channels.map((salesChannel) => ({
9439
+ label: salesChannel.name,
9440
+ value: salesChannel.id
9441
+ }));
9442
+ },
9443
+ defaultValue: order.sales_channel_id || void 0
9444
+ });
9445
+ return /* @__PURE__ */ jsx(
9446
+ Form$2.Field,
9447
+ {
9448
+ control,
9449
+ name: "sales_channel_id",
9450
+ render: ({ field }) => {
9451
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9452
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
9453
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9454
+ Combobox,
9455
+ {
9456
+ options: salesChannels.options,
9457
+ fetchNextPage: salesChannels.fetchNextPage,
9458
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
9459
+ searchValue: salesChannels.searchValue,
9460
+ onSearchValueChange: salesChannels.onSearchValueChange,
9461
+ placeholder: "Select sales channel",
9462
+ ...field
9463
+ }
9464
+ ) }),
9465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9466
+ ] });
9467
+ }
9468
+ }
9469
+ );
9470
+ };
9471
+ const schema = z.object({
9472
+ sales_channel_id: z.string().min(1)
9473
+ });
9474
9474
  const widgetModule = { widgets: [] };
9475
9475
  const routeModule = {
9476
9476
  routes: [
@@ -9496,16 +9496,16 @@ const routeModule = {
9496
9496
  path: "/draft-orders/:id/billing-address"
9497
9497
  },
9498
9498
  {
9499
- Component: CustomItems,
9500
- path: "/draft-orders/:id/custom-items"
9499
+ Component: Items,
9500
+ path: "/draft-orders/:id/items"
9501
9501
  },
9502
9502
  {
9503
9503
  Component: Email,
9504
9504
  path: "/draft-orders/:id/email"
9505
9505
  },
9506
9506
  {
9507
- Component: Items,
9508
- path: "/draft-orders/:id/items"
9507
+ Component: CustomItems,
9508
+ path: "/draft-orders/:id/custom-items"
9509
9509
  },
9510
9510
  {
9511
9511
  Component: Metadata,
@@ -9515,21 +9515,21 @@ const routeModule = {
9515
9515
  Component: Promotions,
9516
9516
  path: "/draft-orders/:id/promotions"
9517
9517
  },
9518
- {
9519
- Component: SalesChannel,
9520
- path: "/draft-orders/:id/sales-channel"
9521
- },
9522
9518
  {
9523
9519
  Component: Shipping,
9524
9520
  path: "/draft-orders/:id/shipping"
9525
9521
  },
9522
+ {
9523
+ Component: TransferOwnership,
9524
+ path: "/draft-orders/:id/transfer-ownership"
9525
+ },
9526
9526
  {
9527
9527
  Component: ShippingAddress,
9528
9528
  path: "/draft-orders/:id/shipping-address"
9529
9529
  },
9530
9530
  {
9531
- Component: TransferOwnership,
9532
- path: "/draft-orders/:id/transfer-ownership"
9531
+ Component: SalesChannel,
9532
+ path: "/draft-orders/:id/sales-channel"
9533
9533
  }
9534
9534
  ]
9535
9535
  }