@medusajs/draft-order 2.11.2-preview-20251027120200 → 2.11.2-preview-20251027180157

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