@medusajs/draft-order 2.11.4-preview-20251112180139 → 2.11.4-preview-20251113000307

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