@medusajs/draft-order 2.10.4-preview-20251003031104 → 2.10.4-preview-20251003060157

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,217 +9573,6 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const BillingAddress = () => {
9577
- const { id } = reactRouterDom.useParams();
9578
- const { order, isPending, isError, error } = useOrder(id, {
9579
- fields: "+billing_address"
9580
- });
9581
- if (isError) {
9582
- throw error;
9583
- }
9584
- const isReady = !isPending && !!order;
9585
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
- /* @__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" }) })
9589
- ] }),
9590
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9591
- ] });
9592
- };
9593
- const BillingAddressForm = ({ order }) => {
9594
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9595
- const form = reactHookForm.useForm({
9596
- 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) ?? ""
9607
- },
9608
- resolver: zod.zodResolver(schema$5)
9609
- });
9610
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
- const { handleSuccess } = useRouteModal();
9612
- const onSubmit = form.handleSubmit(async (data) => {
9613
- await mutateAsync(
9614
- { billing_address: data },
9615
- {
9616
- onSuccess: () => {
9617
- handleSuccess();
9618
- },
9619
- onError: (error) => {
9620
- ui.toast.error(error.message);
9621
- }
9622
- }
9623
- );
9624
- });
9625
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9626
- KeyboundForm,
9627
- {
9628
- className: "flex flex-1 flex-col overflow-hidden",
9629
- onSubmit,
9630
- 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
- ] }) }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9760
- ] }) })
9761
- ]
9762
- }
9763
- ) });
9764
- };
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
- const schema$4 = objectType({
9785
- email: stringType().email()
9786
- });
9787
9576
  const Email = () => {
9788
9577
  const { id } = reactRouterDom.useParams();
9789
9578
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9806,7 +9595,7 @@ const EmailForm = ({ order }) => {
9806
9595
  defaultValues: {
9807
9596
  email: order.email ?? ""
9808
9597
  },
9809
- resolver: zod.zodResolver(schema$3)
9598
+ resolver: zod.zodResolver(schema$5)
9810
9599
  });
9811
9600
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
9601
  const { handleSuccess } = useRouteModal();
@@ -9849,7 +9638,7 @@ const EmailForm = ({ order }) => {
9849
9638
  }
9850
9639
  ) });
9851
9640
  };
9852
- const schema$3 = objectType({
9641
+ const schema$5 = objectType({
9853
9642
  email: stringType().email()
9854
9643
  });
9855
9644
  const NumberInput = React.forwardRef(
@@ -10826,6 +10615,27 @@ const customItemSchema = objectType({
10826
10615
  quantity: numberType(),
10827
10616
  unit_price: unionType([numberType(), stringType()])
10828
10617
  });
10618
+ const CustomItems = () => {
10619
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10620
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
10621
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
10622
+ ] });
10623
+ };
10624
+ const CustomItemsForm = () => {
10625
+ const form = reactHookForm.useForm({
10626
+ resolver: zod.zodResolver(schema$4)
10627
+ });
10628
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10629
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
10630
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10631
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10632
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
10633
+ ] }) })
10634
+ ] }) });
10635
+ };
10636
+ const schema$4 = objectType({
10637
+ email: stringType().email()
10638
+ });
10829
10639
  const InlineTip = React.forwardRef(
10830
10640
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10831
10641
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11176,21 +10986,298 @@ function getHasUneditableRows(metadata) {
11176
10986
  (value) => !EDITABLE_TYPES.includes(typeof value)
11177
10987
  );
11178
10988
  }
11179
- const SalesChannel = () => {
11180
- const { id } = reactRouterDom.useParams();
11181
- const { draft_order, isPending, isError, error } = useDraftOrder(
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,
11182
10997
  id,
11183
- {
11184
- fields: "+sales_channel_id"
11185
- },
11186
- {
11187
- enabled: !!id
11188
- }
11189
- );
11190
- if (isError) {
11191
- throw error;
11192
- }
11193
- const ISrEADY = !!draft_order && !isPending;
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
11006
+ });
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;
11020
+ }
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 })
11025
+ ] });
11026
+ };
11027
+ const PromotionForm = ({ preview }) => {
11028
+ const { items, shipping_methods } = preview;
11029
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11030
+ const [comboboxValue, setComboboxValue] = React.useState("");
11031
+ const { handleSuccess } = useRouteModal();
11032
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11033
+ const promoIds = getPromotionIds(items, shipping_methods);
11034
+ const { promotions, isPending, isError, error } = usePromotions(
11035
+ {
11036
+ id: promoIds
11037
+ },
11038
+ {
11039
+ enabled: !!promoIds.length
11040
+ }
11041
+ );
11042
+ const comboboxData = useComboboxData({
11043
+ queryKey: ["promotions", "combobox", promoIds],
11044
+ queryFn: async (params) => {
11045
+ return await sdk.admin.promotion.list({
11046
+ ...params,
11047
+ id: {
11048
+ $nin: promoIds
11049
+ }
11050
+ });
11051
+ },
11052
+ getOptions: (data) => {
11053
+ return data.promotions.map((promotion) => ({
11054
+ label: promotion.code,
11055
+ value: promotion.code
11056
+ }));
11057
+ }
11058
+ });
11059
+ const add = async (value) => {
11060
+ if (!value) {
11061
+ return;
11062
+ }
11063
+ addPromotions(
11064
+ {
11065
+ promo_codes: [value]
11066
+ },
11067
+ {
11068
+ onError: (e) => {
11069
+ ui.toast.error(e.message);
11070
+ comboboxData.onSearchValueChange("");
11071
+ setComboboxValue("");
11072
+ },
11073
+ onSuccess: () => {
11074
+ comboboxData.onSearchValueChange("");
11075
+ setComboboxValue("");
11076
+ }
11077
+ }
11078
+ );
11079
+ };
11080
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11081
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11082
+ const onSubmit = async () => {
11083
+ setIsSubmitting(true);
11084
+ let requestSucceeded = false;
11085
+ await requestOrderEdit(void 0, {
11086
+ onError: (e) => {
11087
+ ui.toast.error(e.message);
11088
+ },
11089
+ onSuccess: () => {
11090
+ requestSucceeded = true;
11091
+ }
11092
+ });
11093
+ if (!requestSucceeded) {
11094
+ setIsSubmitting(false);
11095
+ return;
11096
+ }
11097
+ await confirmOrderEdit(void 0, {
11098
+ onError: (e) => {
11099
+ ui.toast.error(e.message);
11100
+ },
11101
+ onSuccess: () => {
11102
+ handleSuccess();
11103
+ },
11104
+ onSettled: () => {
11105
+ setIsSubmitting(false);
11106
+ }
11107
+ });
11108
+ };
11109
+ if (isError) {
11110
+ throw error;
11111
+ }
11112
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11113
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11114
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11115
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11116
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11117
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11118
+ ] }),
11119
+ /* @__PURE__ */ jsxRuntime.jsx(
11120
+ Combobox,
11121
+ {
11122
+ id: "promotion-combobox",
11123
+ "aria-describedby": "promotion-combobox-hint",
11124
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11125
+ fetchNextPage: comboboxData.fetchNextPage,
11126
+ options: comboboxData.options,
11127
+ onSearchValueChange: comboboxData.onSearchValueChange,
11128
+ searchValue: comboboxData.searchValue,
11129
+ disabled: comboboxData.disabled || isAddingPromotions,
11130
+ onChange: add,
11131
+ value: comboboxValue
11132
+ }
11133
+ )
11134
+ ] }),
11135
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11136
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11137
+ PromotionItem,
11138
+ {
11139
+ promotion,
11140
+ orderId: preview.id,
11141
+ isLoading: isPending
11142
+ },
11143
+ promotion.id
11144
+ )) })
11145
+ ] }) }),
11146
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11147
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11148
+ /* @__PURE__ */ jsxRuntime.jsx(
11149
+ ui.Button,
11150
+ {
11151
+ size: "small",
11152
+ type: "submit",
11153
+ isLoading: isSubmitting || isAddingPromotions,
11154
+ children: "Save"
11155
+ }
11156
+ )
11157
+ ] }) })
11158
+ ] });
11159
+ };
11160
+ const PromotionItem = ({
11161
+ promotion,
11162
+ orderId,
11163
+ isLoading
11164
+ }) => {
11165
+ var _a;
11166
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11167
+ const onRemove = async () => {
11168
+ removePromotions(
11169
+ {
11170
+ promo_codes: [promotion.code]
11171
+ },
11172
+ {
11173
+ onError: (e) => {
11174
+ ui.toast.error(e.message);
11175
+ }
11176
+ }
11177
+ );
11178
+ };
11179
+ const displayValue = getDisplayValue(promotion);
11180
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11181
+ "div",
11182
+ {
11183
+ className: ui.clx(
11184
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11185
+ {
11186
+ "animate-pulse": isLoading
11187
+ }
11188
+ ),
11189
+ children: [
11190
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11191
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11192
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11193
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11194
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11195
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11196
+ ] }),
11197
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11198
+ ] })
11199
+ ] }),
11200
+ /* @__PURE__ */ jsxRuntime.jsx(
11201
+ ui.IconButton,
11202
+ {
11203
+ size: "small",
11204
+ type: "button",
11205
+ variant: "transparent",
11206
+ onClick: onRemove,
11207
+ isLoading: isPending || isLoading,
11208
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11209
+ }
11210
+ )
11211
+ ]
11212
+ },
11213
+ promotion.id
11214
+ );
11215
+ };
11216
+ function getDisplayValue(promotion) {
11217
+ var _a, _b, _c, _d;
11218
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11219
+ if (!value) {
11220
+ return null;
11221
+ }
11222
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11223
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11224
+ if (!currency) {
11225
+ return null;
11226
+ }
11227
+ return getLocaleAmount(value, currency);
11228
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11229
+ return formatPercentage(value);
11230
+ }
11231
+ return null;
11232
+ }
11233
+ const formatter = new Intl.NumberFormat([], {
11234
+ style: "percent",
11235
+ minimumFractionDigits: 2
11236
+ });
11237
+ const formatPercentage = (value, isPercentageValue = false) => {
11238
+ let val = value || 0;
11239
+ if (!isPercentageValue) {
11240
+ val = val / 100;
11241
+ }
11242
+ return formatter.format(val);
11243
+ };
11244
+ function getPromotionIds(items, shippingMethods) {
11245
+ const promotionIds = /* @__PURE__ */ new Set();
11246
+ for (const item of items) {
11247
+ if (item.adjustments) {
11248
+ for (const adjustment of item.adjustments) {
11249
+ if (adjustment.promotion_id) {
11250
+ promotionIds.add(adjustment.promotion_id);
11251
+ }
11252
+ }
11253
+ }
11254
+ }
11255
+ for (const shippingMethod of shippingMethods) {
11256
+ if (shippingMethod.adjustments) {
11257
+ for (const adjustment of shippingMethod.adjustments) {
11258
+ if (adjustment.promotion_id) {
11259
+ promotionIds.add(adjustment.promotion_id);
11260
+ }
11261
+ }
11262
+ }
11263
+ }
11264
+ return Array.from(promotionIds);
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;
11194
11281
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11195
11282
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11196
11283
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
@@ -11204,7 +11291,7 @@ const SalesChannelForm = ({ order }) => {
11204
11291
  defaultValues: {
11205
11292
  sales_channel_id: order.sales_channel_id || ""
11206
11293
  },
11207
- resolver: zod.zodResolver(schema$2)
11294
+ resolver: zod.zodResolver(schema$3)
11208
11295
  });
11209
11296
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11210
11297
  const { handleSuccess } = useRouteModal();
@@ -11279,7 +11366,7 @@ const SalesChannelField = ({ control, order }) => {
11279
11366
  }
11280
11367
  );
11281
11368
  };
11282
- const schema$2 = objectType({
11369
+ const schema$3 = objectType({
11283
11370
  sales_channel_id: stringType().min(1)
11284
11371
  });
11285
11372
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12121,7 +12208,7 @@ const ShippingAddressForm = ({ order }) => {
12121
12208
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12122
12209
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12123
12210
  },
12124
- resolver: zod.zodResolver(schema$1)
12211
+ resolver: zod.zodResolver(schema$2)
12125
12212
  });
12126
12213
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12127
12214
  const { handleSuccess } = useRouteModal();
@@ -12291,7 +12378,7 @@ const ShippingAddressForm = ({ order }) => {
12291
12378
  }
12292
12379
  ) });
12293
12380
  };
12294
- const schema$1 = addressSchema;
12381
+ const schema$2 = addressSchema;
12295
12382
  const TransferOwnership = () => {
12296
12383
  const { id } = reactRouterDom.useParams();
12297
12384
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12315,7 +12402,7 @@ const TransferOwnershipForm = ({ order }) => {
12315
12402
  defaultValues: {
12316
12403
  customer_id: order.customer_id || ""
12317
12404
  },
12318
- resolver: zod.zodResolver(schema)
12405
+ resolver: zod.zodResolver(schema$1)
12319
12406
  });
12320
12407
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12321
12408
  const { handleSuccess } = useRouteModal();
@@ -12757,294 +12844,207 @@ const Illustration = () => {
12757
12844
  width: "12",
12758
12845
  height: "12",
12759
12846
  fill: "white",
12760
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12761
- }
12762
- ) })
12763
- ] })
12764
- ]
12765
- }
12766
- );
12767
- };
12768
- const schema = objectType({
12769
- customer_id: stringType().min(1)
12770
- });
12771
- const PROMOTION_QUERY_KEY = "promotions";
12772
- const promotionsQueryKeys = {
12773
- list: (query2) => [
12774
- PROMOTION_QUERY_KEY,
12775
- query2 ? query2 : void 0
12776
- ],
12777
- detail: (id, query2) => [
12778
- PROMOTION_QUERY_KEY,
12779
- id,
12780
- query2 ? query2 : void 0
12781
- ]
12782
- };
12783
- const usePromotions = (query2, options) => {
12784
- const { data, ...rest } = reactQuery.useQuery({
12785
- queryKey: promotionsQueryKeys.list(query2),
12786
- queryFn: async () => sdk.admin.promotion.list(query2),
12787
- ...options
12788
- });
12789
- return { ...data, ...rest };
12790
- };
12791
- const Promotions = () => {
12792
- const { id } = reactRouterDom.useParams();
12793
- const {
12794
- order: preview,
12795
- isError: isPreviewError,
12796
- error: previewError
12797
- } = useOrderPreview(id, void 0);
12798
- useInitiateOrderEdit({ preview });
12799
- const { onCancel } = useCancelOrderEdit({ preview });
12800
- if (isPreviewError) {
12801
- throw previewError;
12802
- }
12803
- const isReady = !!preview;
12804
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12805
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12806
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12807
- ] });
12808
- };
12809
- const PromotionForm = ({ preview }) => {
12810
- const { items, shipping_methods } = preview;
12811
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12812
- const [comboboxValue, setComboboxValue] = React.useState("");
12813
- const { handleSuccess } = useRouteModal();
12814
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12815
- const promoIds = getPromotionIds(items, shipping_methods);
12816
- const { promotions, isPending, isError, error } = usePromotions(
12817
- {
12818
- id: promoIds
12819
- },
12820
- {
12821
- enabled: !!promoIds.length
12822
- }
12823
- );
12824
- const comboboxData = useComboboxData({
12825
- queryKey: ["promotions", "combobox", promoIds],
12826
- queryFn: async (params) => {
12827
- return await sdk.admin.promotion.list({
12828
- ...params,
12829
- id: {
12830
- $nin: promoIds
12831
- }
12832
- });
12833
- },
12834
- getOptions: (data) => {
12835
- return data.promotions.map((promotion) => ({
12836
- label: promotion.code,
12837
- value: promotion.code
12838
- }));
12839
- }
12840
- });
12841
- const add = async (value) => {
12842
- if (!value) {
12843
- return;
12844
- }
12845
- addPromotions(
12846
- {
12847
- promo_codes: [value]
12848
- },
12849
- {
12850
- onError: (e) => {
12851
- ui.toast.error(e.message);
12852
- comboboxData.onSearchValueChange("");
12853
- setComboboxValue("");
12854
- },
12855
- onSuccess: () => {
12856
- comboboxData.onSearchValueChange("");
12857
- setComboboxValue("");
12858
- }
12859
- }
12860
- );
12861
- };
12862
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12863
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12864
- const onSubmit = async () => {
12865
- setIsSubmitting(true);
12866
- let requestSucceeded = false;
12867
- await requestOrderEdit(void 0, {
12868
- onError: (e) => {
12869
- ui.toast.error(e.message);
12870
- },
12871
- onSuccess: () => {
12872
- requestSucceeded = true;
12873
- }
12874
- });
12875
- if (!requestSucceeded) {
12876
- setIsSubmitting(false);
12877
- return;
12878
- }
12879
- await confirmOrderEdit(void 0, {
12880
- onError: (e) => {
12881
- ui.toast.error(e.message);
12882
- },
12883
- onSuccess: () => {
12884
- handleSuccess();
12885
- },
12886
- onSettled: () => {
12887
- setIsSubmitting(false);
12888
- }
12889
- });
12890
- };
12891
- if (isError) {
12892
- throw error;
12893
- }
12894
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12895
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12896
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12897
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12898
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12899
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12900
- ] }),
12901
- /* @__PURE__ */ jsxRuntime.jsx(
12902
- Combobox,
12903
- {
12904
- id: "promotion-combobox",
12905
- "aria-describedby": "promotion-combobox-hint",
12906
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12907
- fetchNextPage: comboboxData.fetchNextPage,
12908
- options: comboboxData.options,
12909
- onSearchValueChange: comboboxData.onSearchValueChange,
12910
- searchValue: comboboxData.searchValue,
12911
- disabled: comboboxData.disabled || isAddingPromotions,
12912
- onChange: add,
12913
- value: comboboxValue
12914
- }
12915
- )
12916
- ] }),
12917
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12918
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12919
- PromotionItem,
12920
- {
12921
- promotion,
12922
- orderId: preview.id,
12923
- isLoading: isPending
12924
- },
12925
- promotion.id
12926
- )) })
12927
- ] }) }),
12928
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12929
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12930
- /* @__PURE__ */ jsxRuntime.jsx(
12931
- ui.Button,
12932
- {
12933
- size: "small",
12934
- type: "submit",
12935
- isLoading: isSubmitting || isAddingPromotions,
12936
- children: "Save"
12937
- }
12938
- )
12939
- ] }) })
12940
- ] });
12941
- };
12942
- const PromotionItem = ({
12943
- promotion,
12944
- orderId,
12945
- isLoading
12946
- }) => {
12947
- var _a;
12948
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12949
- const onRemove = async () => {
12950
- removePromotions(
12951
- {
12952
- promo_codes: [promotion.code]
12953
- },
12954
- {
12955
- onError: (e) => {
12956
- ui.toast.error(e.message);
12957
- }
12958
- }
12959
- );
12960
- };
12961
- const displayValue = getDisplayValue(promotion);
12962
- return /* @__PURE__ */ jsxRuntime.jsxs(
12963
- "div",
12964
- {
12965
- className: ui.clx(
12966
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12967
- {
12968
- "animate-pulse": isLoading
12969
- }
12970
- ),
12971
- children: [
12972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12973
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12974
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12975
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12976
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12978
- ] }),
12979
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12980
- ] })
12981
- ] }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(
12983
- ui.IconButton,
12984
- {
12985
- size: "small",
12986
- type: "button",
12987
- variant: "transparent",
12988
- onClick: onRemove,
12989
- isLoading: isPending || isLoading,
12990
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12991
- }
12992
- )
12847
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12848
+ }
12849
+ ) })
12850
+ ] })
12993
12851
  ]
12994
- },
12995
- promotion.id
12852
+ }
12996
12853
  );
12997
12854
  };
12998
- function getDisplayValue(promotion) {
12999
- var _a, _b, _c, _d;
13000
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
13001
- if (!value) {
13002
- return null;
13003
- }
13004
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
13005
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13006
- if (!currency) {
13007
- return null;
13008
- }
13009
- return getLocaleAmount(value, currency);
13010
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13011
- return formatPercentage(value);
13012
- }
13013
- return null;
13014
- }
13015
- const formatter = new Intl.NumberFormat([], {
13016
- style: "percent",
13017
- minimumFractionDigits: 2
12855
+ const schema$1 = objectType({
12856
+ customer_id: stringType().min(1)
13018
12857
  });
13019
- const formatPercentage = (value, isPercentageValue = false) => {
13020
- let val = value || 0;
13021
- if (!isPercentageValue) {
13022
- val = val / 100;
12858
+ const BillingAddress = () => {
12859
+ const { id } = reactRouterDom.useParams();
12860
+ const { order, isPending, isError, error } = useOrder(id, {
12861
+ fields: "+billing_address"
12862
+ });
12863
+ if (isError) {
12864
+ throw error;
13023
12865
  }
13024
- return formatter.format(val);
12866
+ const isReady = !isPending && !!order;
12867
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12868
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
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" }) })
12871
+ ] }),
12872
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12873
+ ] });
13025
12874
  };
13026
- function getPromotionIds(items, shippingMethods) {
13027
- const promotionIds = /* @__PURE__ */ new Set();
13028
- for (const item of items) {
13029
- if (item.adjustments) {
13030
- for (const adjustment of item.adjustments) {
13031
- if (adjustment.promotion_id) {
13032
- promotionIds.add(adjustment.promotion_id);
13033
- }
13034
- }
13035
- }
13036
- }
13037
- for (const shippingMethod of shippingMethods) {
13038
- if (shippingMethod.adjustments) {
13039
- for (const adjustment of shippingMethod.adjustments) {
13040
- if (adjustment.promotion_id) {
13041
- promotionIds.add(adjustment.promotion_id);
12875
+ const BillingAddressForm = ({ order }) => {
12876
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12877
+ const form = reactHookForm.useForm({
12878
+ defaultValues: {
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) ?? ""
12889
+ },
12890
+ resolver: zod.zodResolver(schema)
12891
+ });
12892
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12893
+ const { handleSuccess } = useRouteModal();
12894
+ const onSubmit = form.handleSubmit(async (data) => {
12895
+ await mutateAsync(
12896
+ { billing_address: data },
12897
+ {
12898
+ onSuccess: () => {
12899
+ handleSuccess();
12900
+ },
12901
+ onError: (error) => {
12902
+ ui.toast.error(error.message);
13042
12903
  }
13043
12904
  }
12905
+ );
12906
+ });
12907
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12908
+ KeyboundForm,
12909
+ {
12910
+ className: "flex flex-1 flex-col overflow-hidden",
12911
+ onSubmit,
12912
+ children: [
12913
+ /* @__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: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "country_code",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12927
+ /* @__PURE__ */ jsxRuntime.jsx(
12928
+ Form$2.Field,
12929
+ {
12930
+ control: form.control,
12931
+ name: "first_name",
12932
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12935
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12936
+ ] })
12937
+ }
12938
+ ),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(
12940
+ Form$2.Field,
12941
+ {
12942
+ control: form.control,
12943
+ name: "last_name",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12949
+ }
12950
+ )
12951
+ ] }),
12952
+ /* @__PURE__ */ jsxRuntime.jsx(
12953
+ Form$2.Field,
12954
+ {
12955
+ control: form.control,
12956
+ name: "company",
12957
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12960
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12961
+ ] })
12962
+ }
12963
+ ),
12964
+ /* @__PURE__ */ jsxRuntime.jsx(
12965
+ Form$2.Field,
12966
+ {
12967
+ control: form.control,
12968
+ name: "address_1",
12969
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12973
+ ] })
12974
+ }
12975
+ ),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "address_2",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12989
+ /* @__PURE__ */ jsxRuntime.jsx(
12990
+ Form$2.Field,
12991
+ {
12992
+ control: form.control,
12993
+ name: "postal_code",
12994
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12998
+ ] })
12999
+ }
13000
+ ),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13003
+ {
13004
+ control: form.control,
13005
+ name: "city",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13011
+ }
13012
+ )
13013
+ ] }),
13014
+ /* @__PURE__ */ jsxRuntime.jsx(
13015
+ Form$2.Field,
13016
+ {
13017
+ control: form.control,
13018
+ name: "province",
13019
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13022
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13023
+ ] })
13024
+ }
13025
+ ),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(
13027
+ Form$2.Field,
13028
+ {
13029
+ control: form.control,
13030
+ name: "phone",
13031
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13035
+ ] })
13036
+ }
13037
+ )
13038
+ ] }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13042
+ ] }) })
13043
+ ]
13044
13044
  }
13045
- }
13046
- return Array.from(promotionIds);
13047
- }
13045
+ ) });
13046
+ };
13047
+ const schema = addressSchema;
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,14 +13065,6 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13071
- },
13072
- {
13073
- Component: CustomItems,
13074
- path: "/draft-orders/:id/custom-items"
13075
- },
13076
13068
  {
13077
13069
  Component: Email,
13078
13070
  path: "/draft-orders/:id/email"
@@ -13081,10 +13073,18 @@ const routeModule = {
13081
13073
  Component: Items,
13082
13074
  path: "/draft-orders/:id/items"
13083
13075
  },
13076
+ {
13077
+ Component: CustomItems,
13078
+ path: "/draft-orders/:id/custom-items"
13079
+ },
13084
13080
  {
13085
13081
  Component: Metadata,
13086
13082
  path: "/draft-orders/:id/metadata"
13087
13083
  },
13084
+ {
13085
+ Component: Promotions,
13086
+ path: "/draft-orders/:id/promotions"
13087
+ },
13088
13088
  {
13089
13089
  Component: SalesChannel,
13090
13090
  path: "/draft-orders/:id/sales-channel"
@@ -13102,8 +13102,8 @@ const routeModule = {
13102
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
13103
  },
13104
13104
  {
13105
- Component: Promotions,
13106
- path: "/draft-orders/:id/promotions"
13105
+ Component: BillingAddress,
13106
+ path: "/draft-orders/:id/billing-address"
13107
13107
  }
13108
13108
  ]
13109
13109
  }