@medusajs/draft-order 2.10.4-preview-20250929120206 → 2.10.4-preview-20250929180201

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.
@@ -9573,10 +9573,31 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const BillingAddress = () => {
9576
+ const CustomItems = () => {
9577
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9579
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9580
+ ] });
9581
+ };
9582
+ const CustomItemsForm = () => {
9583
+ const form = reactHookForm.useForm({
9584
+ resolver: zod.zodResolver(schema$5)
9585
+ });
9586
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9590
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9591
+ ] }) })
9592
+ ] }) });
9593
+ };
9594
+ const schema$5 = objectType({
9595
+ email: stringType().email()
9596
+ });
9597
+ const Email = () => {
9577
9598
  const { id } = reactRouterDom.useParams();
9578
9599
  const { order, isPending, isError, error } = useOrder(id, {
9579
- fields: "+billing_address"
9600
+ fields: "+email"
9580
9601
  });
9581
9602
  if (isError) {
9582
9603
  throw error;
@@ -9584,34 +9605,24 @@ const BillingAddress = () => {
9584
9605
  const isReady = !isPending && !!order;
9585
9606
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
9607
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9588
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9608
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9609
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9589
9610
  ] }),
9590
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9611
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9591
9612
  ] });
9592
9613
  };
9593
- const BillingAddressForm = ({ order }) => {
9594
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9614
+ const EmailForm = ({ order }) => {
9595
9615
  const form = reactHookForm.useForm({
9596
9616
  defaultValues: {
9597
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9598
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9599
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9600
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9601
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9602
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9603
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9604
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9605
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9617
+ email: order.email ?? ""
9607
9618
  },
9608
- resolver: zod.zodResolver(schema$5)
9619
+ resolver: zod.zodResolver(schema$4)
9609
9620
  });
9610
9621
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
9622
  const { handleSuccess } = useRouteModal();
9612
9623
  const onSubmit = form.handleSubmit(async (data) => {
9613
9624
  await mutateAsync(
9614
- { billing_address: data },
9625
+ { email: data.email },
9615
9626
  {
9616
9627
  onSuccess: () => {
9617
9628
  handleSuccess();
@@ -9628,132 +9639,18 @@ const BillingAddressForm = ({ order }) => {
9628
9639
  className: "flex flex-1 flex-col overflow-hidden",
9629
9640
  onSubmit,
9630
9641
  children: [
9631
- /* @__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: [
9632
- /* @__PURE__ */ jsxRuntime.jsx(
9633
- Form$2.Field,
9634
- {
9635
- control: form.control,
9636
- name: "country_code",
9637
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9640
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9641
- ] })
9642
- }
9643
- ),
9644
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9645
- /* @__PURE__ */ jsxRuntime.jsx(
9646
- Form$2.Field,
9647
- {
9648
- control: form.control,
9649
- name: "first_name",
9650
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9653
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9654
- ] })
9655
- }
9656
- ),
9657
- /* @__PURE__ */ jsxRuntime.jsx(
9658
- Form$2.Field,
9659
- {
9660
- control: form.control,
9661
- name: "last_name",
9662
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9665
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9666
- ] })
9667
- }
9668
- )
9669
- ] }),
9670
- /* @__PURE__ */ jsxRuntime.jsx(
9671
- Form$2.Field,
9672
- {
9673
- control: form.control,
9674
- name: "company",
9675
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9678
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9679
- ] })
9680
- }
9681
- ),
9682
- /* @__PURE__ */ jsxRuntime.jsx(
9683
- Form$2.Field,
9684
- {
9685
- control: form.control,
9686
- name: "address_1",
9687
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9690
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9691
- ] })
9692
- }
9693
- ),
9694
- /* @__PURE__ */ jsxRuntime.jsx(
9695
- Form$2.Field,
9696
- {
9697
- control: form.control,
9698
- name: "address_2",
9699
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9702
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9703
- ] })
9704
- }
9705
- ),
9706
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9707
- /* @__PURE__ */ jsxRuntime.jsx(
9708
- Form$2.Field,
9709
- {
9710
- control: form.control,
9711
- name: "postal_code",
9712
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9715
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9716
- ] })
9717
- }
9718
- ),
9719
- /* @__PURE__ */ jsxRuntime.jsx(
9720
- Form$2.Field,
9721
- {
9722
- control: form.control,
9723
- name: "city",
9724
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9727
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
- ] })
9729
- }
9730
- )
9731
- ] }),
9732
- /* @__PURE__ */ jsxRuntime.jsx(
9733
- Form$2.Field,
9734
- {
9735
- control: form.control,
9736
- name: "province",
9737
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
- ] })
9742
- }
9743
- ),
9744
- /* @__PURE__ */ jsxRuntime.jsx(
9745
- Form$2.Field,
9746
- {
9747
- control: form.control,
9748
- name: "phone",
9749
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
- ] })
9754
- }
9755
- )
9756
- ] }) }),
9642
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9643
+ Form$2.Field,
9644
+ {
9645
+ control: form.control,
9646
+ name: "email",
9647
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9651
+ ] })
9652
+ }
9653
+ ) }),
9757
9654
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
9655
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
9656
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -9762,25 +9659,6 @@ const BillingAddressForm = ({ order }) => {
9762
9659
  }
9763
9660
  ) });
9764
9661
  };
9765
- const schema$5 = addressSchema;
9766
- const CustomItems = () => {
9767
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
- ] });
9771
- };
9772
- const CustomItemsForm = () => {
9773
- const form = reactHookForm.useForm({
9774
- resolver: zod.zodResolver(schema$4)
9775
- });
9776
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
- ] }) })
9782
- ] }) });
9783
- };
9784
9662
  const schema$4 = objectType({
9785
9663
  email: stringType().email()
9786
9664
  });
@@ -11108,110 +10986,42 @@ function getHasUneditableRows(metadata) {
11108
10986
  (value) => !EDITABLE_TYPES.includes(typeof value)
11109
10987
  );
11110
10988
  }
11111
- const Email = () => {
11112
- const { id } = reactRouterDom.useParams();
11113
- const { order, isPending, isError, error } = useOrder(id, {
11114
- fields: "+email"
10989
+ const PROMOTION_QUERY_KEY = "promotions";
10990
+ const promotionsQueryKeys = {
10991
+ list: (query2) => [
10992
+ PROMOTION_QUERY_KEY,
10993
+ query2 ? query2 : void 0
10994
+ ],
10995
+ detail: (id, query2) => [
10996
+ PROMOTION_QUERY_KEY,
10997
+ id,
10998
+ query2 ? query2 : void 0
10999
+ ]
11000
+ };
11001
+ const usePromotions = (query2, options) => {
11002
+ const { data, ...rest } = reactQuery.useQuery({
11003
+ queryKey: promotionsQueryKeys.list(query2),
11004
+ queryFn: async () => sdk.admin.promotion.list(query2),
11005
+ ...options
11115
11006
  });
11116
- if (isError) {
11117
- throw error;
11007
+ return { ...data, ...rest };
11008
+ };
11009
+ const Promotions = () => {
11010
+ const { id } = reactRouterDom.useParams();
11011
+ const {
11012
+ order: preview,
11013
+ isError: isPreviewError,
11014
+ error: previewError
11015
+ } = useOrderPreview(id, void 0);
11016
+ useInitiateOrderEdit({ preview });
11017
+ const { onCancel } = useCancelOrderEdit({ preview });
11018
+ if (isPreviewError) {
11019
+ throw previewError;
11118
11020
  }
11119
- const isReady = !isPending && !!order;
11120
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11121
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11122
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
11123
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
11124
- ] }),
11125
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
11126
- ] });
11127
- };
11128
- const EmailForm = ({ order }) => {
11129
- const form = reactHookForm.useForm({
11130
- defaultValues: {
11131
- email: order.email ?? ""
11132
- },
11133
- resolver: zod.zodResolver(schema$3)
11134
- });
11135
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11136
- const { handleSuccess } = useRouteModal();
11137
- const onSubmit = form.handleSubmit(async (data) => {
11138
- await mutateAsync(
11139
- { email: data.email },
11140
- {
11141
- onSuccess: () => {
11142
- handleSuccess();
11143
- },
11144
- onError: (error) => {
11145
- ui.toast.error(error.message);
11146
- }
11147
- }
11148
- );
11149
- });
11150
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11151
- KeyboundForm,
11152
- {
11153
- className: "flex flex-1 flex-col overflow-hidden",
11154
- onSubmit,
11155
- children: [
11156
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
11157
- Form$2.Field,
11158
- {
11159
- control: form.control,
11160
- name: "email",
11161
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11162
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
11163
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11164
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
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 = objectType({
11177
- email: stringType().email()
11178
- });
11179
- const PROMOTION_QUERY_KEY = "promotions";
11180
- const promotionsQueryKeys = {
11181
- list: (query2) => [
11182
- PROMOTION_QUERY_KEY,
11183
- query2 ? query2 : void 0
11184
- ],
11185
- detail: (id, query2) => [
11186
- PROMOTION_QUERY_KEY,
11187
- id,
11188
- query2 ? query2 : void 0
11189
- ]
11190
- };
11191
- const usePromotions = (query2, options) => {
11192
- const { data, ...rest } = reactQuery.useQuery({
11193
- queryKey: promotionsQueryKeys.list(query2),
11194
- queryFn: async () => sdk.admin.promotion.list(query2),
11195
- ...options
11196
- });
11197
- return { ...data, ...rest };
11198
- };
11199
- const Promotions = () => {
11200
- const { id } = reactRouterDom.useParams();
11201
- const {
11202
- order: preview,
11203
- isError: isPreviewError,
11204
- error: previewError
11205
- } = useOrderPreview(id, void 0);
11206
- useInitiateOrderEdit({ preview });
11207
- const { onCancel } = useCancelOrderEdit({ preview });
11208
- if (isPreviewError) {
11209
- throw previewError;
11210
- }
11211
- const isReady = !!preview;
11212
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11213
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11214
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11021
+ const isReady = !!preview;
11022
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11023
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11024
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11215
11025
  ] });
11216
11026
  };
11217
11027
  const PromotionForm = ({ preview }) => {
@@ -11453,6 +11263,112 @@ function getPromotionIds(items, shippingMethods) {
11453
11263
  }
11454
11264
  return Array.from(promotionIds);
11455
11265
  }
11266
+ const SalesChannel = () => {
11267
+ const { id } = reactRouterDom.useParams();
11268
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11269
+ id,
11270
+ {
11271
+ fields: "+sales_channel_id"
11272
+ },
11273
+ {
11274
+ enabled: !!id
11275
+ }
11276
+ );
11277
+ if (isError) {
11278
+ throw error;
11279
+ }
11280
+ const ISrEADY = !!draft_order && !isPending;
11281
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11282
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11283
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11284
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11285
+ ] }),
11286
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11287
+ ] });
11288
+ };
11289
+ const SalesChannelForm = ({ order }) => {
11290
+ const form = reactHookForm.useForm({
11291
+ defaultValues: {
11292
+ sales_channel_id: order.sales_channel_id || ""
11293
+ },
11294
+ resolver: zod.zodResolver(schema$3)
11295
+ });
11296
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11297
+ const { handleSuccess } = useRouteModal();
11298
+ const onSubmit = form.handleSubmit(async (data) => {
11299
+ await mutateAsync(
11300
+ {
11301
+ sales_channel_id: data.sales_channel_id
11302
+ },
11303
+ {
11304
+ onSuccess: () => {
11305
+ ui.toast.success("Sales channel updated");
11306
+ handleSuccess();
11307
+ },
11308
+ onError: (error) => {
11309
+ ui.toast.error(error.message);
11310
+ }
11311
+ }
11312
+ );
11313
+ });
11314
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
+ KeyboundForm,
11316
+ {
11317
+ className: "flex flex-1 flex-col overflow-hidden",
11318
+ onSubmit,
11319
+ children: [
11320
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11321
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11322
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11323
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11324
+ ] }) })
11325
+ ]
11326
+ }
11327
+ ) });
11328
+ };
11329
+ const SalesChannelField = ({ control, order }) => {
11330
+ const salesChannels = useComboboxData({
11331
+ queryFn: async (params) => {
11332
+ return await sdk.admin.salesChannel.list(params);
11333
+ },
11334
+ queryKey: ["sales-channels"],
11335
+ getOptions: (data) => {
11336
+ return data.sales_channels.map((salesChannel) => ({
11337
+ label: salesChannel.name,
11338
+ value: salesChannel.id
11339
+ }));
11340
+ },
11341
+ defaultValue: order.sales_channel_id || void 0
11342
+ });
11343
+ return /* @__PURE__ */ jsxRuntime.jsx(
11344
+ Form$2.Field,
11345
+ {
11346
+ control,
11347
+ name: "sales_channel_id",
11348
+ render: ({ field }) => {
11349
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11350
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11351
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11352
+ Combobox,
11353
+ {
11354
+ options: salesChannels.options,
11355
+ fetchNextPage: salesChannels.fetchNextPage,
11356
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11357
+ searchValue: salesChannels.searchValue,
11358
+ onSearchValueChange: salesChannels.onSearchValueChange,
11359
+ placeholder: "Select sales channel",
11360
+ ...field
11361
+ }
11362
+ ) }),
11363
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11364
+ ] });
11365
+ }
11366
+ }
11367
+ );
11368
+ };
11369
+ const schema$3 = objectType({
11370
+ sales_channel_id: stringType().min(1)
11371
+ });
11456
11372
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11457
11373
  const Shipping = () => {
11458
11374
  var _a;
@@ -12260,44 +12176,60 @@ const CustomAmountField = ({
12260
12176
  }
12261
12177
  );
12262
12178
  };
12263
- const TransferOwnership = () => {
12179
+ const ShippingAddress = () => {
12264
12180
  const { id } = reactRouterDom.useParams();
12265
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12266
- fields: "id,customer_id,customer.*"
12181
+ const { order, isPending, isError, error } = useOrder(id, {
12182
+ fields: "+shipping_address"
12267
12183
  });
12268
12184
  if (isError) {
12269
12185
  throw error;
12270
12186
  }
12271
- const isReady = !isPending && !!draft_order;
12187
+ const isReady = !isPending && !!order;
12272
12188
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12273
12189
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12274
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12275
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12190
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12191
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12276
12192
  ] }),
12277
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12193
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12278
12194
  ] });
12279
12195
  };
12280
- const TransferOwnershipForm = ({ order }) => {
12281
- var _a, _b;
12196
+ const ShippingAddressForm = ({ order }) => {
12197
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12282
12198
  const form = reactHookForm.useForm({
12283
12199
  defaultValues: {
12284
- customer_id: order.customer_id || ""
12200
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12201
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12202
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12203
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12204
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12205
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12206
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12207
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12208
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12209
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12285
12210
  },
12286
12211
  resolver: zod.zodResolver(schema$2)
12287
12212
  });
12288
12213
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12289
12214
  const { handleSuccess } = useRouteModal();
12290
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12291
- const currentCustomer = order.customer ? {
12292
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12293
- value: order.customer.id
12294
- } : null;
12295
12215
  const onSubmit = form.handleSubmit(async (data) => {
12296
12216
  await mutateAsync(
12297
- { customer_id: data.customer_id },
12217
+ {
12218
+ shipping_address: {
12219
+ first_name: data.first_name,
12220
+ last_name: data.last_name,
12221
+ company: data.company,
12222
+ address_1: data.address_1,
12223
+ address_2: data.address_2,
12224
+ city: data.city,
12225
+ province: data.province,
12226
+ country_code: data.country_code,
12227
+ postal_code: data.postal_code,
12228
+ phone: data.phone
12229
+ }
12230
+ },
12298
12231
  {
12299
12232
  onSuccess: () => {
12300
- ui.toast.success("Customer updated");
12301
12233
  handleSuccess();
12302
12234
  },
12303
12235
  onError: (error) => {
@@ -12312,23 +12244,210 @@ const TransferOwnershipForm = ({ order }) => {
12312
12244
  className: "flex flex-1 flex-col overflow-hidden",
12313
12245
  onSubmit,
12314
12246
  children: [
12315
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12316
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12317
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12318
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12319
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12320
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12321
- ] }),
12322
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12323
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12324
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12325
- ] })
12326
- ] }),
12247
+ /* @__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: [
12327
12248
  /* @__PURE__ */ jsxRuntime.jsx(
12328
- CustomerField,
12249
+ Form$2.Field,
12329
12250
  {
12330
12251
  control: form.control,
12331
- currentCustomerId: order.customer_id
12252
+ name: "country_code",
12253
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12254
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12255
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12256
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12257
+ ] })
12258
+ }
12259
+ ),
12260
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12261
+ /* @__PURE__ */ jsxRuntime.jsx(
12262
+ Form$2.Field,
12263
+ {
12264
+ control: form.control,
12265
+ name: "first_name",
12266
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12267
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12268
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12269
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12270
+ ] })
12271
+ }
12272
+ ),
12273
+ /* @__PURE__ */ jsxRuntime.jsx(
12274
+ Form$2.Field,
12275
+ {
12276
+ control: form.control,
12277
+ name: "last_name",
12278
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12279
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12280
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12281
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12282
+ ] })
12283
+ }
12284
+ )
12285
+ ] }),
12286
+ /* @__PURE__ */ jsxRuntime.jsx(
12287
+ Form$2.Field,
12288
+ {
12289
+ control: form.control,
12290
+ name: "company",
12291
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12292
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12293
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12294
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12295
+ ] })
12296
+ }
12297
+ ),
12298
+ /* @__PURE__ */ jsxRuntime.jsx(
12299
+ Form$2.Field,
12300
+ {
12301
+ control: form.control,
12302
+ name: "address_1",
12303
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12304
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12305
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12306
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12307
+ ] })
12308
+ }
12309
+ ),
12310
+ /* @__PURE__ */ jsxRuntime.jsx(
12311
+ Form$2.Field,
12312
+ {
12313
+ control: form.control,
12314
+ name: "address_2",
12315
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12316
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12317
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12318
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12319
+ ] })
12320
+ }
12321
+ ),
12322
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12323
+ /* @__PURE__ */ jsxRuntime.jsx(
12324
+ Form$2.Field,
12325
+ {
12326
+ control: form.control,
12327
+ name: "postal_code",
12328
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12329
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12330
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12331
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12332
+ ] })
12333
+ }
12334
+ ),
12335
+ /* @__PURE__ */ jsxRuntime.jsx(
12336
+ Form$2.Field,
12337
+ {
12338
+ control: form.control,
12339
+ name: "city",
12340
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12341
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12342
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12343
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12344
+ ] })
12345
+ }
12346
+ )
12347
+ ] }),
12348
+ /* @__PURE__ */ jsxRuntime.jsx(
12349
+ Form$2.Field,
12350
+ {
12351
+ control: form.control,
12352
+ name: "province",
12353
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12354
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12355
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12356
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12357
+ ] })
12358
+ }
12359
+ ),
12360
+ /* @__PURE__ */ jsxRuntime.jsx(
12361
+ Form$2.Field,
12362
+ {
12363
+ control: form.control,
12364
+ name: "phone",
12365
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12367
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12368
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12369
+ ] })
12370
+ }
12371
+ )
12372
+ ] }) }),
12373
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12374
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12375
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12376
+ ] }) })
12377
+ ]
12378
+ }
12379
+ ) });
12380
+ };
12381
+ const schema$2 = addressSchema;
12382
+ const TransferOwnership = () => {
12383
+ const { id } = reactRouterDom.useParams();
12384
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12385
+ fields: "id,customer_id,customer.*"
12386
+ });
12387
+ if (isError) {
12388
+ throw error;
12389
+ }
12390
+ const isReady = !isPending && !!draft_order;
12391
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12392
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12393
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12394
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12395
+ ] }),
12396
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12397
+ ] });
12398
+ };
12399
+ const TransferOwnershipForm = ({ order }) => {
12400
+ var _a, _b;
12401
+ const form = reactHookForm.useForm({
12402
+ defaultValues: {
12403
+ customer_id: order.customer_id || ""
12404
+ },
12405
+ resolver: zod.zodResolver(schema$1)
12406
+ });
12407
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12408
+ const { handleSuccess } = useRouteModal();
12409
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12410
+ const currentCustomer = order.customer ? {
12411
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12412
+ value: order.customer.id
12413
+ } : null;
12414
+ const onSubmit = form.handleSubmit(async (data) => {
12415
+ await mutateAsync(
12416
+ { customer_id: data.customer_id },
12417
+ {
12418
+ onSuccess: () => {
12419
+ ui.toast.success("Customer updated");
12420
+ handleSuccess();
12421
+ },
12422
+ onError: (error) => {
12423
+ ui.toast.error(error.message);
12424
+ }
12425
+ }
12426
+ );
12427
+ });
12428
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12429
+ KeyboundForm,
12430
+ {
12431
+ className: "flex flex-1 flex-col overflow-hidden",
12432
+ onSubmit,
12433
+ children: [
12434
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12435
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12436
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12437
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12439
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12440
+ ] }),
12441
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12442
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12443
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12444
+ ] })
12445
+ ] }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(
12447
+ CustomerField,
12448
+ {
12449
+ control: form.control,
12450
+ currentCustomerId: order.customer_id
12332
12451
  }
12333
12452
  )
12334
12453
  ] }),
@@ -12733,119 +12852,13 @@ const Illustration = () => {
12733
12852
  }
12734
12853
  );
12735
12854
  };
12736
- const schema$2 = objectType({
12737
- customer_id: stringType().min(1)
12738
- });
12739
- const SalesChannel = () => {
12740
- const { id } = reactRouterDom.useParams();
12741
- const { draft_order, isPending, isError, error } = useDraftOrder(
12742
- id,
12743
- {
12744
- fields: "+sales_channel_id"
12745
- },
12746
- {
12747
- enabled: !!id
12748
- }
12749
- );
12750
- if (isError) {
12751
- throw error;
12752
- }
12753
- const ISrEADY = !!draft_order && !isPending;
12754
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12755
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12758
- ] }),
12759
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12760
- ] });
12761
- };
12762
- const SalesChannelForm = ({ order }) => {
12763
- const form = reactHookForm.useForm({
12764
- defaultValues: {
12765
- sales_channel_id: order.sales_channel_id || ""
12766
- },
12767
- resolver: zod.zodResolver(schema$1)
12768
- });
12769
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12770
- const { handleSuccess } = useRouteModal();
12771
- const onSubmit = form.handleSubmit(async (data) => {
12772
- await mutateAsync(
12773
- {
12774
- sales_channel_id: data.sales_channel_id
12775
- },
12776
- {
12777
- onSuccess: () => {
12778
- ui.toast.success("Sales channel updated");
12779
- handleSuccess();
12780
- },
12781
- onError: (error) => {
12782
- ui.toast.error(error.message);
12783
- }
12784
- }
12785
- );
12786
- });
12787
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12788
- KeyboundForm,
12789
- {
12790
- className: "flex flex-1 flex-col overflow-hidden",
12791
- onSubmit,
12792
- children: [
12793
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12794
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12795
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12796
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12797
- ] }) })
12798
- ]
12799
- }
12800
- ) });
12801
- };
12802
- const SalesChannelField = ({ control, order }) => {
12803
- const salesChannels = useComboboxData({
12804
- queryFn: async (params) => {
12805
- return await sdk.admin.salesChannel.list(params);
12806
- },
12807
- queryKey: ["sales-channels"],
12808
- getOptions: (data) => {
12809
- return data.sales_channels.map((salesChannel) => ({
12810
- label: salesChannel.name,
12811
- value: salesChannel.id
12812
- }));
12813
- },
12814
- defaultValue: order.sales_channel_id || void 0
12815
- });
12816
- return /* @__PURE__ */ jsxRuntime.jsx(
12817
- Form$2.Field,
12818
- {
12819
- control,
12820
- name: "sales_channel_id",
12821
- render: ({ field }) => {
12822
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12823
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12824
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12825
- Combobox,
12826
- {
12827
- options: salesChannels.options,
12828
- fetchNextPage: salesChannels.fetchNextPage,
12829
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12830
- searchValue: salesChannels.searchValue,
12831
- onSearchValueChange: salesChannels.onSearchValueChange,
12832
- placeholder: "Select sales channel",
12833
- ...field
12834
- }
12835
- ) }),
12836
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12837
- ] });
12838
- }
12839
- }
12840
- );
12841
- };
12842
12855
  const schema$1 = objectType({
12843
- sales_channel_id: stringType().min(1)
12856
+ customer_id: stringType().min(1)
12844
12857
  });
12845
- const ShippingAddress = () => {
12858
+ const BillingAddress = () => {
12846
12859
  const { id } = reactRouterDom.useParams();
12847
12860
  const { order, isPending, isError, error } = useOrder(id, {
12848
- fields: "+shipping_address"
12861
+ fields: "+billing_address"
12849
12862
  });
12850
12863
  if (isError) {
12851
12864
  throw error;
@@ -12853,26 +12866,26 @@ const ShippingAddress = () => {
12853
12866
  const isReady = !isPending && !!order;
12854
12867
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12855
12868
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12856
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12857
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12869
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12870
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12858
12871
  ] }),
12859
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12872
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12860
12873
  ] });
12861
12874
  };
12862
- const ShippingAddressForm = ({ order }) => {
12875
+ const BillingAddressForm = ({ order }) => {
12863
12876
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12864
12877
  const form = reactHookForm.useForm({
12865
12878
  defaultValues: {
12866
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12867
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12868
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12869
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12870
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12871
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12872
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12873
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12874
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12875
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12879
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12880
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12881
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12882
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12883
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12884
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12885
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12886
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12887
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12888
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12876
12889
  },
12877
12890
  resolver: zod.zodResolver(schema)
12878
12891
  });
@@ -12880,20 +12893,7 @@ const ShippingAddressForm = ({ order }) => {
12880
12893
  const { handleSuccess } = useRouteModal();
12881
12894
  const onSubmit = form.handleSubmit(async (data) => {
12882
12895
  await mutateAsync(
12883
- {
12884
- shipping_address: {
12885
- first_name: data.first_name,
12886
- last_name: data.last_name,
12887
- company: data.company,
12888
- address_1: data.address_1,
12889
- address_2: data.address_2,
12890
- city: data.city,
12891
- province: data.province,
12892
- country_code: data.country_code,
12893
- postal_code: data.postal_code,
12894
- phone: data.phone
12895
- }
12896
- },
12896
+ { billing_address: data },
12897
12897
  {
12898
12898
  onSuccess: () => {
12899
12899
  handleSuccess();
@@ -13065,14 +13065,14 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13071
- },
13072
13068
  {
13073
13069
  Component: CustomItems,
13074
13070
  path: "/draft-orders/:id/custom-items"
13075
13071
  },
13072
+ {
13073
+ Component: Email,
13074
+ path: "/draft-orders/:id/email"
13075
+ },
13076
13076
  {
13077
13077
  Component: Items,
13078
13078
  path: "/draft-orders/:id/items"
@@ -13081,29 +13081,29 @@ const routeModule = {
13081
13081
  Component: Metadata,
13082
13082
  path: "/draft-orders/:id/metadata"
13083
13083
  },
13084
- {
13085
- Component: Email,
13086
- path: "/draft-orders/:id/email"
13087
- },
13088
13084
  {
13089
13085
  Component: Promotions,
13090
13086
  path: "/draft-orders/:id/promotions"
13091
13087
  },
13088
+ {
13089
+ Component: SalesChannel,
13090
+ path: "/draft-orders/:id/sales-channel"
13091
+ },
13092
13092
  {
13093
13093
  Component: Shipping,
13094
13094
  path: "/draft-orders/:id/shipping"
13095
13095
  },
13096
13096
  {
13097
- Component: TransferOwnership,
13098
- path: "/draft-orders/:id/transfer-ownership"
13097
+ Component: ShippingAddress,
13098
+ path: "/draft-orders/:id/shipping-address"
13099
13099
  },
13100
13100
  {
13101
- Component: SalesChannel,
13102
- path: "/draft-orders/:id/sales-channel"
13101
+ Component: TransferOwnership,
13102
+ path: "/draft-orders/:id/transfer-ownership"
13103
13103
  },
13104
13104
  {
13105
- Component: ShippingAddress,
13106
- path: "/draft-orders/:id/shipping-address"
13105
+ Component: BillingAddress,
13106
+ path: "/draft-orders/:id/billing-address"
13107
13107
  }
13108
13108
  ]
13109
13109
  }