@medusajs/draft-order 2.11.2-preview-20251027150203 → 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.
@@ -11174,283 +11174,6 @@ function getHasUneditableRows(metadata) {
11174
11174
  (value) => !EDITABLE_TYPES.includes(typeof value)
11175
11175
  );
11176
11176
  }
11177
- const PROMOTION_QUERY_KEY = "promotions";
11178
- const promotionsQueryKeys = {
11179
- list: (query2) => [
11180
- PROMOTION_QUERY_KEY,
11181
- query2 ? query2 : void 0
11182
- ],
11183
- detail: (id, query2) => [
11184
- PROMOTION_QUERY_KEY,
11185
- id,
11186
- query2 ? query2 : void 0
11187
- ]
11188
- };
11189
- const usePromotions = (query2, options) => {
11190
- const { data, ...rest } = reactQuery.useQuery({
11191
- queryKey: promotionsQueryKeys.list(query2),
11192
- queryFn: async () => sdk.admin.promotion.list(query2),
11193
- ...options
11194
- });
11195
- return { ...data, ...rest };
11196
- };
11197
- const Promotions = () => {
11198
- const { id } = reactRouterDom.useParams();
11199
- const {
11200
- order: preview,
11201
- isError: isPreviewError,
11202
- error: previewError
11203
- } = useOrderPreview(id, void 0);
11204
- useInitiateOrderEdit({ preview });
11205
- const { onCancel } = useCancelOrderEdit({ preview });
11206
- if (isPreviewError) {
11207
- throw previewError;
11208
- }
11209
- const isReady = !!preview;
11210
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11211
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11212
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11213
- ] });
11214
- };
11215
- const PromotionForm = ({ preview }) => {
11216
- const { items, shipping_methods } = preview;
11217
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11218
- const [comboboxValue, setComboboxValue] = React.useState("");
11219
- const { handleSuccess } = useRouteModal();
11220
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11221
- const promoIds = getPromotionIds(items, shipping_methods);
11222
- const { promotions, isPending, isError, error } = usePromotions(
11223
- {
11224
- id: promoIds
11225
- },
11226
- {
11227
- enabled: !!promoIds.length
11228
- }
11229
- );
11230
- const comboboxData = useComboboxData({
11231
- queryKey: ["promotions", "combobox", promoIds],
11232
- queryFn: async (params) => {
11233
- return await sdk.admin.promotion.list({
11234
- ...params,
11235
- id: {
11236
- $nin: promoIds
11237
- }
11238
- });
11239
- },
11240
- getOptions: (data) => {
11241
- return data.promotions.map((promotion) => ({
11242
- label: promotion.code,
11243
- value: promotion.code
11244
- }));
11245
- }
11246
- });
11247
- const add = async (value) => {
11248
- if (!value) {
11249
- return;
11250
- }
11251
- addPromotions(
11252
- {
11253
- promo_codes: [value]
11254
- },
11255
- {
11256
- onError: (e) => {
11257
- ui.toast.error(e.message);
11258
- comboboxData.onSearchValueChange("");
11259
- setComboboxValue("");
11260
- },
11261
- onSuccess: () => {
11262
- comboboxData.onSearchValueChange("");
11263
- setComboboxValue("");
11264
- }
11265
- }
11266
- );
11267
- };
11268
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11269
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11270
- const onSubmit = async () => {
11271
- setIsSubmitting(true);
11272
- let requestSucceeded = false;
11273
- await requestOrderEdit(void 0, {
11274
- onError: (e) => {
11275
- ui.toast.error(e.message);
11276
- },
11277
- onSuccess: () => {
11278
- requestSucceeded = true;
11279
- }
11280
- });
11281
- if (!requestSucceeded) {
11282
- setIsSubmitting(false);
11283
- return;
11284
- }
11285
- await confirmOrderEdit(void 0, {
11286
- onError: (e) => {
11287
- ui.toast.error(e.message);
11288
- },
11289
- onSuccess: () => {
11290
- handleSuccess();
11291
- },
11292
- onSettled: () => {
11293
- setIsSubmitting(false);
11294
- }
11295
- });
11296
- };
11297
- if (isError) {
11298
- throw error;
11299
- }
11300
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11301
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11302
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11304
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11305
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11306
- ] }),
11307
- /* @__PURE__ */ jsxRuntime.jsx(
11308
- Combobox,
11309
- {
11310
- id: "promotion-combobox",
11311
- "aria-describedby": "promotion-combobox-hint",
11312
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11313
- fetchNextPage: comboboxData.fetchNextPage,
11314
- options: comboboxData.options,
11315
- onSearchValueChange: comboboxData.onSearchValueChange,
11316
- searchValue: comboboxData.searchValue,
11317
- disabled: comboboxData.disabled || isAddingPromotions,
11318
- onChange: add,
11319
- value: comboboxValue
11320
- }
11321
- )
11322
- ] }),
11323
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11324
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11325
- PromotionItem,
11326
- {
11327
- promotion,
11328
- orderId: preview.id,
11329
- isLoading: isPending
11330
- },
11331
- promotion.id
11332
- )) })
11333
- ] }) }),
11334
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11335
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11336
- /* @__PURE__ */ jsxRuntime.jsx(
11337
- ui.Button,
11338
- {
11339
- size: "small",
11340
- type: "submit",
11341
- isLoading: isSubmitting || isAddingPromotions,
11342
- children: "Save"
11343
- }
11344
- )
11345
- ] }) })
11346
- ] });
11347
- };
11348
- const PromotionItem = ({
11349
- promotion,
11350
- orderId,
11351
- isLoading
11352
- }) => {
11353
- var _a;
11354
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11355
- const onRemove = async () => {
11356
- removePromotions(
11357
- {
11358
- promo_codes: [promotion.code]
11359
- },
11360
- {
11361
- onError: (e) => {
11362
- ui.toast.error(e.message);
11363
- }
11364
- }
11365
- );
11366
- };
11367
- const displayValue = getDisplayValue(promotion);
11368
- return /* @__PURE__ */ jsxRuntime.jsxs(
11369
- "div",
11370
- {
11371
- className: ui.clx(
11372
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11373
- {
11374
- "animate-pulse": isLoading
11375
- }
11376
- ),
11377
- children: [
11378
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11379
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11380
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11381
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11382
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11383
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11384
- ] }),
11385
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11386
- ] })
11387
- ] }),
11388
- /* @__PURE__ */ jsxRuntime.jsx(
11389
- ui.IconButton,
11390
- {
11391
- size: "small",
11392
- type: "button",
11393
- variant: "transparent",
11394
- onClick: onRemove,
11395
- isLoading: isPending || isLoading,
11396
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11397
- }
11398
- )
11399
- ]
11400
- },
11401
- promotion.id
11402
- );
11403
- };
11404
- function getDisplayValue(promotion) {
11405
- var _a, _b, _c, _d;
11406
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11407
- if (!value) {
11408
- return null;
11409
- }
11410
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11411
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11412
- if (!currency) {
11413
- return null;
11414
- }
11415
- return getLocaleAmount(value, currency);
11416
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11417
- return formatPercentage(value);
11418
- }
11419
- return null;
11420
- }
11421
- const formatter = new Intl.NumberFormat([], {
11422
- style: "percent",
11423
- minimumFractionDigits: 2
11424
- });
11425
- const formatPercentage = (value, isPercentageValue = false) => {
11426
- let val = value || 0;
11427
- if (!isPercentageValue) {
11428
- val = val / 100;
11429
- }
11430
- return formatter.format(val);
11431
- };
11432
- function getPromotionIds(items, shippingMethods) {
11433
- const promotionIds = /* @__PURE__ */ new Set();
11434
- for (const item of items) {
11435
- if (item.adjustments) {
11436
- for (const adjustment of item.adjustments) {
11437
- if (adjustment.promotion_id) {
11438
- promotionIds.add(adjustment.promotion_id);
11439
- }
11440
- }
11441
- }
11442
- }
11443
- for (const shippingMethod of shippingMethods) {
11444
- if (shippingMethod.adjustments) {
11445
- for (const adjustment of shippingMethod.adjustments) {
11446
- if (adjustment.promotion_id) {
11447
- promotionIds.add(adjustment.promotion_id);
11448
- }
11449
- }
11450
- }
11451
- }
11452
- return Array.from(promotionIds);
11453
- }
11454
11177
  const SalesChannel = () => {
11455
11178
  const { id } = reactRouterDom.useParams();
11456
11179
  const { draft_order, isPending, isError, error } = useDraftOrder(
@@ -12963,86 +12686,363 @@ const Illustration = () => {
12963
12686
  /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12964
12687
  "path",
12965
12688
  {
12966
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12967
- stroke: "#A1A1AA",
12968
- strokeWidth: "1.5",
12969
- strokeLinecap: "round",
12970
- strokeLinejoin: "round"
12689
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12690
+ stroke: "#A1A1AA",
12691
+ strokeWidth: "1.5",
12692
+ strokeLinecap: "round",
12693
+ strokeLinejoin: "round"
12694
+ }
12695
+ ) }),
12696
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12697
+ "path",
12698
+ {
12699
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12700
+ stroke: "#A1A1AA",
12701
+ strokeWidth: "1.5",
12702
+ strokeLinecap: "round",
12703
+ strokeLinejoin: "round"
12704
+ }
12705
+ ) }),
12706
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12707
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12708
+ "rect",
12709
+ {
12710
+ width: "12",
12711
+ height: "12",
12712
+ fill: "white",
12713
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12714
+ }
12715
+ ) }),
12716
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12717
+ "rect",
12718
+ {
12719
+ width: "12",
12720
+ height: "12",
12721
+ fill: "white",
12722
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12723
+ }
12724
+ ) }),
12725
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12726
+ "rect",
12727
+ {
12728
+ width: "12",
12729
+ height: "12",
12730
+ fill: "white",
12731
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12732
+ }
12733
+ ) }),
12734
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12735
+ "rect",
12736
+ {
12737
+ width: "12",
12738
+ height: "12",
12739
+ fill: "white",
12740
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12741
+ }
12742
+ ) }),
12743
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12744
+ "rect",
12745
+ {
12746
+ width: "12",
12747
+ height: "12",
12748
+ fill: "white",
12749
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12750
+ }
12751
+ ) }),
12752
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12753
+ "rect",
12754
+ {
12755
+ width: "12",
12756
+ height: "12",
12757
+ fill: "white",
12758
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12759
+ }
12760
+ ) })
12761
+ ] })
12762
+ ]
12763
+ }
12764
+ );
12765
+ };
12766
+ const schema = objectType({
12767
+ customer_id: stringType().min(1)
12768
+ });
12769
+ const PROMOTION_QUERY_KEY = "promotions";
12770
+ const promotionsQueryKeys = {
12771
+ list: (query2) => [
12772
+ PROMOTION_QUERY_KEY,
12773
+ query2 ? query2 : void 0
12774
+ ],
12775
+ detail: (id, query2) => [
12776
+ PROMOTION_QUERY_KEY,
12777
+ id,
12778
+ query2 ? query2 : void 0
12779
+ ]
12780
+ };
12781
+ const usePromotions = (query2, options) => {
12782
+ const { data, ...rest } = reactQuery.useQuery({
12783
+ queryKey: promotionsQueryKeys.list(query2),
12784
+ queryFn: async () => sdk.admin.promotion.list(query2),
12785
+ ...options
12786
+ });
12787
+ return { ...data, ...rest };
12788
+ };
12789
+ const Promotions = () => {
12790
+ const { id } = reactRouterDom.useParams();
12791
+ const {
12792
+ order: preview,
12793
+ isError: isPreviewError,
12794
+ error: previewError
12795
+ } = useOrderPreview(id, void 0);
12796
+ useInitiateOrderEdit({ preview });
12797
+ const { onCancel } = useCancelOrderEdit({ preview });
12798
+ if (isPreviewError) {
12799
+ throw previewError;
12800
+ }
12801
+ const isReady = !!preview;
12802
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12803
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12804
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12805
+ ] });
12806
+ };
12807
+ const PromotionForm = ({ preview }) => {
12808
+ const { items, shipping_methods } = preview;
12809
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12810
+ const [comboboxValue, setComboboxValue] = React.useState("");
12811
+ const { handleSuccess } = useRouteModal();
12812
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12813
+ const promoIds = getPromotionIds(items, shipping_methods);
12814
+ const { promotions, isPending, isError, error } = usePromotions(
12815
+ {
12816
+ id: promoIds
12817
+ },
12818
+ {
12819
+ enabled: !!promoIds.length
12820
+ }
12821
+ );
12822
+ const comboboxData = useComboboxData({
12823
+ queryKey: ["promotions", "combobox", promoIds],
12824
+ queryFn: async (params) => {
12825
+ return await sdk.admin.promotion.list({
12826
+ ...params,
12827
+ id: {
12828
+ $nin: promoIds
12829
+ }
12830
+ });
12831
+ },
12832
+ getOptions: (data) => {
12833
+ return data.promotions.map((promotion) => ({
12834
+ label: promotion.code,
12835
+ value: promotion.code
12836
+ }));
12837
+ }
12838
+ });
12839
+ const add = async (value) => {
12840
+ if (!value) {
12841
+ return;
12842
+ }
12843
+ addPromotions(
12844
+ {
12845
+ promo_codes: [value]
12846
+ },
12847
+ {
12848
+ onError: (e) => {
12849
+ ui.toast.error(e.message);
12850
+ comboboxData.onSearchValueChange("");
12851
+ setComboboxValue("");
12852
+ },
12853
+ onSuccess: () => {
12854
+ comboboxData.onSearchValueChange("");
12855
+ setComboboxValue("");
12856
+ }
12857
+ }
12858
+ );
12859
+ };
12860
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12861
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12862
+ const onSubmit = async () => {
12863
+ setIsSubmitting(true);
12864
+ let requestSucceeded = false;
12865
+ await requestOrderEdit(void 0, {
12866
+ onError: (e) => {
12867
+ ui.toast.error(e.message);
12868
+ },
12869
+ onSuccess: () => {
12870
+ requestSucceeded = true;
12871
+ }
12872
+ });
12873
+ if (!requestSucceeded) {
12874
+ setIsSubmitting(false);
12875
+ return;
12876
+ }
12877
+ await confirmOrderEdit(void 0, {
12878
+ onError: (e) => {
12879
+ ui.toast.error(e.message);
12880
+ },
12881
+ onSuccess: () => {
12882
+ handleSuccess();
12883
+ },
12884
+ onSettled: () => {
12885
+ setIsSubmitting(false);
12886
+ }
12887
+ });
12888
+ };
12889
+ if (isError) {
12890
+ throw error;
12891
+ }
12892
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12893
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12894
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12895
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12896
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12897
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12898
+ ] }),
12899
+ /* @__PURE__ */ jsxRuntime.jsx(
12900
+ Combobox,
12901
+ {
12902
+ id: "promotion-combobox",
12903
+ "aria-describedby": "promotion-combobox-hint",
12904
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12905
+ fetchNextPage: comboboxData.fetchNextPage,
12906
+ options: comboboxData.options,
12907
+ onSearchValueChange: comboboxData.onSearchValueChange,
12908
+ searchValue: comboboxData.searchValue,
12909
+ disabled: comboboxData.disabled || isAddingPromotions,
12910
+ onChange: add,
12911
+ value: comboboxValue
12971
12912
  }
12972
- ) }),
12973
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12974
- "path",
12913
+ )
12914
+ ] }),
12915
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12916
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12917
+ PromotionItem,
12918
+ {
12919
+ promotion,
12920
+ orderId: preview.id,
12921
+ isLoading: isPending
12922
+ },
12923
+ promotion.id
12924
+ )) })
12925
+ ] }) }),
12926
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12927
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12928
+ /* @__PURE__ */ jsxRuntime.jsx(
12929
+ ui.Button,
12930
+ {
12931
+ size: "small",
12932
+ type: "submit",
12933
+ isLoading: isSubmitting || isAddingPromotions,
12934
+ children: "Save"
12935
+ }
12936
+ )
12937
+ ] }) })
12938
+ ] });
12939
+ };
12940
+ const PromotionItem = ({
12941
+ promotion,
12942
+ orderId,
12943
+ isLoading
12944
+ }) => {
12945
+ var _a;
12946
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12947
+ const onRemove = async () => {
12948
+ removePromotions(
12949
+ {
12950
+ promo_codes: [promotion.code]
12951
+ },
12952
+ {
12953
+ onError: (e) => {
12954
+ ui.toast.error(e.message);
12955
+ }
12956
+ }
12957
+ );
12958
+ };
12959
+ const displayValue = getDisplayValue(promotion);
12960
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12961
+ "div",
12962
+ {
12963
+ className: ui.clx(
12964
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12965
+ {
12966
+ "animate-pulse": isLoading
12967
+ }
12968
+ ),
12969
+ children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12971
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12972
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12973
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12974
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12975
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12976
+ ] }),
12977
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12978
+ ] })
12979
+ ] }),
12980
+ /* @__PURE__ */ jsxRuntime.jsx(
12981
+ ui.IconButton,
12975
12982
  {
12976
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12977
- stroke: "#A1A1AA",
12978
- strokeWidth: "1.5",
12979
- strokeLinecap: "round",
12980
- strokeLinejoin: "round"
12983
+ size: "small",
12984
+ type: "button",
12985
+ variant: "transparent",
12986
+ onClick: onRemove,
12987
+ isLoading: isPending || isLoading,
12988
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12981
12989
  }
12982
- ) }),
12983
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12984
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12985
- "rect",
12986
- {
12987
- width: "12",
12988
- height: "12",
12989
- fill: "white",
12990
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12991
- }
12992
- ) }),
12993
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12994
- "rect",
12995
- {
12996
- width: "12",
12997
- height: "12",
12998
- fill: "white",
12999
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13000
- }
13001
- ) }),
13002
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13003
- "rect",
13004
- {
13005
- width: "12",
13006
- height: "12",
13007
- fill: "white",
13008
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13009
- }
13010
- ) }),
13011
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13012
- "rect",
13013
- {
13014
- width: "12",
13015
- height: "12",
13016
- fill: "white",
13017
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13018
- }
13019
- ) }),
13020
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13021
- "rect",
13022
- {
13023
- width: "12",
13024
- height: "12",
13025
- fill: "white",
13026
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13027
- }
13028
- ) }),
13029
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13030
- "rect",
13031
- {
13032
- width: "12",
13033
- height: "12",
13034
- fill: "white",
13035
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13036
- }
13037
- ) })
13038
- ] })
12990
+ )
13039
12991
  ]
13040
- }
12992
+ },
12993
+ promotion.id
13041
12994
  );
13042
12995
  };
13043
- const schema = objectType({
13044
- customer_id: stringType().min(1)
12996
+ function getDisplayValue(promotion) {
12997
+ var _a, _b, _c, _d;
12998
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12999
+ if (!value) {
13000
+ return null;
13001
+ }
13002
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
13003
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13004
+ if (!currency) {
13005
+ return null;
13006
+ }
13007
+ return getLocaleAmount(value, currency);
13008
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13009
+ return formatPercentage(value);
13010
+ }
13011
+ return null;
13012
+ }
13013
+ const formatter = new Intl.NumberFormat([], {
13014
+ style: "percent",
13015
+ minimumFractionDigits: 2
13045
13016
  });
13017
+ const formatPercentage = (value, isPercentageValue = false) => {
13018
+ let val = value || 0;
13019
+ if (!isPercentageValue) {
13020
+ val = val / 100;
13021
+ }
13022
+ return formatter.format(val);
13023
+ };
13024
+ function getPromotionIds(items, shippingMethods) {
13025
+ const promotionIds = /* @__PURE__ */ new Set();
13026
+ for (const item of items) {
13027
+ if (item.adjustments) {
13028
+ for (const adjustment of item.adjustments) {
13029
+ if (adjustment.promotion_id) {
13030
+ promotionIds.add(adjustment.promotion_id);
13031
+ }
13032
+ }
13033
+ }
13034
+ }
13035
+ for (const shippingMethod of shippingMethods) {
13036
+ if (shippingMethod.adjustments) {
13037
+ for (const adjustment of shippingMethod.adjustments) {
13038
+ if (adjustment.promotion_id) {
13039
+ promotionIds.add(adjustment.promotion_id);
13040
+ }
13041
+ }
13042
+ }
13043
+ }
13044
+ return Array.from(promotionIds);
13045
+ }
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13083,10 +13083,6 @@ const routeModule = {
13083
13083
  Component: Metadata,
13084
13084
  path: "/draft-orders/:id/metadata"
13085
13085
  },
13086
- {
13087
- Component: Promotions,
13088
- path: "/draft-orders/:id/promotions"
13089
- },
13090
13086
  {
13091
13087
  Component: SalesChannel,
13092
13088
  path: "/draft-orders/:id/sales-channel"
@@ -13102,6 +13098,10 @@ const routeModule = {
13102
13098
  {
13103
13099
  Component: TransferOwnership,
13104
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
+ },
13102
+ {
13103
+ Component: Promotions,
13104
+ path: "/draft-orders/:id/promotions"
13105
13105
  }
13106
13106
  ]
13107
13107
  }