@mercurjs/admin 2.0.0-canary.39 → 2.0.0-canary.41
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.
- package/dist/{add-campaign-promotions-ZUXBF5G3.js → add-campaign-promotions-7TPECJOT.js} +4 -4
- package/dist/{api-key-management-detail-SKJNAZ5L.js → api-key-management-detail-2EFDWJSF.js} +7 -7
- package/dist/{api-key-management-list-2D4WKI6Y.js → api-key-management-list-UZLHSM2R.js} +6 -5
- package/dist/{api-key-management-sales-channels-C7EWPHC2.js → api-key-management-sales-channels-ER5ZINL7.js} +6 -7
- package/dist/{campaign-create-B7XM2FZM.js → campaign-create-AFR3V7P4.js} +3 -3
- package/dist/{campaign-detail-7U4CQHU5.js → campaign-detail-UUNEZUY7.js} +9 -8
- package/dist/{campaign-list-SC7FLTRM.js → campaign-list-2AAGWYEG.js} +6 -5
- package/dist/category-create-LY45Z7YB.js +23 -0
- package/dist/{category-detail-HGHR3R2R.js → category-detail-AGTIMI6P.js} +7 -6
- package/dist/{category-list-QBBFGHQM.js → category-list-ROM7UTA4.js} +6 -5
- package/dist/{chunk-ENMRRG4N.js → chunk-2AWQ4FPA.js} +6 -6
- package/dist/{chunk-VBAAYYCS.js → chunk-2HPZJCAF.js} +6 -6
- package/dist/{chunk-SFG7JTBH.js → chunk-2LAANNMF.js} +111 -48
- package/dist/{chunk-KYUXTS2L.js → chunk-2UN7CNBG.js} +7 -7
- package/dist/chunk-3LTXCGNM.js +204 -0
- package/dist/{chunk-EDQBUWY7.js → chunk-3NIWL75F.js} +6 -6
- package/dist/{product-create-variant-CJPECBV4.js → chunk-4UTK7DZN.js} +63 -69
- package/dist/{chunk-5VEYNZSW.js → chunk-5322X23U.js} +9 -4
- package/dist/{chunk-U3SFHLUA.js → chunk-53IISBJZ.js} +1 -0
- package/dist/{chunk-DGCPYCHU.js → chunk-54RTJBYO.js} +63 -8
- package/dist/{chunk-E2AAYIHS.js → chunk-5EFOVNK2.js} +3 -3
- package/dist/{chunk-NQPAEBSZ.js → chunk-6E3T6CGY.js} +15 -7
- package/dist/{chunk-V2DXJ75C.js → chunk-6OA7JZ5E.js} +1 -1
- package/dist/chunk-72IQIAGX.js +245 -0
- package/dist/{chunk-3IYIS5UZ.js → chunk-7DOPC5GY.js} +4 -4
- package/dist/{chunk-Q6XCCONH.js → chunk-AI6RJGRQ.js} +9 -9
- package/dist/{price-list-create-OK7YYLAB.js → chunk-AJZQBGE4.js} +193 -428
- package/dist/{chunk-XDVS4B7W.js → chunk-BAV6Y7RC.js} +8 -7
- package/dist/{chunk-4WYBW3HK.js → chunk-BCAT7P6B.js} +3 -3
- package/dist/{chunk-LYT3RI4O.js → chunk-BHYDGWZ6.js} +18 -9
- package/dist/{chunk-DK3U2SRA.js → chunk-BIEYPCHL.js} +5 -5
- package/dist/{product-create-NVBKO426.js → chunk-BLG726FI.js} +36 -68
- package/dist/chunk-BVRI7YAR.js +100 -0
- package/dist/{chunk-2IGCU3KP.js → chunk-DOMRLXOI.js} +2 -2
- package/dist/{chunk-K6FXWZ2M.js → chunk-F55UXYYA.js} +10 -0
- package/dist/{chunk-AOVEX4EM.js → chunk-FNXSMFGL.js} +5 -5
- package/dist/{chunk-IXGP2EEN.js → chunk-FYAYHOCN.js} +2 -3
- package/dist/{chunk-QBOXELB5.js → chunk-GJHAVFXL.js} +4 -4
- package/dist/{price-list-prices-add-7PGUONDK.js → chunk-GOVOSXUU.js} +90 -290
- package/dist/{chunk-66IHH2HG.js → chunk-H6W6Q6YE.js} +3 -3
- package/dist/{seller-details-KROISMQC.js → chunk-HVLQFQGD.js} +74 -146
- package/dist/{chunk-QD6KYDYH.js → chunk-I6R4I7EF.js} +6 -6
- package/dist/{chunk-RIMR3ULR.js → chunk-ISYWL6RZ.js} +64 -33
- package/dist/{chunk-HHNJNKCB.js → chunk-KMUEJ3IE.js} +59 -20
- package/dist/{chunk-GJTIHFXG.js → chunk-KOILMFJX.js} +29 -31
- package/dist/{chunk-3SAH3NUS.js → chunk-LIXRNUG5.js} +1 -1
- package/dist/chunk-LOJD5572.js +433 -0
- package/dist/{chunk-T25UE7SS.js → chunk-MD56QRKC.js} +6 -6
- package/dist/{chunk-S4QUEQQK.js → chunk-MSFNMGFD.js} +48 -48
- package/dist/{chunk-YH4VQBAA.js → chunk-MX52GGQO.js} +81 -52
- package/dist/{chunk-O6O22BN4.js → chunk-N7BCAAJC.js} +113 -48
- package/dist/{chunk-JA2XIIIZ.js → chunk-NXKCVD5F.js} +6 -5
- package/dist/{chunk-G4QMLQF2.js → chunk-NZN7PFPB.js} +2 -4
- package/dist/{chunk-KUDLPUWR.js → chunk-OFWYMU6K.js} +8 -8
- package/dist/chunk-OOAY7PAK.js +1155 -0
- package/dist/chunk-PAQH5QQH.js +685 -0
- package/dist/{chunk-3H74EI2D.js → chunk-POCHIWE2.js} +100 -40
- package/dist/chunk-PXBCTPQO.js +248 -0
- package/dist/chunk-QSZ2FIM2.js +223 -0
- package/dist/{chunk-23663A2W.js → chunk-R5VKVG6S.js} +1 -1
- package/dist/{chunk-DP5U3GQU.js → chunk-RXUUBJSZ.js} +1 -1
- package/dist/{chunk-FYB5MS4F.js → chunk-S2GARTQU.js} +6 -6
- package/dist/{chunk-7TLEUIAL.js → chunk-SO6PXIPV.js} +21 -16
- package/dist/{category-create-UWBJGIED.js → chunk-ST74PSEZ.js} +78 -149
- package/dist/{chunk-33FUPXJL.js → chunk-T3OYE2MH.js} +4 -4
- package/dist/{chunk-JRWB7VWP.js → chunk-U4RMXPGI.js} +8 -8
- package/dist/{chunk-YGSM5PVN.js → chunk-UI2BJVP5.js} +1 -1
- package/dist/{chunk-FXU7SL6M.js → chunk-UOIUQC3P.js} +25 -15
- package/dist/{chunk-ZU2RNSCP.js → chunk-UONTDHRH.js} +4 -2
- package/dist/{chunk-J7SR4GW5.js → chunk-V3SHSLK4.js} +4 -4
- package/dist/{chunk-TE5VQBCL.js → chunk-V42ZR4XW.js} +8 -9
- package/dist/chunk-V5J73NPW.js +117 -0
- package/dist/{chunk-QP6XXG6A.js → chunk-VOFAM7HJ.js} +74 -42
- package/dist/{chunk-CR4E2DCR.js → chunk-VT3RBTYK.js} +3 -3
- package/dist/{chunk-AOVJTW7M.js → chunk-VWQYMOBM.js} +9 -9
- package/dist/{chunk-6L2LSIPR.js → chunk-VXAQZ2ZZ.js} +4 -4
- package/dist/{chunk-OSHCUDYY.js → chunk-X3KBQBGW.js} +6 -6
- package/dist/{chunk-WZADCDDE.js → chunk-X56THFPA.js} +2 -1
- package/dist/{chunk-HZKW7HRU.js → chunk-X7NWBH7T.js} +64 -35
- package/dist/{chunk-OFRQZHVQ.js → chunk-XE5ZMNUN.js} +6 -6
- package/dist/{chunk-4GVHNYZR.js → chunk-XHVYNMTA.js} +2 -2
- package/dist/{chunk-U2UCL2VG.js → chunk-XIZLPYEE.js} +3 -111
- package/dist/{chunk-KXPCEVFB.js → chunk-XOKRMMVP.js} +6 -6
- package/dist/{chunk-XVKRTPVM.js → chunk-Y5N26ZC3.js} +41 -15
- package/dist/{chunk-A6Z2Q7D5.js → chunk-Z2MDPTF2.js} +4 -2
- package/dist/{chunk-TKGZBTOS.js → chunk-ZFSZTRZ6.js} +54 -32
- package/dist/{chunk-RV6NZTNP.js → chunk-ZZEAWVFX.js} +27 -27
- package/dist/{collection-detail-YJ3FV2C6.js → collection-detail-SRR3HSIV.js} +7 -6
- package/dist/{collection-list-WDQOBHQN.js → collection-list-MKISW5S4.js} +6 -5
- package/dist/{commission-rate-detail-UQDIIMIK.js → commission-rate-detail-GLB733F3.js} +5 -4
- package/dist/{commission-rate-list-WTDZLKUR.js → commission-rate-list-5V3FQROA.js} +6 -5
- package/dist/{customer-detail-N7CS4IJU.js → customer-detail-SBQF232S.js} +4 -3
- package/dist/customer-group-add-customers-LCNDTLXR.js +1 -1
- package/dist/{customer-group-detail-UCTY4FF7.js → customer-group-detail-QQSNRM2K.js} +6 -5
- package/dist/{customer-group-list-XOQ64CVR.js → customer-group-list-IO7SVK3F.js} +15 -6
- package/dist/{customer-list-BUUO6OF7.js → customer-list-TXBAME4V.js} +4 -3
- package/dist/customers-add-customer-group-BKEV24N2.js +1 -1
- package/dist/index.d.ts +225 -16
- package/dist/index.js +581 -387
- package/dist/inventory-create-Q4JIXZTT.js +56 -0
- package/dist/{inventory-detail-BJT5WEV5.js → inventory-detail-3D37JWQT.js} +7 -6
- package/dist/{inventory-list-3LWBPWVK.js → inventory-list-WH42ADNB.js} +6 -5
- package/dist/{inventory-stock-G3GP4FZX.js → inventory-stock-DTKOGYT7.js} +6 -6
- package/dist/{location-detail-N7J6PEAP.js → location-detail-2SSHXSKL.js} +5 -4
- package/dist/location-fulfillment-providers-BHCY2MYC.js +1 -1
- package/dist/{location-list-UG6B47NP.js → location-list-LPISOSQI.js} +5 -4
- package/dist/{location-sales-channels-3IGHCJEN.js → location-sales-channels-PPH53OHD.js} +6 -7
- package/dist/location-service-zone-shipping-option-create-GSXLVEGO.js +57 -0
- package/dist/{location-service-zone-shipping-option-pricing-7VMPXDWX.js → location-service-zone-shipping-option-pricing-4CTGXBP3.js} +6 -6
- package/dist/marketplace-add-currencies-CIGOPBO6.js +1 -1
- package/dist/{marketplace-detail-7KJMXXAJ.js → marketplace-detail-3CBLIYVK.js} +6 -5
- package/dist/{order-detail-C25NQSZN.js → order-detail-AJV2PE7J.js} +7 -6
- package/dist/{order-edit-billing-address-NVRMPZEU.js → order-edit-billing-address-QQUPIC2H.js} +6 -6
- package/dist/{order-list-7NH7LROU.js → order-list-VPQOG5WE.js} +6 -5
- package/dist/pages/index.d.ts +2608 -82
- package/dist/pages/index.js +238 -156
- package/dist/{payout-detail-MDD5SRK5.js → payout-detail-PMR26YQI.js} +5 -4
- package/dist/{payout-list-XY2A5KYS.js → payout-list-DMG7MQM7.js} +6 -4
- package/dist/price-list-configuration-XK3IZLLX.js +1 -1
- package/dist/price-list-create-QS6CVEWS.js +76 -0
- package/dist/{price-list-detail-IGFSM77P.js → price-list-detail-IO5ZURVW.js} +7 -6
- package/dist/{price-list-list-TBXQ5DOS.js → price-list-list-B3FKB46L.js} +6 -5
- package/dist/price-list-prices-add-NSAQWBT6.js +71 -0
- package/dist/{price-list-prices-edit-QVGBT6AI.js → price-list-prices-edit-UOAIOS5X.js} +6 -6
- package/dist/product-create-UVKMOKRF.js +68 -0
- package/dist/product-create-variant-TCXDJ425.js +53 -0
- package/dist/{product-detail-ZC37BGPC.js → product-detail-273ME23P.js} +4 -4
- package/dist/{product-list-635ZXM2D.js → product-list-2ZHLFSBI.js} +5 -4
- package/dist/{product-media-ZMDAVPGI.js → product-media-YMFP6Q6A.js} +3 -3
- package/dist/{product-prices-WMRIC7WM.js → product-prices-X6JO3Y5A.js} +5 -5
- package/dist/{product-sales-channels-LSN5DVWZ.js → product-sales-channels-2PVBPK6W.js} +2 -3
- package/dist/{product-stock-HF42WRSC.js → product-stock-ARRFHDSU.js} +6 -6
- package/dist/{product-tag-detail-OJLYO3Q5.js → product-tag-detail-545AVFGA.js} +7 -6
- package/dist/{product-tag-list-XFHGJBRF.js → product-tag-list-2Y2Q7K3A.js} +7 -6
- package/dist/{product-type-detail-J4UA4AEM.js → product-type-detail-PBP572AM.js} +7 -6
- package/dist/{product-type-list-H5EQHCXS.js → product-type-list-XWNUKETZ.js} +6 -5
- package/dist/{product-variant-detail-5WKYURFA.js → product-variant-detail-RJUQWBYH.js} +4 -3
- package/dist/{profile-detail-EYNXOHGZ.js → profile-detail-H22ZBNOB.js} +5 -4
- package/dist/{promotion-add-campaign-B5SF72KC.js → promotion-add-campaign-5LCKEU6H.js} +3 -3
- package/dist/promotion-create-KXBEHXPK.js +54 -0
- package/dist/{promotion-detail-MVFOMS4E.js → promotion-detail-NZZ2HII7.js} +7 -6
- package/dist/{promotion-list-IN4VWEQN.js → promotion-list-KARWNOAQ.js} +9 -8
- package/dist/{refund-reason-list-DJZZC7KK.js → refund-reason-list-GTZQBZ7R.js} +3 -2
- package/dist/{region-detail-OFZHX57G.js → region-detail-3OPMLS4V.js} +5 -4
- package/dist/{region-list-L4FKHVJJ.js → region-list-542EMW5C.js} +6 -5
- package/dist/{reservation-detail-LZYEM5NW.js → reservation-detail-IPGIBQW4.js} +5 -4
- package/dist/{reservation-list-OGPDB7WG.js → reservation-list-CEFKMB2G.js} +6 -5
- package/dist/{reset-password-Q7Y4FWRE.js → reset-password-R5ULRWEM.js} +1 -1
- package/dist/{return-reason-list-6ICMSVKF.js → return-reason-list-S7LU655M.js} +5 -4
- package/dist/{sales-channel-detail-RRJG7U7R.js → sales-channel-detail-QCJ6OC3H.js} +7 -6
- package/dist/{sales-channel-list-LUZ4ZXCY.js → sales-channel-list-KYNBWXUD.js} +7 -7
- package/dist/seller-details-A7TYGP67.js +104 -0
- package/dist/{seller-list-664H4SI5.js → seller-list-5KPNNC2B.js} +7 -6
- package/dist/{shipping-option-type-detail-2RY3NHRO.js → shipping-option-type-detail-OBYOZZWS.js} +5 -4
- package/dist/{shipping-option-type-list-IOSOE33S.js → shipping-option-type-list-UGVMQ3DC.js} +6 -5
- package/dist/{shipping-profile-detail-RIIAX7VE.js → shipping-profile-detail-RYOFRMLH.js} +5 -4
- package/dist/{shipping-profiles-list-AL4EJSJY.js → shipping-profiles-list-XJGQ7AVX.js} +5 -4
- package/dist/{tax-region-create-UOTLTCOP.js → tax-region-create-AR2LNF2G.js} +6 -6
- package/dist/{tax-region-detail-CA2W5W6A.js → tax-region-detail-PIGY5JQ7.js} +7 -6
- package/dist/{tax-region-list-JTZ7KZCX.js → tax-region-list-AMGZWUAI.js} +6 -5
- package/dist/{tax-region-province-detail-ZHLX4FF4.js → tax-region-province-detail-D3R4FJT4.js} +6 -5
- package/dist/types-DUhfb5tH.d.ts +30 -0
- package/dist/{user-detail-YNPBC5MN.js → user-detail-H66ZAR7W.js} +5 -4
- package/dist/{user-list-LNTZNT3D.js → user-list-HIUXLIJV.js} +5 -4
- package/package.json +3 -3
- package/dist/chunk-62ZRA6BZ.js +0 -216
- package/dist/chunk-6PNMR6XP.js +0 -192
- package/dist/chunk-7COSFMM7.js +0 -163
- package/dist/chunk-A2KURGQO.js +0 -151
- package/dist/chunk-BHID7W3U.js +0 -78
- package/dist/chunk-UKLRBS4W.js +0 -61
- package/dist/inventory-create-QLEIHESO.js +0 -620
- package/dist/location-service-zone-shipping-option-create-GYPW6SSN.js +0 -811
- package/dist/promotion-create-D77SANLX.js +0 -1262
- package/dist/{adjust-inventory-HZCWL6SC.js → adjust-inventory-WL7D7TQR.js} +3 -3
- package/dist/{campaign-budget-edit-AIXCDGG3.js → campaign-budget-edit-722ECPRI.js} +3 -3
- package/dist/{category-products-XLCG2JR7.js → category-products-H3VFYGOU.js} +2 -2
- package/dist/{chunk-DEKJJ7NG.js → chunk-OFCUTNGV.js} +3 -3
- package/dist/{chunk-KUWNYCGL.js → chunk-U3OWJE7V.js} +0 -0
- package/dist/{collection-add-products-IQ7M63BA.js → collection-add-products-BQ2FZKR4.js} +1 -1
- package/dist/{commission-rate-create-VC72GTV4.js → commission-rate-create-GFQNADQS.js} +9 -9
- package/dist/{commission-rate-edit-AXJKJNFY.js → commission-rate-edit-A2BFZUEI.js} +9 -9
- package/dist/{location-service-zone-shipping-option-edit-E3GN4ZF5.js → location-service-zone-shipping-option-edit-KPECMUYB.js} +3 -3
- package/dist/{order-create-claim-7WW6MXTT.js → order-create-claim-IWTV2HKL.js} +6 -6
- package/dist/{order-create-edit-KAH6ZPLX.js → order-create-edit-H2MHZFIW.js} +5 -5
- package/dist/{order-create-exchange-ELLWF3IY.js → order-create-exchange-PPMRSGLD.js} +6 -6
- package/dist/{order-create-refund-5QZBOSCA.js → order-create-refund-LZOHRL7T.js} +3 -3
- package/dist/{order-create-return-L6DEDPJK.js → order-create-return-WY6R4QMN.js} +6 -6
- package/dist/{order-edit-shipping-address-BPU7OL2N.js → order-edit-shipping-address-XQCSN4YO.js} +3 -3
- package/dist/{order-receive-return-FW5QZJBM.js → order-receive-return-GKMHYD4G.js} +1 -1
- package/dist/{product-edit-LQJDUUVX.js → product-edit-QGRKGJ3H.js} +1 -1
- package/dist/{product-variant-edit-66ZUIIMP.js → product-variant-edit-IQLBIHDE.js} +1 -1
- package/dist/{product-variant-manage-inventory-items-CV2CC2PV.js → product-variant-manage-inventory-items-C77QHYRT.js} +3 -3
- package/dist/{promotion-edit-details-YKS24GBD.js → promotion-edit-details-BFXPUEE6.js} +4 -4
- package/dist/{region-create-UMJK3VGL.js → region-create-ZPY6V77Q.js} +3 -3
- package/dist/{region-edit-ODVSNJHM.js → region-edit-Q2CBVPR2.js} +3 -3
- package/dist/{sales-channel-add-products-EOWFSO35.js → sales-channel-add-products-PIY4PUIW.js} +2 -2
- package/dist/{tax-region-province-create-RFYCUDER.js → tax-region-province-create-7BMYABJ6.js} +3 -3
- package/dist/{tax-region-tax-override-create-WIWUNXW6.js → tax-region-tax-override-create-EBDKSAXG.js} +6 -6
- package/dist/{tax-region-tax-override-edit-SWROFQTP.js → tax-region-tax-override-edit-55ODL7KC.js} +6 -6
|
@@ -0,0 +1,1155 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DeprecatedPercentageInput
|
|
3
|
+
} from "./chunk-MAEP2UCK.js";
|
|
4
|
+
import {
|
|
5
|
+
AddCampaignPromotionFields
|
|
6
|
+
} from "./chunk-X56THFPA.js";
|
|
7
|
+
import {
|
|
8
|
+
RulesFormField
|
|
9
|
+
} from "./chunk-VBBBIEVH.js";
|
|
10
|
+
import {
|
|
11
|
+
CreateCampaignSchema,
|
|
12
|
+
DEFAULT_CAMPAIGN_VALUES
|
|
13
|
+
} from "./chunk-R5VKVG6S.js";
|
|
14
|
+
import {
|
|
15
|
+
currencies,
|
|
16
|
+
getCurrencySymbol
|
|
17
|
+
} from "./chunk-IQPN4PZJ.js";
|
|
18
|
+
import {
|
|
19
|
+
TabbedForm,
|
|
20
|
+
defineTabMeta,
|
|
21
|
+
useTabbedForm
|
|
22
|
+
} from "./chunk-5GG65TKV.js";
|
|
23
|
+
import {
|
|
24
|
+
useDocumentDirection
|
|
25
|
+
} from "./chunk-Y7QKP6QU.js";
|
|
26
|
+
import {
|
|
27
|
+
RouteFocusModal,
|
|
28
|
+
useRouteModal
|
|
29
|
+
} from "./chunk-MWOKFNRO.js";
|
|
30
|
+
import {
|
|
31
|
+
Form
|
|
32
|
+
} from "./chunk-3QSRE5LS.js";
|
|
33
|
+
import {
|
|
34
|
+
useCreatePromotion
|
|
35
|
+
} from "./chunk-5PB7KCTF.js";
|
|
36
|
+
|
|
37
|
+
// src/pages/promotions/promotion-create/components/create-promotion-form/form-schema.ts
|
|
38
|
+
import { z } from "zod";
|
|
39
|
+
var RuleSchema = z.array(
|
|
40
|
+
z.object({
|
|
41
|
+
id: z.string().optional(),
|
|
42
|
+
attribute: z.string().min(1, { message: "Required field" }),
|
|
43
|
+
operator: z.string().min(1, { message: "Required field" }),
|
|
44
|
+
values: z.union([
|
|
45
|
+
z.number().min(1, { message: "Required field" }),
|
|
46
|
+
z.string().min(1, { message: "Required field" }),
|
|
47
|
+
z.array(z.string()).min(1, { message: "Required field" })
|
|
48
|
+
]),
|
|
49
|
+
required: z.boolean().optional(),
|
|
50
|
+
disguised: z.boolean().optional(),
|
|
51
|
+
field_type: z.string().optional()
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
var CreatePromotionSchema = z.object({
|
|
55
|
+
template_id: z.string().optional(),
|
|
56
|
+
campaign_id: z.string().optional(),
|
|
57
|
+
campaign_choice: z.enum(["none", "existing", "new"]).optional(),
|
|
58
|
+
is_automatic: z.string().toLowerCase(),
|
|
59
|
+
code: z.string().min(1),
|
|
60
|
+
type: z.enum(["buyget", "standard"]),
|
|
61
|
+
status: z.enum(["draft", "active", "inactive"]),
|
|
62
|
+
rules: RuleSchema,
|
|
63
|
+
is_tax_inclusive: z.boolean().optional(),
|
|
64
|
+
application_method: z.object({
|
|
65
|
+
allocation: z.enum(["each", "across", "once"]),
|
|
66
|
+
value: z.number().min(0).or(z.string().min(1)),
|
|
67
|
+
currency_code: z.string().optional(),
|
|
68
|
+
max_quantity: z.number().optional().nullable(),
|
|
69
|
+
target_rules: RuleSchema,
|
|
70
|
+
buy_rules: RuleSchema,
|
|
71
|
+
type: z.enum(["fixed", "percentage"]),
|
|
72
|
+
target_type: z.enum(["order", "shipping_methods", "items"])
|
|
73
|
+
}),
|
|
74
|
+
campaign: CreateCampaignSchema.optional()
|
|
75
|
+
}).refine(
|
|
76
|
+
(data) => {
|
|
77
|
+
if (data.application_method.allocation === "across") {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return typeof data.application_method.max_quantity === "number";
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
path: ["application_method.max_quantity"],
|
|
84
|
+
message: `required field`
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// src/pages/promotions/promotion-create/promotion-create.tsx
|
|
89
|
+
import { Children as Children2 } from "react";
|
|
90
|
+
|
|
91
|
+
// src/pages/promotions/promotion-create/components/create-promotion-form/create-promotion-form.tsx
|
|
92
|
+
import { Children, useEffect as useEffect2, useMemo } from "react";
|
|
93
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
94
|
+
import { toast } from "@medusajs/ui";
|
|
95
|
+
import { useForm, useWatch as useWatch3 } from "react-hook-form";
|
|
96
|
+
import { useTranslation as useTranslation3 } from "react-i18next";
|
|
97
|
+
|
|
98
|
+
// src/pages/promotions/promotion-create/components/create-promotion-form/promotion-campaign-tab.tsx
|
|
99
|
+
import { useWatch } from "react-hook-form";
|
|
100
|
+
import { jsx } from "react/jsx-runtime";
|
|
101
|
+
var Root = () => {
|
|
102
|
+
const form = useTabbedForm();
|
|
103
|
+
const currencyCode = useWatch({
|
|
104
|
+
control: form.control,
|
|
105
|
+
name: "application_method.currency_code"
|
|
106
|
+
});
|
|
107
|
+
return /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center", children: /* @__PURE__ */ jsx("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8 py-16", children: /* @__PURE__ */ jsx(
|
|
108
|
+
AddCampaignPromotionFields,
|
|
109
|
+
{
|
|
110
|
+
form,
|
|
111
|
+
promotionCurrencyCode: currencyCode
|
|
112
|
+
}
|
|
113
|
+
) }) });
|
|
114
|
+
};
|
|
115
|
+
Root._tabMeta = defineTabMeta({
|
|
116
|
+
id: "campaign",
|
|
117
|
+
labelKey: "promotions.tabs.campaign",
|
|
118
|
+
validationFields: ["campaign_id", "campaign_choice", "campaign"]
|
|
119
|
+
});
|
|
120
|
+
var PromotionCampaignTab = Root;
|
|
121
|
+
|
|
122
|
+
// src/pages/promotions/promotion-create/components/create-promotion-form/promotion-details-tab.tsx
|
|
123
|
+
import { useEffect, useState } from "react";
|
|
124
|
+
import {
|
|
125
|
+
Alert,
|
|
126
|
+
Badge,
|
|
127
|
+
clx,
|
|
128
|
+
CurrencyInput,
|
|
129
|
+
Divider,
|
|
130
|
+
Heading,
|
|
131
|
+
Input,
|
|
132
|
+
RadioGroup,
|
|
133
|
+
Switch,
|
|
134
|
+
Text
|
|
135
|
+
} from "@medusajs/ui";
|
|
136
|
+
import { useWatch as useWatch2 } from "react-hook-form";
|
|
137
|
+
import { Trans, useTranslation } from "react-i18next";
|
|
138
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
139
|
+
var Root2 = ({ currentTemplate }) => {
|
|
140
|
+
const { t } = useTranslation();
|
|
141
|
+
const direction = useDocumentDirection();
|
|
142
|
+
const form = useTabbedForm();
|
|
143
|
+
const { setValue } = form;
|
|
144
|
+
const [allocationMode, setAllocationMode] = useState("each");
|
|
145
|
+
const watchValueType = useWatch2({
|
|
146
|
+
control: form.control,
|
|
147
|
+
name: "application_method.type"
|
|
148
|
+
});
|
|
149
|
+
const isFixedValueType = watchValueType === "fixed";
|
|
150
|
+
const watchAllocation = useWatch2({
|
|
151
|
+
control: form.control,
|
|
152
|
+
name: "application_method.allocation"
|
|
153
|
+
});
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (watchAllocation) {
|
|
156
|
+
setAllocationMode(watchAllocation);
|
|
157
|
+
}
|
|
158
|
+
}, [watchAllocation]);
|
|
159
|
+
const watchType = useWatch2({
|
|
160
|
+
control: form.control,
|
|
161
|
+
name: "type"
|
|
162
|
+
});
|
|
163
|
+
const isTypeStandard = watchType === "standard";
|
|
164
|
+
const isTypeBuyGet = watchType === "buyget";
|
|
165
|
+
const targetType = useWatch2({
|
|
166
|
+
control: form.control,
|
|
167
|
+
name: "application_method.target_type"
|
|
168
|
+
});
|
|
169
|
+
const isTargetTypeOrder = targetType === "order";
|
|
170
|
+
return /* @__PURE__ */ jsx2("div", { className: "flex size-full flex-col items-center", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8 py-16", children: [
|
|
171
|
+
/* @__PURE__ */ jsxs(
|
|
172
|
+
Heading,
|
|
173
|
+
{
|
|
174
|
+
level: "h1",
|
|
175
|
+
className: "text-fg-base",
|
|
176
|
+
"data-testid": "promotion-create-form-promotion-heading",
|
|
177
|
+
children: [
|
|
178
|
+
t(`promotions.sections.details`),
|
|
179
|
+
currentTemplate?.title && /* @__PURE__ */ jsx2(
|
|
180
|
+
Badge,
|
|
181
|
+
{
|
|
182
|
+
className: "ml-2 align-middle",
|
|
183
|
+
color: "grey",
|
|
184
|
+
size: "2xsmall",
|
|
185
|
+
rounded: "full",
|
|
186
|
+
"data-testid": "promotion-create-form-promotion-template-badge",
|
|
187
|
+
children: currentTemplate?.title
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
),
|
|
193
|
+
form.formState.errors.root && /* @__PURE__ */ jsx2(
|
|
194
|
+
Alert,
|
|
195
|
+
{
|
|
196
|
+
variant: "error",
|
|
197
|
+
dismissible: false,
|
|
198
|
+
className: "text-balance",
|
|
199
|
+
"data-testid": "promotion-create-form-promotion-error-alert",
|
|
200
|
+
children: form.formState.errors.root.message
|
|
201
|
+
}
|
|
202
|
+
),
|
|
203
|
+
/* @__PURE__ */ jsx2(
|
|
204
|
+
Form.Field,
|
|
205
|
+
{
|
|
206
|
+
control: form.control,
|
|
207
|
+
name: "is_automatic",
|
|
208
|
+
render: ({ field }) => {
|
|
209
|
+
return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "promotion-create-form-method-item", children: [
|
|
210
|
+
/* @__PURE__ */ jsx2(Form.Label, { "data-testid": "promotion-create-form-method-label", children: t("promotions.form.method.label") }),
|
|
211
|
+
/* @__PURE__ */ jsx2(Form.Control, { "data-testid": "promotion-create-form-method-control", children: /* @__PURE__ */ jsxs(
|
|
212
|
+
RadioGroup,
|
|
213
|
+
{
|
|
214
|
+
dir: direction,
|
|
215
|
+
className: "flex gap-y-3",
|
|
216
|
+
...field,
|
|
217
|
+
value: field.value,
|
|
218
|
+
onValueChange: field.onChange,
|
|
219
|
+
"data-testid": "promotion-create-form-method-radio-group",
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ jsx2(
|
|
222
|
+
RadioGroup.ChoiceBox,
|
|
223
|
+
{
|
|
224
|
+
value: "false",
|
|
225
|
+
label: t("promotions.form.method.code.title"),
|
|
226
|
+
description: t("promotions.form.method.code.description"),
|
|
227
|
+
className: clx("basis-1/2"),
|
|
228
|
+
"data-testid": "promotion-create-form-method-option-code"
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
/* @__PURE__ */ jsx2(
|
|
232
|
+
RadioGroup.ChoiceBox,
|
|
233
|
+
{
|
|
234
|
+
value: "true",
|
|
235
|
+
label: t("promotions.form.method.automatic.title"),
|
|
236
|
+
description: t(
|
|
237
|
+
"promotions.form.method.automatic.description"
|
|
238
|
+
),
|
|
239
|
+
className: clx("basis-1/2"),
|
|
240
|
+
"data-testid": "promotion-create-form-method-option-automatic"
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
) }),
|
|
246
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-method-error" })
|
|
247
|
+
] });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
),
|
|
251
|
+
/* @__PURE__ */ jsx2(
|
|
252
|
+
Form.Field,
|
|
253
|
+
{
|
|
254
|
+
control: form.control,
|
|
255
|
+
name: "status",
|
|
256
|
+
render: ({ field }) => {
|
|
257
|
+
return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "promotion-create-form-status-item", children: [
|
|
258
|
+
/* @__PURE__ */ jsx2(Form.Label, { "data-testid": "promotion-create-form-status-label", children: t("promotions.form.status.label") }),
|
|
259
|
+
/* @__PURE__ */ jsx2(Form.Control, { "data-testid": "promotion-create-form-status-control", children: /* @__PURE__ */ jsxs(
|
|
260
|
+
RadioGroup,
|
|
261
|
+
{
|
|
262
|
+
dir: direction,
|
|
263
|
+
className: "flex gap-y-3",
|
|
264
|
+
...field,
|
|
265
|
+
value: field.value,
|
|
266
|
+
onValueChange: field.onChange,
|
|
267
|
+
"data-testid": "promotion-create-form-status-radio-group",
|
|
268
|
+
children: [
|
|
269
|
+
/* @__PURE__ */ jsx2(
|
|
270
|
+
RadioGroup.ChoiceBox,
|
|
271
|
+
{
|
|
272
|
+
value: "draft",
|
|
273
|
+
label: t("promotions.form.status.draft.title"),
|
|
274
|
+
description: t(
|
|
275
|
+
"promotions.form.status.draft.description"
|
|
276
|
+
),
|
|
277
|
+
className: clx("basis-1/2"),
|
|
278
|
+
"data-testid": "promotion-create-form-status-option-draft"
|
|
279
|
+
}
|
|
280
|
+
),
|
|
281
|
+
/* @__PURE__ */ jsx2(
|
|
282
|
+
RadioGroup.ChoiceBox,
|
|
283
|
+
{
|
|
284
|
+
value: "active",
|
|
285
|
+
label: t("promotions.form.status.active.title"),
|
|
286
|
+
description: t(
|
|
287
|
+
"promotions.form.status.active.description"
|
|
288
|
+
),
|
|
289
|
+
className: clx("basis-1/2"),
|
|
290
|
+
"data-testid": "promotion-create-form-status-option-active"
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
) }),
|
|
296
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-status-error" })
|
|
297
|
+
] });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
),
|
|
301
|
+
/* @__PURE__ */ jsx2("div", { className: "flex gap-y-4", children: /* @__PURE__ */ jsx2(
|
|
302
|
+
Form.Field,
|
|
303
|
+
{
|
|
304
|
+
control: form.control,
|
|
305
|
+
name: "code",
|
|
306
|
+
render: ({ field }) => {
|
|
307
|
+
return /* @__PURE__ */ jsxs(
|
|
308
|
+
Form.Item,
|
|
309
|
+
{
|
|
310
|
+
className: "basis-1/2",
|
|
311
|
+
"data-testid": "promotion-create-form-code-item",
|
|
312
|
+
children: [
|
|
313
|
+
/* @__PURE__ */ jsx2(Form.Label, { "data-testid": "promotion-create-form-code-label", children: t("promotions.form.code.title") }),
|
|
314
|
+
/* @__PURE__ */ jsx2(Form.Control, { "data-testid": "promotion-create-form-code-control", children: /* @__PURE__ */ jsx2(
|
|
315
|
+
Input,
|
|
316
|
+
{
|
|
317
|
+
...field,
|
|
318
|
+
placeholder: "SUMMER15",
|
|
319
|
+
"data-testid": "promotion-create-form-code-input"
|
|
320
|
+
}
|
|
321
|
+
) }),
|
|
322
|
+
/* @__PURE__ */ jsx2(
|
|
323
|
+
Text,
|
|
324
|
+
{
|
|
325
|
+
size: "small",
|
|
326
|
+
leading: "compact",
|
|
327
|
+
className: "text-ui-fg-subtle",
|
|
328
|
+
"data-testid": "promotion-create-form-code-description",
|
|
329
|
+
children: /* @__PURE__ */ jsx2(
|
|
330
|
+
Trans,
|
|
331
|
+
{
|
|
332
|
+
t,
|
|
333
|
+
i18nKey: "promotions.form.code.description",
|
|
334
|
+
components: [/* @__PURE__ */ jsx2("br", {}, "break")]
|
|
335
|
+
}
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
),
|
|
339
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-code-error" })
|
|
340
|
+
]
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
) }),
|
|
346
|
+
!currentTemplate?.hiddenFields?.includes("is_tax_inclusive") && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
347
|
+
/* @__PURE__ */ jsx2(Divider, {}),
|
|
348
|
+
/* @__PURE__ */ jsx2("div", { className: "flex gap-x-2 gap-y-4", children: /* @__PURE__ */ jsx2(
|
|
349
|
+
Form.Field,
|
|
350
|
+
{
|
|
351
|
+
control: form.control,
|
|
352
|
+
name: "is_tax_inclusive",
|
|
353
|
+
render: ({ field: { onChange, value, ...field } }) => {
|
|
354
|
+
return /* @__PURE__ */ jsxs(
|
|
355
|
+
Form.Item,
|
|
356
|
+
{
|
|
357
|
+
className: "basis-full",
|
|
358
|
+
"data-testid": "promotion-create-form-tax-inclusive-item",
|
|
359
|
+
children: [
|
|
360
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
361
|
+
/* @__PURE__ */ jsxs("div", { className: "block", children: [
|
|
362
|
+
/* @__PURE__ */ jsx2(Form.Label, { "data-testid": "promotion-create-form-tax-inclusive-label", children: t("promotions.form.taxInclusive.title") }),
|
|
363
|
+
/* @__PURE__ */ jsx2(
|
|
364
|
+
Form.Hint,
|
|
365
|
+
{
|
|
366
|
+
className: "!mt-1",
|
|
367
|
+
"data-testid": "promotion-create-form-tax-inclusive-hint",
|
|
368
|
+
children: t("promotions.form.taxInclusive.description")
|
|
369
|
+
}
|
|
370
|
+
)
|
|
371
|
+
] }),
|
|
372
|
+
/* @__PURE__ */ jsx2(
|
|
373
|
+
Form.Control,
|
|
374
|
+
{
|
|
375
|
+
className: "mr-2 self-center",
|
|
376
|
+
"data-testid": "promotion-create-form-tax-inclusive-control",
|
|
377
|
+
children: /* @__PURE__ */ jsx2(
|
|
378
|
+
Switch,
|
|
379
|
+
{
|
|
380
|
+
dir: "ltr",
|
|
381
|
+
className: "mt-[2px] rtl:rotate-180",
|
|
382
|
+
checked: !!value,
|
|
383
|
+
onCheckedChange: onChange,
|
|
384
|
+
...field,
|
|
385
|
+
"data-testid": "promotion-create-form-tax-inclusive-switch"
|
|
386
|
+
}
|
|
387
|
+
)
|
|
388
|
+
}
|
|
389
|
+
)
|
|
390
|
+
] }),
|
|
391
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-tax-inclusive-error" })
|
|
392
|
+
]
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
) })
|
|
398
|
+
] }),
|
|
399
|
+
!currentTemplate?.hiddenFields?.includes("type") && /* @__PURE__ */ jsx2(
|
|
400
|
+
Form.Field,
|
|
401
|
+
{
|
|
402
|
+
control: form.control,
|
|
403
|
+
name: "type",
|
|
404
|
+
render: ({ field }) => {
|
|
405
|
+
return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "promotion-create-form-type-item", children: [
|
|
406
|
+
/* @__PURE__ */ jsx2(Form.Label, { "data-testid": "promotion-create-form-type-label", children: t("promotions.fields.type") }),
|
|
407
|
+
/* @__PURE__ */ jsx2(Form.Control, { "data-testid": "promotion-create-form-type-control", children: /* @__PURE__ */ jsxs(
|
|
408
|
+
RadioGroup,
|
|
409
|
+
{
|
|
410
|
+
dir: direction,
|
|
411
|
+
className: "flex gap-y-3",
|
|
412
|
+
...field,
|
|
413
|
+
onValueChange: field.onChange,
|
|
414
|
+
"data-testid": "promotion-create-form-type-radio-group",
|
|
415
|
+
children: [
|
|
416
|
+
/* @__PURE__ */ jsx2(
|
|
417
|
+
RadioGroup.ChoiceBox,
|
|
418
|
+
{
|
|
419
|
+
value: "standard",
|
|
420
|
+
label: t("promotions.form.type.standard.title"),
|
|
421
|
+
description: t(
|
|
422
|
+
"promotions.form.type.standard.description"
|
|
423
|
+
),
|
|
424
|
+
className: clx("basis-1/2"),
|
|
425
|
+
"data-testid": "promotion-create-form-type-option-standard"
|
|
426
|
+
}
|
|
427
|
+
),
|
|
428
|
+
/* @__PURE__ */ jsx2(
|
|
429
|
+
RadioGroup.ChoiceBox,
|
|
430
|
+
{
|
|
431
|
+
value: "buyget",
|
|
432
|
+
label: t("promotions.form.type.buyget.title"),
|
|
433
|
+
description: t(
|
|
434
|
+
"promotions.form.type.buyget.description"
|
|
435
|
+
),
|
|
436
|
+
className: clx("basis-1/2"),
|
|
437
|
+
"data-testid": "promotion-create-form-type-option-buyget"
|
|
438
|
+
}
|
|
439
|
+
)
|
|
440
|
+
]
|
|
441
|
+
}
|
|
442
|
+
) }),
|
|
443
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-type-error" })
|
|
444
|
+
] });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
),
|
|
448
|
+
/* @__PURE__ */ jsx2(Divider, {}),
|
|
449
|
+
/* @__PURE__ */ jsx2(RulesFormField, { form, ruleType: "rules" }),
|
|
450
|
+
!currentTemplate?.hiddenFields?.includes("application_method.type") && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
451
|
+
/* @__PURE__ */ jsx2(Divider, {}),
|
|
452
|
+
/* @__PURE__ */ jsx2(
|
|
453
|
+
Form.Field,
|
|
454
|
+
{
|
|
455
|
+
control: form.control,
|
|
456
|
+
name: "application_method.type",
|
|
457
|
+
render: ({ field }) => {
|
|
458
|
+
return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "promotion-create-form-value-type-item", children: [
|
|
459
|
+
/* @__PURE__ */ jsx2(Form.Label, { "data-testid": "promotion-create-form-value-type-label", children: t("promotions.fields.value_type") }),
|
|
460
|
+
/* @__PURE__ */ jsx2(Form.Control, { "data-testid": "promotion-create-form-value-type-control", children: /* @__PURE__ */ jsxs(
|
|
461
|
+
RadioGroup,
|
|
462
|
+
{
|
|
463
|
+
dir: direction,
|
|
464
|
+
className: "flex gap-y-3",
|
|
465
|
+
...field,
|
|
466
|
+
onValueChange: field.onChange,
|
|
467
|
+
"data-testid": "promotion-create-form-value-type-radio-group",
|
|
468
|
+
children: [
|
|
469
|
+
/* @__PURE__ */ jsx2(
|
|
470
|
+
RadioGroup.ChoiceBox,
|
|
471
|
+
{
|
|
472
|
+
value: "fixed",
|
|
473
|
+
label: t(
|
|
474
|
+
"promotions.form.value_type.fixed.title"
|
|
475
|
+
),
|
|
476
|
+
description: t(
|
|
477
|
+
"promotions.form.value_type.fixed.description"
|
|
478
|
+
),
|
|
479
|
+
className: clx("basis-1/2"),
|
|
480
|
+
"data-testid": "promotion-create-form-value-type-option-fixed"
|
|
481
|
+
}
|
|
482
|
+
),
|
|
483
|
+
/* @__PURE__ */ jsx2(
|
|
484
|
+
RadioGroup.ChoiceBox,
|
|
485
|
+
{
|
|
486
|
+
value: "percentage",
|
|
487
|
+
label: t(
|
|
488
|
+
"promotions.form.value_type.percentage.title"
|
|
489
|
+
),
|
|
490
|
+
description: t(
|
|
491
|
+
"promotions.form.value_type.percentage.description"
|
|
492
|
+
),
|
|
493
|
+
className: clx("basis-1/2"),
|
|
494
|
+
"data-testid": "promotion-create-form-value-type-option-percentage"
|
|
495
|
+
}
|
|
496
|
+
)
|
|
497
|
+
]
|
|
498
|
+
}
|
|
499
|
+
) }),
|
|
500
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-value-type-error" })
|
|
501
|
+
] });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
)
|
|
505
|
+
] }),
|
|
506
|
+
!currentTemplate?.hiddenFields?.includes(
|
|
507
|
+
"application_method.value"
|
|
508
|
+
) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
509
|
+
/* @__PURE__ */ jsx2(Divider, {}),
|
|
510
|
+
/* @__PURE__ */ jsx2(
|
|
511
|
+
Form.Field,
|
|
512
|
+
{
|
|
513
|
+
control: form.control,
|
|
514
|
+
name: "application_method.value",
|
|
515
|
+
render: ({ field: { onChange, value, ...field } }) => {
|
|
516
|
+
const currencyCode = form.getValues().application_method.currency_code;
|
|
517
|
+
const currencyInfo = currencies[currencyCode?.toUpperCase() || "USD"];
|
|
518
|
+
return /* @__PURE__ */ jsxs(
|
|
519
|
+
Form.Item,
|
|
520
|
+
{
|
|
521
|
+
className: "basis-1/2",
|
|
522
|
+
"data-testid": "promotion-create-form-value-item",
|
|
523
|
+
children: [
|
|
524
|
+
/* @__PURE__ */ jsx2(
|
|
525
|
+
Form.Label,
|
|
526
|
+
{
|
|
527
|
+
tooltip: currencyCode || !isFixedValueType ? void 0 : t("promotions.fields.amount.tooltip"),
|
|
528
|
+
"data-testid": "promotion-create-form-value-label",
|
|
529
|
+
children: t("promotions.form.value.title")
|
|
530
|
+
}
|
|
531
|
+
),
|
|
532
|
+
/* @__PURE__ */ jsx2(Form.Control, { "data-testid": "promotion-create-form-value-control", children: isFixedValueType ? /* @__PURE__ */ jsx2(
|
|
533
|
+
CurrencyInput,
|
|
534
|
+
{
|
|
535
|
+
...field,
|
|
536
|
+
min: 0,
|
|
537
|
+
code: currencyCode || "USD",
|
|
538
|
+
onValueChange: (_value, _name, values) => onChange(values?.value),
|
|
539
|
+
decimalScale: currencyInfo?.decimal_digits ?? 2,
|
|
540
|
+
decimalsLimit: currencyInfo?.decimal_digits ?? 2,
|
|
541
|
+
symbol: currencyCode ? getCurrencySymbol(currencyCode) : "$",
|
|
542
|
+
value,
|
|
543
|
+
disabled: !currencyCode,
|
|
544
|
+
"data-testid": "promotion-create-form-value-currency-input"
|
|
545
|
+
}
|
|
546
|
+
) : /* @__PURE__ */ jsx2(
|
|
547
|
+
DeprecatedPercentageInput,
|
|
548
|
+
{
|
|
549
|
+
className: "text-right",
|
|
550
|
+
min: 0,
|
|
551
|
+
max: 100,
|
|
552
|
+
...field,
|
|
553
|
+
value,
|
|
554
|
+
onChange: (e) => {
|
|
555
|
+
onChange(
|
|
556
|
+
e.target.value === "" ? null : parseFloat(e.target.value)
|
|
557
|
+
);
|
|
558
|
+
},
|
|
559
|
+
"data-testid": "promotion-create-form-value-percentage-input"
|
|
560
|
+
},
|
|
561
|
+
"amount"
|
|
562
|
+
) }),
|
|
563
|
+
/* @__PURE__ */ jsx2(
|
|
564
|
+
Text,
|
|
565
|
+
{
|
|
566
|
+
size: "small",
|
|
567
|
+
leading: "compact",
|
|
568
|
+
className: "text-ui-fg-subtle",
|
|
569
|
+
"data-testid": "promotion-create-form-value-description",
|
|
570
|
+
children: /* @__PURE__ */ jsx2(
|
|
571
|
+
Trans,
|
|
572
|
+
{
|
|
573
|
+
t,
|
|
574
|
+
i18nKey: isFixedValueType ? "promotions.form.value_type.fixed.description" : "promotions.form.value_type.percentage.description",
|
|
575
|
+
components: [/* @__PURE__ */ jsx2("br", {}, "break")]
|
|
576
|
+
}
|
|
577
|
+
)
|
|
578
|
+
}
|
|
579
|
+
),
|
|
580
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-value-error" })
|
|
581
|
+
]
|
|
582
|
+
}
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
)
|
|
587
|
+
] }),
|
|
588
|
+
(isTypeStandard || isTypeBuyGet) && allocationMode !== "across" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
589
|
+
isTypeBuyGet && /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsx2(Divider, {}) }),
|
|
590
|
+
/* @__PURE__ */ jsx2(
|
|
591
|
+
Form.Field,
|
|
592
|
+
{
|
|
593
|
+
control: form.control,
|
|
594
|
+
name: "application_method.max_quantity",
|
|
595
|
+
render: () => {
|
|
596
|
+
return /* @__PURE__ */ jsxs(
|
|
597
|
+
Form.Item,
|
|
598
|
+
{
|
|
599
|
+
className: "basis-1/2",
|
|
600
|
+
"data-testid": "promotion-create-form-max-quantity-item",
|
|
601
|
+
children: [
|
|
602
|
+
/* @__PURE__ */ jsx2(Form.Label, { "data-testid": "promotion-create-form-max-quantity-label", children: t("promotions.form.max_quantity.title") }),
|
|
603
|
+
/* @__PURE__ */ jsx2(Form.Control, { "data-testid": "promotion-create-form-max-quantity-control", children: /* @__PURE__ */ jsx2(
|
|
604
|
+
Input,
|
|
605
|
+
{
|
|
606
|
+
...form.register("application_method.max_quantity", {
|
|
607
|
+
valueAsNumber: true
|
|
608
|
+
}),
|
|
609
|
+
type: "number",
|
|
610
|
+
min: 1,
|
|
611
|
+
placeholder: "3",
|
|
612
|
+
"data-testid": "promotion-create-form-max-quantity-input"
|
|
613
|
+
}
|
|
614
|
+
) }),
|
|
615
|
+
/* @__PURE__ */ jsx2(
|
|
616
|
+
Text,
|
|
617
|
+
{
|
|
618
|
+
size: "small",
|
|
619
|
+
leading: "compact",
|
|
620
|
+
className: "text-ui-fg-subtle",
|
|
621
|
+
"data-testid": "promotion-create-form-max-quantity-description",
|
|
622
|
+
children: /* @__PURE__ */ jsx2(
|
|
623
|
+
Trans,
|
|
624
|
+
{
|
|
625
|
+
t,
|
|
626
|
+
i18nKey: "promotions.form.max_quantity.description",
|
|
627
|
+
components: [/* @__PURE__ */ jsx2("br", {}, "break")]
|
|
628
|
+
}
|
|
629
|
+
)
|
|
630
|
+
}
|
|
631
|
+
),
|
|
632
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-max-quantity-error" })
|
|
633
|
+
]
|
|
634
|
+
}
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
)
|
|
639
|
+
] }),
|
|
640
|
+
!currentTemplate?.hiddenFields?.includes(
|
|
641
|
+
"application_method.allocation"
|
|
642
|
+
) && /* @__PURE__ */ jsx2(
|
|
643
|
+
Form.Field,
|
|
644
|
+
{
|
|
645
|
+
control: form.control,
|
|
646
|
+
name: "application_method.allocation",
|
|
647
|
+
render: ({ field }) => {
|
|
648
|
+
const handleAllocationChange = (value) => {
|
|
649
|
+
setAllocationMode(value);
|
|
650
|
+
setValue(
|
|
651
|
+
"application_method.allocation",
|
|
652
|
+
value
|
|
653
|
+
);
|
|
654
|
+
field.onChange(value);
|
|
655
|
+
if (value === "once") {
|
|
656
|
+
setValue("application_method.max_quantity", 1);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "promotion-create-form-allocation-item", children: [
|
|
660
|
+
/* @__PURE__ */ jsx2(Form.Label, { "data-testid": "promotion-create-form-allocation-label", children: t("promotions.fields.allocation") }),
|
|
661
|
+
/* @__PURE__ */ jsx2(Form.Control, { "data-testid": "promotion-create-form-allocation-control", children: /* @__PURE__ */ jsxs(
|
|
662
|
+
RadioGroup,
|
|
663
|
+
{
|
|
664
|
+
dir: direction,
|
|
665
|
+
className: "flex gap-y-3",
|
|
666
|
+
value: allocationMode,
|
|
667
|
+
onValueChange: (val) => handleAllocationChange(val),
|
|
668
|
+
"data-testid": "promotion-create-form-allocation-radio-group",
|
|
669
|
+
children: [
|
|
670
|
+
/* @__PURE__ */ jsx2(
|
|
671
|
+
RadioGroup.ChoiceBox,
|
|
672
|
+
{
|
|
673
|
+
value: "each",
|
|
674
|
+
label: t("promotions.form.allocation.each.title"),
|
|
675
|
+
description: t(
|
|
676
|
+
"promotions.form.allocation.each.description"
|
|
677
|
+
),
|
|
678
|
+
className: clx("basis-1/2"),
|
|
679
|
+
"data-testid": "promotion-create-form-allocation-option-each"
|
|
680
|
+
}
|
|
681
|
+
),
|
|
682
|
+
/* @__PURE__ */ jsx2(
|
|
683
|
+
RadioGroup.ChoiceBox,
|
|
684
|
+
{
|
|
685
|
+
value: "once",
|
|
686
|
+
label: t("promotions.form.allocation.once.title", {
|
|
687
|
+
defaultValue: "Once"
|
|
688
|
+
}),
|
|
689
|
+
description: t(
|
|
690
|
+
"promotions.form.allocation.once.description",
|
|
691
|
+
{
|
|
692
|
+
defaultValue: "Limit discount to max quantity"
|
|
693
|
+
}
|
|
694
|
+
),
|
|
695
|
+
className: clx("basis-1/2"),
|
|
696
|
+
"data-testid": "promotion-create-form-allocation-option-once"
|
|
697
|
+
}
|
|
698
|
+
)
|
|
699
|
+
]
|
|
700
|
+
}
|
|
701
|
+
) }),
|
|
702
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, { "data-testid": "promotion-create-form-allocation-error" })
|
|
703
|
+
] });
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
),
|
|
707
|
+
!isTypeStandard && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
708
|
+
/* @__PURE__ */ jsx2(Divider, {}),
|
|
709
|
+
/* @__PURE__ */ jsx2(
|
|
710
|
+
RulesFormField,
|
|
711
|
+
{
|
|
712
|
+
form,
|
|
713
|
+
ruleType: "buy-rules",
|
|
714
|
+
scope: "application_method.buy_rules"
|
|
715
|
+
}
|
|
716
|
+
)
|
|
717
|
+
] }),
|
|
718
|
+
!isTargetTypeOrder && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
719
|
+
/* @__PURE__ */ jsx2(Divider, {}),
|
|
720
|
+
/* @__PURE__ */ jsx2(
|
|
721
|
+
RulesFormField,
|
|
722
|
+
{
|
|
723
|
+
form,
|
|
724
|
+
ruleType: "target-rules",
|
|
725
|
+
scope: "application_method.target_rules"
|
|
726
|
+
}
|
|
727
|
+
)
|
|
728
|
+
] })
|
|
729
|
+
] }) });
|
|
730
|
+
};
|
|
731
|
+
Root2._tabMeta = defineTabMeta({
|
|
732
|
+
id: "promotion",
|
|
733
|
+
labelKey: "promotions.tabs.details",
|
|
734
|
+
validationFields: [
|
|
735
|
+
"is_automatic",
|
|
736
|
+
"code",
|
|
737
|
+
"type",
|
|
738
|
+
"status",
|
|
739
|
+
"rules",
|
|
740
|
+
"is_tax_inclusive",
|
|
741
|
+
"application_method"
|
|
742
|
+
]
|
|
743
|
+
});
|
|
744
|
+
var PromotionDetailsTab = Root2;
|
|
745
|
+
|
|
746
|
+
// src/pages/promotions/promotion-create/components/create-promotion-form/promotion-template-tab.tsx
|
|
747
|
+
import { RadioGroup as RadioGroup2 } from "@medusajs/ui";
|
|
748
|
+
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
749
|
+
|
|
750
|
+
// src/pages/promotions/promotion-create/components/create-promotion-form/templates.ts
|
|
751
|
+
var commonHiddenFields = [
|
|
752
|
+
"type",
|
|
753
|
+
"application_method.type"
|
|
754
|
+
];
|
|
755
|
+
var amountOfOrderHiddenFields = [...commonHiddenFields];
|
|
756
|
+
var amountOfProductHiddenFields = [...commonHiddenFields];
|
|
757
|
+
var percentageOfOrderHiddenFields = [
|
|
758
|
+
...commonHiddenFields,
|
|
759
|
+
"is_tax_inclusive"
|
|
760
|
+
];
|
|
761
|
+
var percentageOfProductHiddenFields = [
|
|
762
|
+
...commonHiddenFields,
|
|
763
|
+
"is_tax_inclusive"
|
|
764
|
+
];
|
|
765
|
+
var buyGetHiddenFields = [
|
|
766
|
+
...commonHiddenFields,
|
|
767
|
+
"application_method.value",
|
|
768
|
+
"is_tax_inclusive"
|
|
769
|
+
];
|
|
770
|
+
var freeShippingHiddenFields = [
|
|
771
|
+
...commonHiddenFields,
|
|
772
|
+
"application_method.value",
|
|
773
|
+
"application_method.allocation",
|
|
774
|
+
"is_tax_inclusive"
|
|
775
|
+
];
|
|
776
|
+
var templates = [
|
|
777
|
+
{
|
|
778
|
+
id: "amount_off_products",
|
|
779
|
+
type: "standard",
|
|
780
|
+
title: "Amount off products",
|
|
781
|
+
description: "Discount specific products or collection of products",
|
|
782
|
+
hiddenFields: amountOfProductHiddenFields,
|
|
783
|
+
defaults: {
|
|
784
|
+
is_automatic: "false",
|
|
785
|
+
type: "standard",
|
|
786
|
+
application_method: {
|
|
787
|
+
allocation: "each",
|
|
788
|
+
target_type: "items",
|
|
789
|
+
type: "fixed"
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
id: "amount_off_order",
|
|
795
|
+
type: "standard",
|
|
796
|
+
title: "Amount off order",
|
|
797
|
+
description: "Discounts the total order amount",
|
|
798
|
+
hiddenFields: amountOfOrderHiddenFields,
|
|
799
|
+
defaults: {
|
|
800
|
+
is_automatic: "false",
|
|
801
|
+
type: "standard",
|
|
802
|
+
application_method: {
|
|
803
|
+
allocation: "across",
|
|
804
|
+
target_type: "order",
|
|
805
|
+
type: "fixed"
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
id: "percentage_off_product",
|
|
811
|
+
type: "standard",
|
|
812
|
+
title: "Percentage off product",
|
|
813
|
+
description: "Discounts a percentage off selected products",
|
|
814
|
+
hiddenFields: percentageOfProductHiddenFields,
|
|
815
|
+
defaults: {
|
|
816
|
+
is_automatic: "false",
|
|
817
|
+
type: "standard",
|
|
818
|
+
application_method: {
|
|
819
|
+
allocation: "each",
|
|
820
|
+
target_type: "items",
|
|
821
|
+
type: "percentage"
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
id: "percentage_off_order",
|
|
827
|
+
type: "standard",
|
|
828
|
+
title: "Percentage off order",
|
|
829
|
+
description: "Discounts a percentage of the total order amount",
|
|
830
|
+
hiddenFields: percentageOfOrderHiddenFields,
|
|
831
|
+
defaults: {
|
|
832
|
+
is_automatic: "false",
|
|
833
|
+
type: "standard",
|
|
834
|
+
application_method: {
|
|
835
|
+
allocation: "across",
|
|
836
|
+
target_type: "order",
|
|
837
|
+
type: "percentage"
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
id: "buy_get",
|
|
843
|
+
type: "buy_get",
|
|
844
|
+
title: "Buy X Get Y",
|
|
845
|
+
description: "Buy X product(s), get Y product(s)",
|
|
846
|
+
hiddenFields: buyGetHiddenFields,
|
|
847
|
+
defaults: {
|
|
848
|
+
is_automatic: "false",
|
|
849
|
+
type: "buyget",
|
|
850
|
+
application_method: {
|
|
851
|
+
type: "percentage",
|
|
852
|
+
value: 100,
|
|
853
|
+
apply_to_quantity: 1,
|
|
854
|
+
max_quantity: 1
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
id: "shipping_discount",
|
|
860
|
+
type: "standard",
|
|
861
|
+
title: "Free shipping",
|
|
862
|
+
description: "Applies a 100% discount to shipping fees",
|
|
863
|
+
hiddenFields: freeShippingHiddenFields,
|
|
864
|
+
defaults: {
|
|
865
|
+
is_automatic: "false",
|
|
866
|
+
type: "standard",
|
|
867
|
+
application_method: {
|
|
868
|
+
allocation: "across",
|
|
869
|
+
target_type: "shipping_methods",
|
|
870
|
+
type: "percentage",
|
|
871
|
+
value: 100
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
];
|
|
876
|
+
|
|
877
|
+
// src/pages/promotions/promotion-create/components/create-promotion-form/promotion-template-tab.tsx
|
|
878
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
879
|
+
var Root3 = () => {
|
|
880
|
+
const { t } = useTranslation2();
|
|
881
|
+
const direction = useDocumentDirection();
|
|
882
|
+
const form = useTabbedForm();
|
|
883
|
+
return /* @__PURE__ */ jsx3("div", { className: "flex size-full flex-col items-center", children: /* @__PURE__ */ jsx3("div", { className: "w-full max-w-[720px] py-16", children: /* @__PURE__ */ jsx3(
|
|
884
|
+
Form.Field,
|
|
885
|
+
{
|
|
886
|
+
control: form.control,
|
|
887
|
+
name: "template_id",
|
|
888
|
+
render: ({ field }) => {
|
|
889
|
+
return /* @__PURE__ */ jsxs2(Form.Item, { "data-testid": "promotion-create-form-template-item", children: [
|
|
890
|
+
/* @__PURE__ */ jsx3(Form.Label, { "data-testid": "promotion-create-form-template-label", children: t("promotions.fields.type") }),
|
|
891
|
+
/* @__PURE__ */ jsx3(Form.Control, { "data-testid": "promotion-create-form-template-control", children: /* @__PURE__ */ jsx3(
|
|
892
|
+
RadioGroup2,
|
|
893
|
+
{
|
|
894
|
+
dir: direction,
|
|
895
|
+
className: "flex-col gap-y-3",
|
|
896
|
+
...field,
|
|
897
|
+
onValueChange: field.onChange,
|
|
898
|
+
"data-testid": "promotion-create-form-template-radio-group",
|
|
899
|
+
children: templates.map((template) => {
|
|
900
|
+
return /* @__PURE__ */ jsx3(
|
|
901
|
+
RadioGroup2.ChoiceBox,
|
|
902
|
+
{
|
|
903
|
+
value: template.id,
|
|
904
|
+
label: template.title,
|
|
905
|
+
description: template.description,
|
|
906
|
+
"data-testid": `promotion-create-form-template-option-${template.id}`
|
|
907
|
+
},
|
|
908
|
+
template.id
|
|
909
|
+
);
|
|
910
|
+
})
|
|
911
|
+
},
|
|
912
|
+
"template_id"
|
|
913
|
+
) }),
|
|
914
|
+
/* @__PURE__ */ jsx3(Form.ErrorMessage, { "data-testid": "promotion-create-form-template-error" })
|
|
915
|
+
] });
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
) }) });
|
|
919
|
+
};
|
|
920
|
+
Root3._tabMeta = defineTabMeta({
|
|
921
|
+
id: "type",
|
|
922
|
+
labelKey: "promotions.tabs.template",
|
|
923
|
+
validationFields: ["template_id"]
|
|
924
|
+
});
|
|
925
|
+
var PromotionTemplateTab = Root3;
|
|
926
|
+
|
|
927
|
+
// src/pages/promotions/promotion-create/components/create-promotion-form/create-promotion-form.tsx
|
|
928
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
929
|
+
var PROMOTION_CREATE_DEFAULTS = {
|
|
930
|
+
campaign_id: void 0,
|
|
931
|
+
template_id: templates[0].id,
|
|
932
|
+
campaign_choice: "none",
|
|
933
|
+
is_automatic: "false",
|
|
934
|
+
code: "",
|
|
935
|
+
type: "standard",
|
|
936
|
+
status: "draft",
|
|
937
|
+
rules: [],
|
|
938
|
+
is_tax_inclusive: false,
|
|
939
|
+
application_method: {
|
|
940
|
+
allocation: "each",
|
|
941
|
+
type: "fixed",
|
|
942
|
+
target_type: "items",
|
|
943
|
+
max_quantity: 1,
|
|
944
|
+
target_rules: [],
|
|
945
|
+
buy_rules: []
|
|
946
|
+
},
|
|
947
|
+
campaign: void 0
|
|
948
|
+
};
|
|
949
|
+
function CreatePromotionForm({
|
|
950
|
+
children,
|
|
951
|
+
schema,
|
|
952
|
+
defaultValues: extraDefaults
|
|
953
|
+
}) {
|
|
954
|
+
const { t } = useTranslation3();
|
|
955
|
+
const { handleSuccess } = useRouteModal();
|
|
956
|
+
const form = useForm({
|
|
957
|
+
defaultValues: {
|
|
958
|
+
...PROMOTION_CREATE_DEFAULTS,
|
|
959
|
+
...extraDefaults
|
|
960
|
+
},
|
|
961
|
+
resolver: zodResolver(schema ?? CreatePromotionSchema)
|
|
962
|
+
});
|
|
963
|
+
const { setValue, reset, getValues } = form;
|
|
964
|
+
const { mutateAsync: createPromotion, isPending: isLoading } = useCreatePromotion();
|
|
965
|
+
const handleSubmit = form.handleSubmit(
|
|
966
|
+
async (data) => {
|
|
967
|
+
if (data.campaign_choice === "existing" && !data.campaign_id) {
|
|
968
|
+
form.setError("campaign_id", {
|
|
969
|
+
message: t("promotions.errors.requiredField")
|
|
970
|
+
});
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
const {
|
|
974
|
+
campaign_choice: _campaignChoice,
|
|
975
|
+
is_automatic,
|
|
976
|
+
is_tax_inclusive,
|
|
977
|
+
template_id: _templateId,
|
|
978
|
+
application_method,
|
|
979
|
+
rules,
|
|
980
|
+
...promotionData
|
|
981
|
+
} = data;
|
|
982
|
+
const {
|
|
983
|
+
target_rules: targetRulesData = [],
|
|
984
|
+
buy_rules: buyRulesData = [],
|
|
985
|
+
...applicationMethodData
|
|
986
|
+
} = application_method;
|
|
987
|
+
const allocationTyped = applicationMethodData.allocation;
|
|
988
|
+
const disguisedRules = [
|
|
989
|
+
...targetRulesData.filter((r) => !!r.disguised),
|
|
990
|
+
...buyRulesData.filter((r) => !!r.disguised),
|
|
991
|
+
...rules.filter((r) => !!r.disguised)
|
|
992
|
+
];
|
|
993
|
+
const applicationMethodRuleData = {};
|
|
994
|
+
for (const rule of disguisedRules) {
|
|
995
|
+
applicationMethodRuleData[rule.attribute] = rule.field_type === "number" ? parseInt(rule.values) : rule.values;
|
|
996
|
+
}
|
|
997
|
+
const buildRulesData = (rules2) => {
|
|
998
|
+
return rules2.filter((r) => !r.disguised).map((rule) => ({
|
|
999
|
+
operator: rule.operator,
|
|
1000
|
+
attribute: rule.attribute,
|
|
1001
|
+
values: rule.values
|
|
1002
|
+
}));
|
|
1003
|
+
};
|
|
1004
|
+
if (data.campaign) {
|
|
1005
|
+
data.campaign.budget.attribute = data.campaign.budget.attribute || null;
|
|
1006
|
+
data.campaign.budget.type = data.campaign.budget.attribute ? "use_by_attribute" : data.campaign.budget.type;
|
|
1007
|
+
}
|
|
1008
|
+
await createPromotion(
|
|
1009
|
+
{
|
|
1010
|
+
...promotionData,
|
|
1011
|
+
rules: buildRulesData(rules),
|
|
1012
|
+
application_method: {
|
|
1013
|
+
...applicationMethodData,
|
|
1014
|
+
allocation: allocationTyped,
|
|
1015
|
+
...applicationMethodRuleData,
|
|
1016
|
+
value: parseFloat(applicationMethodData.value),
|
|
1017
|
+
target_rules: buildRulesData(targetRulesData),
|
|
1018
|
+
buy_rules: buildRulesData(buyRulesData),
|
|
1019
|
+
max_quantity: allocationTyped === "across" ? void 0 : applicationMethodData.max_quantity
|
|
1020
|
+
},
|
|
1021
|
+
is_tax_inclusive,
|
|
1022
|
+
is_automatic: is_automatic === "true"
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
onSuccess: ({ promotion }) => {
|
|
1026
|
+
toast.success(
|
|
1027
|
+
t("promotions.toasts.promotionCreateSuccess", {
|
|
1028
|
+
code: promotion.code
|
|
1029
|
+
})
|
|
1030
|
+
);
|
|
1031
|
+
handleSuccess(`/promotions/${promotion.id}`);
|
|
1032
|
+
},
|
|
1033
|
+
onError: (e) => {
|
|
1034
|
+
toast.error(e.message);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
);
|
|
1038
|
+
},
|
|
1039
|
+
async (error) => {
|
|
1040
|
+
const { campaign: _campaign, ...rest } = error || {};
|
|
1041
|
+
const errorInPromotionTab = !!Object.keys(rest || {}).length;
|
|
1042
|
+
if (errorInPromotionTab) {
|
|
1043
|
+
toast.error(t("promotions.errors.promotionTabError"));
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
);
|
|
1047
|
+
const watchTemplateId = useWatch3({
|
|
1048
|
+
control: form.control,
|
|
1049
|
+
name: "template_id"
|
|
1050
|
+
});
|
|
1051
|
+
const currentTemplate = useMemo(() => {
|
|
1052
|
+
const currentTemplate2 = templates.find(
|
|
1053
|
+
(template) => template.id === watchTemplateId
|
|
1054
|
+
);
|
|
1055
|
+
if (!currentTemplate2) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
reset({
|
|
1059
|
+
...PROMOTION_CREATE_DEFAULTS,
|
|
1060
|
+
...extraDefaults,
|
|
1061
|
+
template_id: watchTemplateId
|
|
1062
|
+
});
|
|
1063
|
+
for (const [key, value] of Object.entries(currentTemplate2.defaults)) {
|
|
1064
|
+
if (typeof value === "object") {
|
|
1065
|
+
for (const [subKey, subValue] of Object.entries(
|
|
1066
|
+
value
|
|
1067
|
+
)) {
|
|
1068
|
+
setValue(`application_method.${subKey}`, subValue);
|
|
1069
|
+
}
|
|
1070
|
+
} else {
|
|
1071
|
+
setValue(key, value);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
return currentTemplate2;
|
|
1075
|
+
}, [watchTemplateId, setValue, reset]);
|
|
1076
|
+
const watchCampaignChoice = useWatch3({
|
|
1077
|
+
control: form.control,
|
|
1078
|
+
name: "campaign_choice"
|
|
1079
|
+
});
|
|
1080
|
+
useEffect2(() => {
|
|
1081
|
+
const formData = getValues();
|
|
1082
|
+
if (watchCampaignChoice !== "existing") {
|
|
1083
|
+
setValue("campaign_id", void 0);
|
|
1084
|
+
form.clearErrors("campaign_id");
|
|
1085
|
+
}
|
|
1086
|
+
if (watchCampaignChoice !== "new") {
|
|
1087
|
+
setValue("campaign", void 0);
|
|
1088
|
+
}
|
|
1089
|
+
if (watchCampaignChoice === "new") {
|
|
1090
|
+
if (!formData.campaign || !formData.campaign?.budget?.type) {
|
|
1091
|
+
setValue("campaign", {
|
|
1092
|
+
...DEFAULT_CAMPAIGN_VALUES,
|
|
1093
|
+
budget: {
|
|
1094
|
+
...DEFAULT_CAMPAIGN_VALUES.budget,
|
|
1095
|
+
type: DEFAULT_CAMPAIGN_VALUES.budget.type,
|
|
1096
|
+
currency_code: formData.application_method.currency_code
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}, [watchCampaignChoice, getValues, setValue, form]);
|
|
1102
|
+
const watchRules = useWatch3({
|
|
1103
|
+
control: form.control,
|
|
1104
|
+
name: "rules"
|
|
1105
|
+
});
|
|
1106
|
+
const watchCurrencyRule = watchRules.find(
|
|
1107
|
+
(rule) => rule.attribute === "currency_code"
|
|
1108
|
+
);
|
|
1109
|
+
if (watchCurrencyRule) {
|
|
1110
|
+
const formData = form.getValues();
|
|
1111
|
+
const currencyCode = formData.application_method.currency_code;
|
|
1112
|
+
const ruleValue = watchCurrencyRule.values;
|
|
1113
|
+
if (!Array.isArray(ruleValue) && currencyCode !== ruleValue) {
|
|
1114
|
+
form.setValue("application_method.currency_code", ruleValue);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
const defaultTabs = useMemo(
|
|
1118
|
+
() => [
|
|
1119
|
+
/* @__PURE__ */ jsx4(PromotionTemplateTab, {}, "type"),
|
|
1120
|
+
/* @__PURE__ */ jsx4(PromotionDetailsTab, { currentTemplate }, "promotion"),
|
|
1121
|
+
/* @__PURE__ */ jsx4(PromotionCampaignTab, {}, "campaign")
|
|
1122
|
+
],
|
|
1123
|
+
[currentTemplate]
|
|
1124
|
+
);
|
|
1125
|
+
const hasCustomChildren = Children.count(children) > 0;
|
|
1126
|
+
return /* @__PURE__ */ jsx4(
|
|
1127
|
+
TabbedForm,
|
|
1128
|
+
{
|
|
1129
|
+
form,
|
|
1130
|
+
onSubmit: handleSubmit,
|
|
1131
|
+
isLoading,
|
|
1132
|
+
children: hasCustomChildren ? children : defaultTabs
|
|
1133
|
+
}
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
// src/pages/promotions/promotion-create/promotion-create.tsx
|
|
1138
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1139
|
+
var Root4 = ({ children }) => {
|
|
1140
|
+
return /* @__PURE__ */ jsx5(RouteFocusModal, { "data-testid": "promotion-create-modal", children: Children2.count(children) > 0 ? children : /* @__PURE__ */ jsx5(CreatePromotionForm, {}) });
|
|
1141
|
+
};
|
|
1142
|
+
var PromotionCreatePage = Object.assign(Root4, {
|
|
1143
|
+
Form: CreatePromotionForm,
|
|
1144
|
+
TemplateTab: PromotionTemplateTab,
|
|
1145
|
+
DetailsTab: PromotionDetailsTab,
|
|
1146
|
+
CampaignTab: PromotionCampaignTab,
|
|
1147
|
+
Tab: TabbedForm.Tab
|
|
1148
|
+
});
|
|
1149
|
+
var PromotionCreate = Root4;
|
|
1150
|
+
|
|
1151
|
+
export {
|
|
1152
|
+
CreatePromotionSchema,
|
|
1153
|
+
PromotionCreatePage,
|
|
1154
|
+
PromotionCreate
|
|
1155
|
+
};
|