@medusajs/draft-order 2.10.4-preview-20250925120212 → 2.10.4-preview-20250925180208

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.
@@ -9567,196 +9567,6 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const BillingAddress = () => {
9571
- const { id } = useParams();
9572
- const { order, isPending, isError, error } = useOrder(id, {
9573
- fields: "+billing_address"
9574
- });
9575
- if (isError) {
9576
- throw error;
9577
- }
9578
- const isReady = !isPending && !!order;
9579
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
- ] }),
9584
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9585
- ] });
9586
- };
9587
- const BillingAddressForm = ({ order }) => {
9588
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9589
- const form = useForm({
9590
- defaultValues: {
9591
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
- },
9602
- resolver: zodResolver(schema$5)
9603
- });
9604
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
- const { handleSuccess } = useRouteModal();
9606
- const onSubmit = form.handleSubmit(async (data) => {
9607
- await mutateAsync(
9608
- { billing_address: data },
9609
- {
9610
- onSuccess: () => {
9611
- handleSuccess();
9612
- },
9613
- onError: (error) => {
9614
- toast.error(error.message);
9615
- }
9616
- }
9617
- );
9618
- });
9619
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
- KeyboundForm,
9621
- {
9622
- className: "flex flex-1 flex-col overflow-hidden",
9623
- onSubmit,
9624
- children: [
9625
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9626
- /* @__PURE__ */ jsx(
9627
- Form$2.Field,
9628
- {
9629
- control: form.control,
9630
- name: "country_code",
9631
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
- ] })
9636
- }
9637
- ),
9638
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
- /* @__PURE__ */ jsx(
9640
- Form$2.Field,
9641
- {
9642
- control: form.control,
9643
- name: "first_name",
9644
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
- ] })
9649
- }
9650
- ),
9651
- /* @__PURE__ */ jsx(
9652
- Form$2.Field,
9653
- {
9654
- control: form.control,
9655
- name: "last_name",
9656
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
- ] })
9661
- }
9662
- )
9663
- ] }),
9664
- /* @__PURE__ */ jsx(
9665
- Form$2.Field,
9666
- {
9667
- control: form.control,
9668
- name: "company",
9669
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
- ] })
9674
- }
9675
- ),
9676
- /* @__PURE__ */ jsx(
9677
- Form$2.Field,
9678
- {
9679
- control: form.control,
9680
- name: "address_1",
9681
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
- ] })
9686
- }
9687
- ),
9688
- /* @__PURE__ */ jsx(
9689
- Form$2.Field,
9690
- {
9691
- control: form.control,
9692
- name: "address_2",
9693
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
- ] })
9698
- }
9699
- ),
9700
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
- /* @__PURE__ */ jsx(
9702
- Form$2.Field,
9703
- {
9704
- control: form.control,
9705
- name: "postal_code",
9706
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
- ] })
9711
- }
9712
- ),
9713
- /* @__PURE__ */ jsx(
9714
- Form$2.Field,
9715
- {
9716
- control: form.control,
9717
- name: "city",
9718
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
- ] })
9723
- }
9724
- )
9725
- ] }),
9726
- /* @__PURE__ */ jsx(
9727
- Form$2.Field,
9728
- {
9729
- control: form.control,
9730
- name: "province",
9731
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
- ] })
9736
- }
9737
- ),
9738
- /* @__PURE__ */ jsx(
9739
- Form$2.Field,
9740
- {
9741
- control: form.control,
9742
- name: "phone",
9743
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
- ] })
9748
- }
9749
- )
9750
- ] }) }),
9751
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
- ] }) })
9755
- ]
9756
- }
9757
- ) });
9758
- };
9759
- const schema$5 = addressSchema;
9760
9570
  const Email = () => {
9761
9571
  const { id } = useParams();
9762
9572
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9779,7 +9589,7 @@ const EmailForm = ({ order }) => {
9779
9589
  defaultValues: {
9780
9590
  email: order.email ?? ""
9781
9591
  },
9782
- resolver: zodResolver(schema$4)
9592
+ resolver: zodResolver(schema$5)
9783
9593
  });
9784
9594
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9785
9595
  const { handleSuccess } = useRouteModal();
@@ -9822,7 +9632,7 @@ const EmailForm = ({ order }) => {
9822
9632
  }
9823
9633
  ) });
9824
9634
  };
9825
- const schema$4 = objectType({
9635
+ const schema$5 = objectType({
9826
9636
  email: stringType().email()
9827
9637
  });
9828
9638
  const NumberInput = forwardRef(
@@ -11149,33 +10959,289 @@ function getHasUneditableRows(metadata) {
11149
10959
  (value) => !EDITABLE_TYPES.includes(typeof value)
11150
10960
  );
11151
10961
  }
11152
- const CustomItems = () => {
11153
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11154
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
11155
- /* @__PURE__ */ jsx(CustomItemsForm, {})
11156
- ] });
10962
+ const PROMOTION_QUERY_KEY = "promotions";
10963
+ const promotionsQueryKeys = {
10964
+ list: (query2) => [
10965
+ PROMOTION_QUERY_KEY,
10966
+ query2 ? query2 : void 0
10967
+ ],
10968
+ detail: (id, query2) => [
10969
+ PROMOTION_QUERY_KEY,
10970
+ id,
10971
+ query2 ? query2 : void 0
10972
+ ]
11157
10973
  };
11158
- const CustomItemsForm = () => {
11159
- const form = useForm({
11160
- resolver: zodResolver(schema$3)
10974
+ const usePromotions = (query2, options) => {
10975
+ const { data, ...rest } = useQuery({
10976
+ queryKey: promotionsQueryKeys.list(query2),
10977
+ queryFn: async () => sdk.admin.promotion.list(query2),
10978
+ ...options
11161
10979
  });
11162
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11163
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
11164
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11165
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11166
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
11167
- ] }) })
11168
- ] }) });
10980
+ return { ...data, ...rest };
11169
10981
  };
11170
- const schema$3 = objectType({
11171
- email: stringType().email()
11172
- });
11173
- const SalesChannel = () => {
10982
+ const Promotions = () => {
11174
10983
  const { id } = useParams();
11175
- const { draft_order, isPending, isError, error } = useDraftOrder(
11176
- id,
10984
+ const {
10985
+ order: preview,
10986
+ isError: isPreviewError,
10987
+ error: previewError
10988
+ } = useOrderPreview(id, void 0);
10989
+ useInitiateOrderEdit({ preview });
10990
+ const { onCancel } = useCancelOrderEdit({ preview });
10991
+ if (isPreviewError) {
10992
+ throw previewError;
10993
+ }
10994
+ const isReady = !!preview;
10995
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10996
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10997
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10998
+ ] });
10999
+ };
11000
+ const PromotionForm = ({ preview }) => {
11001
+ const { items, shipping_methods } = preview;
11002
+ const [isSubmitting, setIsSubmitting] = useState(false);
11003
+ const [comboboxValue, setComboboxValue] = useState("");
11004
+ const { handleSuccess } = useRouteModal();
11005
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11006
+ const promoIds = getPromotionIds(items, shipping_methods);
11007
+ const { promotions, isPending, isError, error } = usePromotions(
11177
11008
  {
11178
- fields: "+sales_channel_id"
11009
+ id: promoIds
11010
+ },
11011
+ {
11012
+ enabled: !!promoIds.length
11013
+ }
11014
+ );
11015
+ const comboboxData = useComboboxData({
11016
+ queryKey: ["promotions", "combobox", promoIds],
11017
+ queryFn: async (params) => {
11018
+ return await sdk.admin.promotion.list({
11019
+ ...params,
11020
+ id: {
11021
+ $nin: promoIds
11022
+ }
11023
+ });
11024
+ },
11025
+ getOptions: (data) => {
11026
+ return data.promotions.map((promotion) => ({
11027
+ label: promotion.code,
11028
+ value: promotion.code
11029
+ }));
11030
+ }
11031
+ });
11032
+ const add = async (value) => {
11033
+ if (!value) {
11034
+ return;
11035
+ }
11036
+ addPromotions(
11037
+ {
11038
+ promo_codes: [value]
11039
+ },
11040
+ {
11041
+ onError: (e) => {
11042
+ toast.error(e.message);
11043
+ comboboxData.onSearchValueChange("");
11044
+ setComboboxValue("");
11045
+ },
11046
+ onSuccess: () => {
11047
+ comboboxData.onSearchValueChange("");
11048
+ setComboboxValue("");
11049
+ }
11050
+ }
11051
+ );
11052
+ };
11053
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11054
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11055
+ const onSubmit = async () => {
11056
+ setIsSubmitting(true);
11057
+ let requestSucceeded = false;
11058
+ await requestOrderEdit(void 0, {
11059
+ onError: (e) => {
11060
+ toast.error(e.message);
11061
+ },
11062
+ onSuccess: () => {
11063
+ requestSucceeded = true;
11064
+ }
11065
+ });
11066
+ if (!requestSucceeded) {
11067
+ setIsSubmitting(false);
11068
+ return;
11069
+ }
11070
+ await confirmOrderEdit(void 0, {
11071
+ onError: (e) => {
11072
+ toast.error(e.message);
11073
+ },
11074
+ onSuccess: () => {
11075
+ handleSuccess();
11076
+ },
11077
+ onSettled: () => {
11078
+ setIsSubmitting(false);
11079
+ }
11080
+ });
11081
+ };
11082
+ if (isError) {
11083
+ throw error;
11084
+ }
11085
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11086
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11087
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11088
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11089
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11090
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11091
+ ] }),
11092
+ /* @__PURE__ */ jsx(
11093
+ Combobox,
11094
+ {
11095
+ id: "promotion-combobox",
11096
+ "aria-describedby": "promotion-combobox-hint",
11097
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11098
+ fetchNextPage: comboboxData.fetchNextPage,
11099
+ options: comboboxData.options,
11100
+ onSearchValueChange: comboboxData.onSearchValueChange,
11101
+ searchValue: comboboxData.searchValue,
11102
+ disabled: comboboxData.disabled || isAddingPromotions,
11103
+ onChange: add,
11104
+ value: comboboxValue
11105
+ }
11106
+ )
11107
+ ] }),
11108
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11109
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11110
+ PromotionItem,
11111
+ {
11112
+ promotion,
11113
+ orderId: preview.id,
11114
+ isLoading: isPending
11115
+ },
11116
+ promotion.id
11117
+ )) })
11118
+ ] }) }),
11119
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11120
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11121
+ /* @__PURE__ */ jsx(
11122
+ Button,
11123
+ {
11124
+ size: "small",
11125
+ type: "submit",
11126
+ isLoading: isSubmitting || isAddingPromotions,
11127
+ children: "Save"
11128
+ }
11129
+ )
11130
+ ] }) })
11131
+ ] });
11132
+ };
11133
+ const PromotionItem = ({
11134
+ promotion,
11135
+ orderId,
11136
+ isLoading
11137
+ }) => {
11138
+ var _a;
11139
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11140
+ const onRemove = async () => {
11141
+ removePromotions(
11142
+ {
11143
+ promo_codes: [promotion.code]
11144
+ },
11145
+ {
11146
+ onError: (e) => {
11147
+ toast.error(e.message);
11148
+ }
11149
+ }
11150
+ );
11151
+ };
11152
+ const displayValue = getDisplayValue(promotion);
11153
+ return /* @__PURE__ */ jsxs(
11154
+ "div",
11155
+ {
11156
+ className: clx(
11157
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11158
+ {
11159
+ "animate-pulse": isLoading
11160
+ }
11161
+ ),
11162
+ children: [
11163
+ /* @__PURE__ */ jsxs("div", { children: [
11164
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11165
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11166
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11167
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11168
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11169
+ ] }),
11170
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11171
+ ] })
11172
+ ] }),
11173
+ /* @__PURE__ */ jsx(
11174
+ IconButton,
11175
+ {
11176
+ size: "small",
11177
+ type: "button",
11178
+ variant: "transparent",
11179
+ onClick: onRemove,
11180
+ isLoading: isPending || isLoading,
11181
+ children: /* @__PURE__ */ jsx(XMark, {})
11182
+ }
11183
+ )
11184
+ ]
11185
+ },
11186
+ promotion.id
11187
+ );
11188
+ };
11189
+ function getDisplayValue(promotion) {
11190
+ var _a, _b, _c, _d;
11191
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11192
+ if (!value) {
11193
+ return null;
11194
+ }
11195
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11196
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11197
+ if (!currency) {
11198
+ return null;
11199
+ }
11200
+ return getLocaleAmount(value, currency);
11201
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11202
+ return formatPercentage(value);
11203
+ }
11204
+ return null;
11205
+ }
11206
+ const formatter = new Intl.NumberFormat([], {
11207
+ style: "percent",
11208
+ minimumFractionDigits: 2
11209
+ });
11210
+ const formatPercentage = (value, isPercentageValue = false) => {
11211
+ let val = value || 0;
11212
+ if (!isPercentageValue) {
11213
+ val = val / 100;
11214
+ }
11215
+ return formatter.format(val);
11216
+ };
11217
+ function getPromotionIds(items, shippingMethods) {
11218
+ const promotionIds = /* @__PURE__ */ new Set();
11219
+ for (const item of items) {
11220
+ if (item.adjustments) {
11221
+ for (const adjustment of item.adjustments) {
11222
+ if (adjustment.promotion_id) {
11223
+ promotionIds.add(adjustment.promotion_id);
11224
+ }
11225
+ }
11226
+ }
11227
+ }
11228
+ for (const shippingMethod of shippingMethods) {
11229
+ if (shippingMethod.adjustments) {
11230
+ for (const adjustment of shippingMethod.adjustments) {
11231
+ if (adjustment.promotion_id) {
11232
+ promotionIds.add(adjustment.promotion_id);
11233
+ }
11234
+ }
11235
+ }
11236
+ }
11237
+ return Array.from(promotionIds);
11238
+ }
11239
+ const SalesChannel = () => {
11240
+ const { id } = useParams();
11241
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11242
+ id,
11243
+ {
11244
+ fields: "+sales_channel_id"
11179
11245
  },
11180
11246
  {
11181
11247
  enabled: !!id
@@ -11198,7 +11264,7 @@ const SalesChannelForm = ({ order }) => {
11198
11264
  defaultValues: {
11199
11265
  sales_channel_id: order.sales_channel_id || ""
11200
11266
  },
11201
- resolver: zodResolver(schema$2)
11267
+ resolver: zodResolver(schema$4)
11202
11268
  });
11203
11269
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11204
11270
  const { handleSuccess } = useRouteModal();
@@ -11273,7 +11339,7 @@ const SalesChannelField = ({ control, order }) => {
11273
11339
  }
11274
11340
  );
11275
11341
  };
11276
- const schema$2 = objectType({
11342
+ const schema$4 = objectType({
11277
11343
  sales_channel_id: stringType().min(1)
11278
11344
  });
11279
11345
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12115,7 +12181,7 @@ const ShippingAddressForm = ({ order }) => {
12115
12181
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12116
12182
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12117
12183
  },
12118
- resolver: zodResolver(schema$1)
12184
+ resolver: zodResolver(schema$3)
12119
12185
  });
12120
12186
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12121
12187
  const { handleSuccess } = useRouteModal();
@@ -12285,7 +12351,7 @@ const ShippingAddressForm = ({ order }) => {
12285
12351
  }
12286
12352
  ) });
12287
12353
  };
12288
- const schema$1 = addressSchema;
12354
+ const schema$3 = addressSchema;
12289
12355
  const TransferOwnership = () => {
12290
12356
  const { id } = useParams();
12291
12357
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12309,7 +12375,7 @@ const TransferOwnershipForm = ({ order }) => {
12309
12375
  defaultValues: {
12310
12376
  customer_id: order.customer_id || ""
12311
12377
  },
12312
- resolver: zodResolver(schema)
12378
+ resolver: zodResolver(schema$2)
12313
12379
  });
12314
12380
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12315
12381
  const { handleSuccess } = useRouteModal();
@@ -12759,286 +12825,220 @@ const Illustration = () => {
12759
12825
  }
12760
12826
  );
12761
12827
  };
12762
- const schema = objectType({
12828
+ const schema$2 = objectType({
12763
12829
  customer_id: stringType().min(1)
12764
12830
  });
12765
- const PROMOTION_QUERY_KEY = "promotions";
12766
- const promotionsQueryKeys = {
12767
- list: (query2) => [
12768
- PROMOTION_QUERY_KEY,
12769
- query2 ? query2 : void 0
12770
- ],
12771
- detail: (id, query2) => [
12772
- PROMOTION_QUERY_KEY,
12773
- id,
12774
- query2 ? query2 : void 0
12775
- ]
12776
- };
12777
- const usePromotions = (query2, options) => {
12778
- const { data, ...rest } = useQuery({
12779
- queryKey: promotionsQueryKeys.list(query2),
12780
- queryFn: async () => sdk.admin.promotion.list(query2),
12781
- ...options
12782
- });
12783
- return { ...data, ...rest };
12784
- };
12785
- const Promotions = () => {
12831
+ const BillingAddress = () => {
12786
12832
  const { id } = useParams();
12787
- const {
12788
- order: preview,
12789
- isError: isPreviewError,
12790
- error: previewError
12791
- } = useOrderPreview(id, void 0);
12792
- useInitiateOrderEdit({ preview });
12793
- const { onCancel } = useCancelOrderEdit({ preview });
12794
- if (isPreviewError) {
12795
- throw previewError;
12833
+ const { order, isPending, isError, error } = useOrder(id, {
12834
+ fields: "+billing_address"
12835
+ });
12836
+ if (isError) {
12837
+ throw error;
12796
12838
  }
12797
- const isReady = !!preview;
12798
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12799
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12800
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12839
+ const isReady = !isPending && !!order;
12840
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12841
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12842
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12843
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12844
+ ] }),
12845
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12801
12846
  ] });
12802
12847
  };
12803
- const PromotionForm = ({ preview }) => {
12804
- const { items, shipping_methods } = preview;
12805
- const [isSubmitting, setIsSubmitting] = useState(false);
12806
- const [comboboxValue, setComboboxValue] = useState("");
12807
- const { handleSuccess } = useRouteModal();
12808
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12809
- const promoIds = getPromotionIds(items, shipping_methods);
12810
- const { promotions, isPending, isError, error } = usePromotions(
12811
- {
12812
- id: promoIds
12813
- },
12814
- {
12815
- enabled: !!promoIds.length
12816
- }
12817
- );
12818
- const comboboxData = useComboboxData({
12819
- queryKey: ["promotions", "combobox", promoIds],
12820
- queryFn: async (params) => {
12821
- return await sdk.admin.promotion.list({
12822
- ...params,
12823
- id: {
12824
- $nin: promoIds
12825
- }
12826
- });
12848
+ const BillingAddressForm = ({ order }) => {
12849
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12850
+ const form = useForm({
12851
+ defaultValues: {
12852
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12853
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12854
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12855
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12856
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12857
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12858
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12859
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12860
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12861
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12827
12862
  },
12828
- getOptions: (data) => {
12829
- return data.promotions.map((promotion) => ({
12830
- label: promotion.code,
12831
- value: promotion.code
12832
- }));
12833
- }
12863
+ resolver: zodResolver(schema$1)
12834
12864
  });
12835
- const add = async (value) => {
12836
- if (!value) {
12837
- return;
12838
- }
12839
- addPromotions(
12840
- {
12841
- promo_codes: [value]
12842
- },
12865
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12866
+ const { handleSuccess } = useRouteModal();
12867
+ const onSubmit = form.handleSubmit(async (data) => {
12868
+ await mutateAsync(
12869
+ { billing_address: data },
12843
12870
  {
12844
- onError: (e) => {
12845
- toast.error(e.message);
12846
- comboboxData.onSearchValueChange("");
12847
- setComboboxValue("");
12848
- },
12849
12871
  onSuccess: () => {
12850
- comboboxData.onSearchValueChange("");
12851
- setComboboxValue("");
12852
- }
12853
- }
12854
- );
12855
- };
12856
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12857
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12858
- const onSubmit = async () => {
12859
- setIsSubmitting(true);
12860
- let requestSucceeded = false;
12861
- await requestOrderEdit(void 0, {
12862
- onError: (e) => {
12863
- toast.error(e.message);
12864
- },
12865
- onSuccess: () => {
12866
- requestSucceeded = true;
12867
- }
12868
- });
12869
- if (!requestSucceeded) {
12870
- setIsSubmitting(false);
12871
- return;
12872
- }
12873
- await confirmOrderEdit(void 0, {
12874
- onError: (e) => {
12875
- toast.error(e.message);
12876
- },
12877
- onSuccess: () => {
12878
- handleSuccess();
12879
- },
12880
- onSettled: () => {
12881
- setIsSubmitting(false);
12882
- }
12883
- });
12884
- };
12885
- if (isError) {
12886
- throw error;
12887
- }
12888
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12889
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12890
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12891
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12892
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12893
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12894
- ] }),
12895
- /* @__PURE__ */ jsx(
12896
- Combobox,
12897
- {
12898
- id: "promotion-combobox",
12899
- "aria-describedby": "promotion-combobox-hint",
12900
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12901
- fetchNextPage: comboboxData.fetchNextPage,
12902
- options: comboboxData.options,
12903
- onSearchValueChange: comboboxData.onSearchValueChange,
12904
- searchValue: comboboxData.searchValue,
12905
- disabled: comboboxData.disabled || isAddingPromotions,
12906
- onChange: add,
12907
- value: comboboxValue
12908
- }
12909
- )
12910
- ] }),
12911
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12912
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12913
- PromotionItem,
12914
- {
12915
- promotion,
12916
- orderId: preview.id,
12917
- isLoading: isPending
12872
+ handleSuccess();
12918
12873
  },
12919
- promotion.id
12920
- )) })
12921
- ] }) }),
12922
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12923
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12924
- /* @__PURE__ */ jsx(
12925
- Button,
12926
- {
12927
- size: "small",
12928
- type: "submit",
12929
- isLoading: isSubmitting || isAddingPromotions,
12930
- children: "Save"
12931
- }
12932
- )
12933
- ] }) })
12934
- ] });
12935
- };
12936
- const PromotionItem = ({
12937
- promotion,
12938
- orderId,
12939
- isLoading
12940
- }) => {
12941
- var _a;
12942
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12943
- const onRemove = async () => {
12944
- removePromotions(
12945
- {
12946
- promo_codes: [promotion.code]
12947
- },
12948
- {
12949
- onError: (e) => {
12950
- toast.error(e.message);
12874
+ onError: (error) => {
12875
+ toast.error(error.message);
12951
12876
  }
12952
12877
  }
12953
12878
  );
12954
- };
12955
- const displayValue = getDisplayValue(promotion);
12956
- return /* @__PURE__ */ jsxs(
12957
- "div",
12879
+ });
12880
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12881
+ KeyboundForm,
12958
12882
  {
12959
- className: clx(
12960
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12961
- {
12962
- "animate-pulse": isLoading
12963
- }
12964
- ),
12883
+ className: "flex flex-1 flex-col overflow-hidden",
12884
+ onSubmit,
12965
12885
  children: [
12966
- /* @__PURE__ */ jsxs("div", { children: [
12967
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12968
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12969
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12970
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12971
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12972
- ] }),
12973
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12974
- ] })
12975
- ] }),
12976
- /* @__PURE__ */ jsx(
12977
- IconButton,
12978
- {
12979
- size: "small",
12980
- type: "button",
12981
- variant: "transparent",
12982
- onClick: onRemove,
12983
- isLoading: isPending || isLoading,
12984
- children: /* @__PURE__ */ jsx(XMark, {})
12985
- }
12986
- )
12886
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12887
+ /* @__PURE__ */ jsx(
12888
+ Form$2.Field,
12889
+ {
12890
+ control: form.control,
12891
+ name: "country_code",
12892
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12893
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12894
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12895
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12896
+ ] })
12897
+ }
12898
+ ),
12899
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12900
+ /* @__PURE__ */ jsx(
12901
+ Form$2.Field,
12902
+ {
12903
+ control: form.control,
12904
+ name: "first_name",
12905
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12906
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12907
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12908
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12909
+ ] })
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ Form$2.Field,
12914
+ {
12915
+ control: form.control,
12916
+ name: "last_name",
12917
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12918
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12919
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12920
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12921
+ ] })
12922
+ }
12923
+ )
12924
+ ] }),
12925
+ /* @__PURE__ */ jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "company",
12930
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12931
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12932
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12933
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12934
+ ] })
12935
+ }
12936
+ ),
12937
+ /* @__PURE__ */ jsx(
12938
+ Form$2.Field,
12939
+ {
12940
+ control: form.control,
12941
+ name: "address_1",
12942
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12943
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12944
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12945
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12946
+ ] })
12947
+ }
12948
+ ),
12949
+ /* @__PURE__ */ jsx(
12950
+ Form$2.Field,
12951
+ {
12952
+ control: form.control,
12953
+ name: "address_2",
12954
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12955
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12956
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12957
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12958
+ ] })
12959
+ }
12960
+ ),
12961
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12962
+ /* @__PURE__ */ jsx(
12963
+ Form$2.Field,
12964
+ {
12965
+ control: form.control,
12966
+ name: "postal_code",
12967
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12968
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12969
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12970
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12971
+ ] })
12972
+ }
12973
+ ),
12974
+ /* @__PURE__ */ jsx(
12975
+ Form$2.Field,
12976
+ {
12977
+ control: form.control,
12978
+ name: "city",
12979
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12980
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12981
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12982
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12983
+ ] })
12984
+ }
12985
+ )
12986
+ ] }),
12987
+ /* @__PURE__ */ jsx(
12988
+ Form$2.Field,
12989
+ {
12990
+ control: form.control,
12991
+ name: "province",
12992
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12993
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12994
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12995
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12996
+ ] })
12997
+ }
12998
+ ),
12999
+ /* @__PURE__ */ jsx(
13000
+ Form$2.Field,
13001
+ {
13002
+ control: form.control,
13003
+ name: "phone",
13004
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13005
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13006
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13007
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13008
+ ] })
13009
+ }
13010
+ )
13011
+ ] }) }),
13012
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13013
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13014
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13015
+ ] }) })
12987
13016
  ]
12988
- },
12989
- promotion.id
12990
- );
12991
- };
12992
- function getDisplayValue(promotion) {
12993
- var _a, _b, _c, _d;
12994
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12995
- if (!value) {
12996
- return null;
12997
- }
12998
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12999
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13000
- if (!currency) {
13001
- return null;
13002
13017
  }
13003
- return getLocaleAmount(value, currency);
13004
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13005
- return formatPercentage(value);
13006
- }
13007
- return null;
13008
- }
13009
- const formatter = new Intl.NumberFormat([], {
13010
- style: "percent",
13011
- minimumFractionDigits: 2
13012
- });
13013
- const formatPercentage = (value, isPercentageValue = false) => {
13014
- let val = value || 0;
13015
- if (!isPercentageValue) {
13016
- val = val / 100;
13017
- }
13018
- return formatter.format(val);
13018
+ ) });
13019
13019
  };
13020
- function getPromotionIds(items, shippingMethods) {
13021
- const promotionIds = /* @__PURE__ */ new Set();
13022
- for (const item of items) {
13023
- if (item.adjustments) {
13024
- for (const adjustment of item.adjustments) {
13025
- if (adjustment.promotion_id) {
13026
- promotionIds.add(adjustment.promotion_id);
13027
- }
13028
- }
13029
- }
13030
- }
13031
- for (const shippingMethod of shippingMethods) {
13032
- if (shippingMethod.adjustments) {
13033
- for (const adjustment of shippingMethod.adjustments) {
13034
- if (adjustment.promotion_id) {
13035
- promotionIds.add(adjustment.promotion_id);
13036
- }
13037
- }
13038
- }
13039
- }
13040
- return Array.from(promotionIds);
13041
- }
13020
+ const schema$1 = addressSchema;
13021
+ const CustomItems = () => {
13022
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
13023
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
13024
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
13025
+ ] });
13026
+ };
13027
+ const CustomItemsForm = () => {
13028
+ const form = useForm({
13029
+ resolver: zodResolver(schema)
13030
+ });
13031
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13032
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
13033
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
13036
+ ] }) })
13037
+ ] }) });
13038
+ };
13039
+ const schema = objectType({
13040
+ email: stringType().email()
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,10 +13059,6 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
- {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13065
- },
13066
13062
  {
13067
13063
  Component: Email,
13068
13064
  path: "/draft-orders/:id/email"
@@ -13076,8 +13072,8 @@ const routeModule = {
13076
13072
  path: "/draft-orders/:id/metadata"
13077
13073
  },
13078
13074
  {
13079
- Component: CustomItems,
13080
- path: "/draft-orders/:id/custom-items"
13075
+ Component: Promotions,
13076
+ path: "/draft-orders/:id/promotions"
13081
13077
  },
13082
13078
  {
13083
13079
  Component: SalesChannel,
@@ -13096,8 +13092,12 @@ const routeModule = {
13096
13092
  path: "/draft-orders/:id/transfer-ownership"
13097
13093
  },
13098
13094
  {
13099
- Component: Promotions,
13100
- path: "/draft-orders/:id/promotions"
13095
+ Component: BillingAddress,
13096
+ path: "/draft-orders/:id/billing-address"
13097
+ },
13098
+ {
13099
+ Component: CustomItems,
13100
+ path: "/draft-orders/:id/custom-items"
13101
13101
  }
13102
13102
  ]
13103
13103
  }