@medusajs/draft-order 2.11.2-preview-20251028000318 → 2.11.2-preview-20251028060159

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.
@@ -10560,74 +10560,6 @@ const customItemSchema = objectType({
10560
10560
  quantity: numberType(),
10561
10561
  unit_price: unionType([numberType(), stringType()])
10562
10562
  });
10563
- const Email = () => {
10564
- const { id } = useParams();
10565
- const { order, isPending, isError, error } = useOrder(id, {
10566
- fields: "+email"
10567
- });
10568
- if (isError) {
10569
- throw error;
10570
- }
10571
- const isReady = !isPending && !!order;
10572
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10573
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10574
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10575
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10576
- ] }),
10577
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10578
- ] });
10579
- };
10580
- const EmailForm = ({ order }) => {
10581
- const form = useForm({
10582
- defaultValues: {
10583
- email: order.email ?? ""
10584
- },
10585
- resolver: zodResolver(schema$4)
10586
- });
10587
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10588
- const { handleSuccess } = useRouteModal();
10589
- const onSubmit = form.handleSubmit(async (data) => {
10590
- await mutateAsync(
10591
- { email: data.email },
10592
- {
10593
- onSuccess: () => {
10594
- handleSuccess();
10595
- },
10596
- onError: (error) => {
10597
- toast.error(error.message);
10598
- }
10599
- }
10600
- );
10601
- });
10602
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10603
- KeyboundForm,
10604
- {
10605
- className: "flex flex-1 flex-col overflow-hidden",
10606
- onSubmit,
10607
- children: [
10608
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10609
- Form$2.Field,
10610
- {
10611
- control: form.control,
10612
- name: "email",
10613
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10614
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10615
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10616
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10617
- ] })
10618
- }
10619
- ) }),
10620
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10621
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10622
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10623
- ] }) })
10624
- ]
10625
- }
10626
- ) });
10627
- };
10628
- const schema$4 = objectType({
10629
- email: stringType().email()
10630
- });
10631
10563
  const InlineTip = forwardRef(
10632
10564
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10633
10565
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -10978,283 +10910,93 @@ function getHasUneditableRows(metadata) {
10978
10910
  (value) => !EDITABLE_TYPES.includes(typeof value)
10979
10911
  );
10980
10912
  }
10981
- const BillingAddress = () => {
10982
- const { id } = useParams();
10983
- const { order, isPending, isError, error } = useOrder(id, {
10984
- fields: "+billing_address"
10913
+ const PROMOTION_QUERY_KEY = "promotions";
10914
+ const promotionsQueryKeys = {
10915
+ list: (query2) => [
10916
+ PROMOTION_QUERY_KEY,
10917
+ query2 ? query2 : void 0
10918
+ ],
10919
+ detail: (id, query2) => [
10920
+ PROMOTION_QUERY_KEY,
10921
+ id,
10922
+ query2 ? query2 : void 0
10923
+ ]
10924
+ };
10925
+ const usePromotions = (query2, options) => {
10926
+ const { data, ...rest } = useQuery({
10927
+ queryKey: promotionsQueryKeys.list(query2),
10928
+ queryFn: async () => sdk.admin.promotion.list(query2),
10929
+ ...options
10985
10930
  });
10986
- if (isError) {
10987
- throw error;
10931
+ return { ...data, ...rest };
10932
+ };
10933
+ const Promotions = () => {
10934
+ const { id } = useParams();
10935
+ const {
10936
+ order: preview,
10937
+ isError: isPreviewError,
10938
+ error: previewError
10939
+ } = useOrderPreview(id, void 0);
10940
+ useInitiateOrderEdit({ preview });
10941
+ const { onCancel } = useCancelOrderEdit({ preview });
10942
+ if (isPreviewError) {
10943
+ throw previewError;
10988
10944
  }
10989
- const isReady = !isPending && !!order;
10990
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10991
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10992
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
10993
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
10994
- ] }),
10995
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
10945
+ const isReady = !!preview;
10946
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10947
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10948
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10996
10949
  ] });
10997
10950
  };
10998
- const BillingAddressForm = ({ order }) => {
10999
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11000
- const form = useForm({
11001
- defaultValues: {
11002
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
11003
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
11004
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
11005
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
11006
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
11007
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
11008
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
11009
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
11010
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11011
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
10951
+ const PromotionForm = ({ preview }) => {
10952
+ const { items, shipping_methods } = preview;
10953
+ const [isSubmitting, setIsSubmitting] = useState(false);
10954
+ const [comboboxValue, setComboboxValue] = useState("");
10955
+ const { handleSuccess } = useRouteModal();
10956
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10957
+ const promoIds = getPromotionIds(items, shipping_methods);
10958
+ const { promotions, isPending, isError, error } = usePromotions(
10959
+ {
10960
+ id: promoIds
11012
10961
  },
11013
- resolver: zodResolver(schema$3)
10962
+ {
10963
+ enabled: !!promoIds.length
10964
+ }
10965
+ );
10966
+ const comboboxData = useComboboxData({
10967
+ queryKey: ["promotions", "combobox", promoIds],
10968
+ queryFn: async (params) => {
10969
+ return await sdk.admin.promotion.list({
10970
+ ...params,
10971
+ id: {
10972
+ $nin: promoIds
10973
+ }
10974
+ });
10975
+ },
10976
+ getOptions: (data) => {
10977
+ return data.promotions.map((promotion) => ({
10978
+ label: promotion.code,
10979
+ value: promotion.code
10980
+ }));
10981
+ }
11014
10982
  });
11015
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11016
- const { handleSuccess } = useRouteModal();
11017
- const onSubmit = form.handleSubmit(async (data) => {
11018
- await mutateAsync(
11019
- { billing_address: data },
10983
+ const add = async (value) => {
10984
+ if (!value) {
10985
+ return;
10986
+ }
10987
+ addPromotions(
11020
10988
  {
11021
- onSuccess: () => {
11022
- handleSuccess();
10989
+ promo_codes: [value]
10990
+ },
10991
+ {
10992
+ onError: (e) => {
10993
+ toast.error(e.message);
10994
+ comboboxData.onSearchValueChange("");
10995
+ setComboboxValue("");
11023
10996
  },
11024
- onError: (error) => {
11025
- toast.error(error.message);
11026
- }
11027
- }
11028
- );
11029
- });
11030
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11031
- KeyboundForm,
11032
- {
11033
- className: "flex flex-1 flex-col overflow-hidden",
11034
- onSubmit,
11035
- children: [
11036
- /* @__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: [
11037
- /* @__PURE__ */ jsx(
11038
- Form$2.Field,
11039
- {
11040
- control: form.control,
11041
- name: "country_code",
11042
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11043
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11044
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11045
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11046
- ] })
11047
- }
11048
- ),
11049
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11050
- /* @__PURE__ */ jsx(
11051
- Form$2.Field,
11052
- {
11053
- control: form.control,
11054
- name: "first_name",
11055
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11056
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11057
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11058
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11059
- ] })
11060
- }
11061
- ),
11062
- /* @__PURE__ */ jsx(
11063
- Form$2.Field,
11064
- {
11065
- control: form.control,
11066
- name: "last_name",
11067
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11068
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11069
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11070
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11071
- ] })
11072
- }
11073
- )
11074
- ] }),
11075
- /* @__PURE__ */ jsx(
11076
- Form$2.Field,
11077
- {
11078
- control: form.control,
11079
- name: "company",
11080
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11081
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11082
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11083
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11084
- ] })
11085
- }
11086
- ),
11087
- /* @__PURE__ */ jsx(
11088
- Form$2.Field,
11089
- {
11090
- control: form.control,
11091
- name: "address_1",
11092
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11093
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11094
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11095
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11096
- ] })
11097
- }
11098
- ),
11099
- /* @__PURE__ */ jsx(
11100
- Form$2.Field,
11101
- {
11102
- control: form.control,
11103
- name: "address_2",
11104
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11105
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11106
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11107
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11108
- ] })
11109
- }
11110
- ),
11111
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11112
- /* @__PURE__ */ jsx(
11113
- Form$2.Field,
11114
- {
11115
- control: form.control,
11116
- name: "postal_code",
11117
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11118
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11119
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11120
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11121
- ] })
11122
- }
11123
- ),
11124
- /* @__PURE__ */ jsx(
11125
- Form$2.Field,
11126
- {
11127
- control: form.control,
11128
- name: "city",
11129
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11130
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11131
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11132
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11133
- ] })
11134
- }
11135
- )
11136
- ] }),
11137
- /* @__PURE__ */ jsx(
11138
- Form$2.Field,
11139
- {
11140
- control: form.control,
11141
- name: "province",
11142
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11143
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11144
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11145
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11146
- ] })
11147
- }
11148
- ),
11149
- /* @__PURE__ */ jsx(
11150
- Form$2.Field,
11151
- {
11152
- control: form.control,
11153
- name: "phone",
11154
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11155
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11156
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11157
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11158
- ] })
11159
- }
11160
- )
11161
- ] }) }),
11162
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11163
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11164
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11165
- ] }) })
11166
- ]
11167
- }
11168
- ) });
11169
- };
11170
- const schema$3 = addressSchema;
11171
- const PROMOTION_QUERY_KEY = "promotions";
11172
- const promotionsQueryKeys = {
11173
- list: (query2) => [
11174
- PROMOTION_QUERY_KEY,
11175
- query2 ? query2 : void 0
11176
- ],
11177
- detail: (id, query2) => [
11178
- PROMOTION_QUERY_KEY,
11179
- id,
11180
- query2 ? query2 : void 0
11181
- ]
11182
- };
11183
- const usePromotions = (query2, options) => {
11184
- const { data, ...rest } = useQuery({
11185
- queryKey: promotionsQueryKeys.list(query2),
11186
- queryFn: async () => sdk.admin.promotion.list(query2),
11187
- ...options
11188
- });
11189
- return { ...data, ...rest };
11190
- };
11191
- const Promotions = () => {
11192
- const { id } = useParams();
11193
- const {
11194
- order: preview,
11195
- isError: isPreviewError,
11196
- error: previewError
11197
- } = useOrderPreview(id, void 0);
11198
- useInitiateOrderEdit({ preview });
11199
- const { onCancel } = useCancelOrderEdit({ preview });
11200
- if (isPreviewError) {
11201
- throw previewError;
11202
- }
11203
- const isReady = !!preview;
11204
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11205
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11206
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11207
- ] });
11208
- };
11209
- const PromotionForm = ({ preview }) => {
11210
- const { items, shipping_methods } = preview;
11211
- const [isSubmitting, setIsSubmitting] = useState(false);
11212
- const [comboboxValue, setComboboxValue] = useState("");
11213
- const { handleSuccess } = useRouteModal();
11214
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11215
- const promoIds = getPromotionIds(items, shipping_methods);
11216
- const { promotions, isPending, isError, error } = usePromotions(
11217
- {
11218
- id: promoIds
11219
- },
11220
- {
11221
- enabled: !!promoIds.length
11222
- }
11223
- );
11224
- const comboboxData = useComboboxData({
11225
- queryKey: ["promotions", "combobox", promoIds],
11226
- queryFn: async (params) => {
11227
- return await sdk.admin.promotion.list({
11228
- ...params,
11229
- id: {
11230
- $nin: promoIds
11231
- }
11232
- });
11233
- },
11234
- getOptions: (data) => {
11235
- return data.promotions.map((promotion) => ({
11236
- label: promotion.code,
11237
- value: promotion.code
11238
- }));
11239
- }
11240
- });
11241
- const add = async (value) => {
11242
- if (!value) {
11243
- return;
11244
- }
11245
- addPromotions(
11246
- {
11247
- promo_codes: [value]
11248
- },
11249
- {
11250
- onError: (e) => {
11251
- toast.error(e.message);
11252
- comboboxData.onSearchValueChange("");
11253
- setComboboxValue("");
11254
- },
11255
- onSuccess: () => {
11256
- comboboxData.onSearchValueChange("");
11257
- setComboboxValue("");
10997
+ onSuccess: () => {
10998
+ comboboxData.onSearchValueChange("");
10999
+ setComboboxValue("");
11258
11000
  }
11259
11001
  }
11260
11002
  );
@@ -11473,7 +11215,7 @@ const SalesChannelForm = ({ order }) => {
11473
11215
  defaultValues: {
11474
11216
  sales_channel_id: order.sales_channel_id || ""
11475
11217
  },
11476
- resolver: zodResolver(schema$2)
11218
+ resolver: zodResolver(schema$4)
11477
11219
  });
11478
11220
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
11221
  const { handleSuccess } = useRouteModal();
@@ -11548,7 +11290,7 @@ const SalesChannelField = ({ control, order }) => {
11548
11290
  }
11549
11291
  );
11550
11292
  };
11551
- const schema$2 = objectType({
11293
+ const schema$4 = objectType({
11552
11294
  sales_channel_id: stringType().min(1)
11553
11295
  });
11554
11296
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12390,7 +12132,7 @@ const ShippingAddressForm = ({ order }) => {
12390
12132
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
12133
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12392
12134
  },
12393
- resolver: zodResolver(schema$1)
12135
+ resolver: zodResolver(schema$3)
12394
12136
  });
12395
12137
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12396
12138
  const { handleSuccess } = useRouteModal();
@@ -12560,7 +12302,7 @@ const ShippingAddressForm = ({ order }) => {
12560
12302
  }
12561
12303
  ) });
12562
12304
  };
12563
- const schema$1 = addressSchema;
12305
+ const schema$3 = addressSchema;
12564
12306
  const TransferOwnership = () => {
12565
12307
  const { id } = useParams();
12566
12308
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12584,7 +12326,7 @@ const TransferOwnershipForm = ({ order }) => {
12584
12326
  defaultValues: {
12585
12327
  customer_id: order.customer_id || ""
12586
12328
  },
12587
- resolver: zodResolver(schema)
12329
+ resolver: zodResolver(schema$2)
12588
12330
  });
12589
12331
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
12332
  const { handleSuccess } = useRouteModal();
@@ -13034,9 +12776,267 @@ const Illustration = () => {
13034
12776
  }
13035
12777
  );
13036
12778
  };
13037
- const schema = objectType({
12779
+ const schema$2 = objectType({
13038
12780
  customer_id: stringType().min(1)
13039
12781
  });
12782
+ const BillingAddress = () => {
12783
+ const { id } = useParams();
12784
+ const { order, isPending, isError, error } = useOrder(id, {
12785
+ fields: "+billing_address"
12786
+ });
12787
+ if (isError) {
12788
+ throw error;
12789
+ }
12790
+ const isReady = !isPending && !!order;
12791
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12792
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12793
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12794
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12795
+ ] }),
12796
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12797
+ ] });
12798
+ };
12799
+ const BillingAddressForm = ({ order }) => {
12800
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12801
+ const form = useForm({
12802
+ defaultValues: {
12803
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12804
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12805
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12806
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12807
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12808
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12809
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12810
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12811
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12812
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12813
+ },
12814
+ resolver: zodResolver(schema$1)
12815
+ });
12816
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12817
+ const { handleSuccess } = useRouteModal();
12818
+ const onSubmit = form.handleSubmit(async (data) => {
12819
+ await mutateAsync(
12820
+ { billing_address: data },
12821
+ {
12822
+ onSuccess: () => {
12823
+ handleSuccess();
12824
+ },
12825
+ onError: (error) => {
12826
+ toast.error(error.message);
12827
+ }
12828
+ }
12829
+ );
12830
+ });
12831
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12832
+ KeyboundForm,
12833
+ {
12834
+ className: "flex flex-1 flex-col overflow-hidden",
12835
+ onSubmit,
12836
+ children: [
12837
+ /* @__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: [
12838
+ /* @__PURE__ */ jsx(
12839
+ Form$2.Field,
12840
+ {
12841
+ control: form.control,
12842
+ name: "country_code",
12843
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12844
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12845
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12846
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12847
+ ] })
12848
+ }
12849
+ ),
12850
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12851
+ /* @__PURE__ */ jsx(
12852
+ Form$2.Field,
12853
+ {
12854
+ control: form.control,
12855
+ name: "first_name",
12856
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12857
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12858
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12859
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12860
+ ] })
12861
+ }
12862
+ ),
12863
+ /* @__PURE__ */ jsx(
12864
+ Form$2.Field,
12865
+ {
12866
+ control: form.control,
12867
+ name: "last_name",
12868
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12869
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12870
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12871
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12872
+ ] })
12873
+ }
12874
+ )
12875
+ ] }),
12876
+ /* @__PURE__ */ jsx(
12877
+ Form$2.Field,
12878
+ {
12879
+ control: form.control,
12880
+ name: "company",
12881
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12882
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12883
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12884
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12885
+ ] })
12886
+ }
12887
+ ),
12888
+ /* @__PURE__ */ jsx(
12889
+ Form$2.Field,
12890
+ {
12891
+ control: form.control,
12892
+ name: "address_1",
12893
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12894
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12895
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12896
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12897
+ ] })
12898
+ }
12899
+ ),
12900
+ /* @__PURE__ */ jsx(
12901
+ Form$2.Field,
12902
+ {
12903
+ control: form.control,
12904
+ name: "address_2",
12905
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12906
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12907
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12908
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12909
+ ] })
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12913
+ /* @__PURE__ */ jsx(
12914
+ Form$2.Field,
12915
+ {
12916
+ control: form.control,
12917
+ name: "postal_code",
12918
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12919
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12920
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12921
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12922
+ ] })
12923
+ }
12924
+ ),
12925
+ /* @__PURE__ */ jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "city",
12930
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12931
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12932
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12933
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12934
+ ] })
12935
+ }
12936
+ )
12937
+ ] }),
12938
+ /* @__PURE__ */ jsx(
12939
+ Form$2.Field,
12940
+ {
12941
+ control: form.control,
12942
+ name: "province",
12943
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12944
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12945
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12946
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12947
+ ] })
12948
+ }
12949
+ ),
12950
+ /* @__PURE__ */ jsx(
12951
+ Form$2.Field,
12952
+ {
12953
+ control: form.control,
12954
+ name: "phone",
12955
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12956
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12957
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12958
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12959
+ ] })
12960
+ }
12961
+ )
12962
+ ] }) }),
12963
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12964
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12965
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12966
+ ] }) })
12967
+ ]
12968
+ }
12969
+ ) });
12970
+ };
12971
+ const schema$1 = addressSchema;
12972
+ const Email = () => {
12973
+ const { id } = useParams();
12974
+ const { order, isPending, isError, error } = useOrder(id, {
12975
+ fields: "+email"
12976
+ });
12977
+ if (isError) {
12978
+ throw error;
12979
+ }
12980
+ const isReady = !isPending && !!order;
12981
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12982
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12983
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12984
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12985
+ ] }),
12986
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12987
+ ] });
12988
+ };
12989
+ const EmailForm = ({ order }) => {
12990
+ const form = useForm({
12991
+ defaultValues: {
12992
+ email: order.email ?? ""
12993
+ },
12994
+ resolver: zodResolver(schema)
12995
+ });
12996
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12997
+ const { handleSuccess } = useRouteModal();
12998
+ const onSubmit = form.handleSubmit(async (data) => {
12999
+ await mutateAsync(
13000
+ { email: data.email },
13001
+ {
13002
+ onSuccess: () => {
13003
+ handleSuccess();
13004
+ },
13005
+ onError: (error) => {
13006
+ toast.error(error.message);
13007
+ }
13008
+ }
13009
+ );
13010
+ });
13011
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
13012
+ KeyboundForm,
13013
+ {
13014
+ className: "flex flex-1 flex-col overflow-hidden",
13015
+ onSubmit,
13016
+ children: [
13017
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
13018
+ Form$2.Field,
13019
+ {
13020
+ control: form.control,
13021
+ name: "email",
13022
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13023
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
13024
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13025
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13026
+ ] })
13027
+ }
13028
+ ) }),
13029
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13030
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13031
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13032
+ ] }) })
13033
+ ]
13034
+ }
13035
+ ) });
13036
+ };
13037
+ const schema = objectType({
13038
+ email: stringType().email()
13039
+ });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13065,18 +13065,10 @@ const routeModule = {
13065
13065
  Component: Items,
13066
13066
  path: "/draft-orders/:id/items"
13067
13067
  },
13068
- {
13069
- Component: Email,
13070
- path: "/draft-orders/:id/email"
13071
- },
13072
13068
  {
13073
13069
  Component: Metadata,
13074
13070
  path: "/draft-orders/:id/metadata"
13075
13071
  },
13076
- {
13077
- Component: BillingAddress,
13078
- path: "/draft-orders/:id/billing-address"
13079
- },
13080
13072
  {
13081
13073
  Component: Promotions,
13082
13074
  path: "/draft-orders/:id/promotions"
@@ -13096,6 +13088,14 @@ const routeModule = {
13096
13088
  {
13097
13089
  Component: TransferOwnership,
13098
13090
  path: "/draft-orders/:id/transfer-ownership"
13091
+ },
13092
+ {
13093
+ Component: BillingAddress,
13094
+ path: "/draft-orders/:id/billing-address"
13095
+ },
13096
+ {
13097
+ Component: Email,
13098
+ path: "/draft-orders/:id/email"
13099
13099
  }
13100
13100
  ]
13101
13101
  }