@medusajs/draft-order 2.11.0-preview-20251016210154 → 2.11.0-preview-20251017031517

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