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