@mercurjs/vendor 2.2.1 → 2.3.0-canary.1
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/[id]-3TCOLUQH.js +197 -0
- package/dist/{[id]-YB3DBBXT.js → [id]-4QVLDR3S.js} +13 -10
- package/dist/{[id]-RJRAZN3T.js → [id]-4VX7CTRZ.js} +8 -6
- package/dist/{[id]-OE5TUWNF.js → [id]-5FP6JZM3.js} +9 -7
- package/dist/[id]-6FEVCKQU.js +949 -0
- package/dist/{[id]-47SUX5X3.js → [id]-7QVJAIDU.js} +13 -10
- package/dist/{[id]-BHU5BSQT.js → [id]-CFVBH66J.js} +20 -17
- package/dist/{[id]-SKU5SFBG.js → [id]-HAJ3735Z.js} +137 -204
- package/dist/{[id]-NGRV5I2A.js → [id]-PBNGQSNY.js} +9 -7
- package/dist/[id]-QGZ26C6D.js +286 -0
- package/dist/{[id]-ZD5HBP2R.js → [id]-RAJUZUNH.js} +13 -10
- package/dist/[id]-RJ3MUR4M.js +697 -0
- package/dist/{[id]-PIB2DEVI.js → [id]-RRVYKA7U.js} +12 -9
- package/dist/{[id]-BPQNQFVE.js → [id]-Y4HRAAV2.js} +75 -124
- package/dist/{[province_id]-CUWKNPBW.js → [province_id]-VWN4OOGM.js} +9 -7
- package/dist/{add-MYV5IOGP.js → add-57LM6WKL.js} +157 -227
- package/dist/{add-YEUSE5QA.js → add-7HIVF77P.js} +10 -8
- package/dist/{add-customer-groups-Q3F357F2.js → add-customer-groups-VJYI5J5Z.js} +8 -6
- package/dist/{add-products-WVNYODC6.js → add-products-XWU5ZUTZ.js} +13 -10
- package/dist/{add-promotions-F62YE3BE.js → add-promotions-DOJS6CEE.js} +27 -9
- package/dist/{add-to-campaign-WBSCTSKW.js → add-to-campaign-B3PGGNFA.js} +3 -2
- package/dist/{address-ZMZ4ST5T.js → address-X4TXBPUG.js} +7 -5
- package/dist/{adjust-inventory-QUGKDXOC.js → adjust-inventory-2OKDFVLK.js} +2 -3
- package/dist/{allocate-items-7NSBGXSF.js → allocate-items-QAYROQMK.js} +4 -2
- package/dist/{areas-EJCZBY2E.js → areas-WQ44GWQO.js} +2 -2
- package/dist/{breadcrumb-M657ZCG6.js → breadcrumb-4I7MU2QY.js} +1 -1
- package/dist/{breadcrumb-KNBZ3JNR.js → breadcrumb-7ZFC43R4.js} +1 -1
- package/dist/{breadcrumb-C7M5PG2Q.js → breadcrumb-HMW2K4DW.js} +7 -5
- package/dist/{breadcrumb-KLNC72RI.js → breadcrumb-MH2L34OD.js} +2 -2
- package/dist/{breadcrumb-QPV566YX.js → breadcrumb-Q7FS3IDL.js} +8 -6
- package/dist/{breadcrumb-JWFTKHLE.js → breadcrumb-RQ52GELM.js} +2 -1
- package/dist/{breadcrumb-M6NW3DRQ.js → breadcrumb-WBUUK3AP.js} +1 -1
- package/dist/breadcrumb-XCPUUZUO.js +26 -0
- package/dist/{breadcrumb-MXYWEBK6.js → breadcrumb-Z2QUGZM3.js} +7 -5
- package/dist/{campaigns-BPLAE6QQ.js → campaigns-LIPKZKI7.js} +5 -4
- package/dist/{categories-H2XAJCGC.js → categories-D2U6VLH5.js} +2 -2
- package/dist/{chunk-4RVWITM2.js → chunk-3JWHERV7.js} +76 -23
- package/dist/{chunk-BCXREBMV.js → chunk-4ATO577Q.js} +1 -1
- package/dist/{chunk-VHFKJLDH.js → chunk-4JVORTN4.js} +1 -1
- package/dist/{chunk-HHD2VUED.js → chunk-4UKAKFKL.js} +1 -1
- package/dist/{chunk-3L7WHWKB.js → chunk-5DRYAIOY.js} +3 -3
- package/dist/{chunk-7TIZP4YG.js → chunk-5RWK4U4V.js} +26 -0
- package/dist/{chunk-XQUF3WIS.js → chunk-5ZHZVKNQ.js} +4 -0
- package/dist/{chunk-IWAL74YU.js → chunk-6GQLSWOO.js} +1 -1
- package/dist/{chunk-HCUIYIIY.js → chunk-6OZQTHCR.js} +1 -1
- package/dist/chunk-6XMUN2BZ.js +0 -0
- package/dist/{chunk-RLRWDHME.js → chunk-6YQR2AWM.js} +3 -20
- package/dist/{chunk-26OOAKQ6.js → chunk-7H6NMQ6U.js} +8 -1
- package/dist/{chunk-OKJHUQBY.js → chunk-7JVJIAWS.js} +17 -29
- package/dist/chunk-7LIENHWP.js +26 -0
- package/dist/{chunk-EPSRO7C5.js → chunk-7LIT4GXO.js} +2 -2
- package/dist/chunk-7POOMBIN.js +108 -0
- package/dist/{chunk-PF7R7LMW.js → chunk-AHR2FIMC.js} +22 -0
- package/dist/{chunk-EJBOBB4B.js → chunk-AQT2G6K2.js} +46 -46
- package/dist/{chunk-UEKRQS5Q.js → chunk-ATYOOL7K.js} +2 -2
- package/dist/chunk-BR6PEFXX.js +27 -0
- package/dist/{chunk-SDFZUBS3.js → chunk-CDZALZ5E.js} +1 -1
- package/dist/{chunk-3XW55FZY.js → chunk-CRVVPIFZ.js} +6 -6
- package/dist/{chunk-72HQFLZI.js → chunk-CSEB2RNO.js} +1 -1
- package/dist/{chunk-X6ZQMFCT.js → chunk-DAOSTHVB.js} +44 -25
- package/dist/{chunk-UUBGLS7U.js → chunk-EWJTXSKI.js} +211 -36
- package/dist/chunk-FKKI62AC.js +282 -0
- package/dist/{chunk-VBKW4GWP.js → chunk-FPBXQIFJ.js} +1 -1
- package/dist/{chunk-SI55QRZ4.js → chunk-G5NNOOHR.js} +59 -6
- package/dist/chunk-G6J5ZKM3.js +31 -0
- package/dist/{chunk-U5V6HNVW.js → chunk-GL3XVUAY.js} +1 -1
- package/dist/{chunk-RJE4MAYB.js → chunk-GYLRZXWS.js} +1 -1
- package/dist/{chunk-SVYBMLVN.js → chunk-HHCLMWXT.js} +1 -1
- package/dist/{chunk-YUQA6TUA.js → chunk-JOCO7JOB.js} +3 -3
- package/dist/{chunk-OGUTFP6B.js → chunk-JYUHDM23.js} +13 -51
- package/dist/{chunk-QB7BI4B7.js → chunk-K2DXXPNA.js} +153 -86
- package/dist/{chunk-XG76XXM2.js → chunk-KKMA6VPG.js} +1 -1
- package/dist/chunk-KVAD5JGS.js +11 -0
- package/dist/{chunk-YRZ53SAN.js → chunk-L26J5MO2.js} +2 -2
- package/dist/{chunk-63XYNXUL.js → chunk-LYP7XK5O.js} +1 -1
- package/dist/chunk-MVVFD2JT.js +51 -0
- package/dist/{chunk-RVFPWOR2.js → chunk-MY5H7C3A.js} +2 -2
- package/dist/{chunk-3GSR455R.js → chunk-NQMHP2LC.js} +1 -1
- package/dist/{chunk-2S2WK2OG.js → chunk-NV2RZAHW.js} +1 -10
- package/dist/{chunk-4IIATKG7.js → chunk-O7OWHKWA.js} +6 -6
- package/dist/{chunk-GIKVFOQL.js → chunk-OJCMHDZI.js} +2 -2
- package/dist/chunk-QLOJNFUE.js +53 -0
- package/dist/{chunk-GTNCNKTC.js → chunk-RBWIHKUF.js} +1 -1
- package/dist/{chunk-XVBONKRV.js → chunk-RCMKDW6O.js} +1 -1
- package/dist/{chunk-WJF24CGA.js → chunk-RDLVH6CM.js} +33 -5
- package/dist/chunk-SF5N2HX4.js +268 -0
- package/dist/{chunk-MQR26KYT.js → chunk-SYHA2RVL.js} +1 -1
- package/dist/{chunk-ZXDMPIXN.js → chunk-U3OEGBHH.js} +2 -2
- package/dist/chunk-UTGI6R2X.js +334 -0
- package/dist/{chunk-VBRTC2VU.js → chunk-VAFGNDAP.js} +4 -3
- package/dist/{chunk-4UQMRTSC.js → chunk-VH3TGSWE.js} +46 -2
- package/dist/{chunk-ZEKV7LGF.js → chunk-VV2K3EBF.js} +1 -1
- package/dist/{chunk-S2VYK3YC.js → chunk-WI2ZAFZF.js} +1 -1
- package/dist/chunk-WP3B4NEU.js +32 -0
- package/dist/{chunk-DY3XQPHC.js → chunk-WW2XYOHJ.js} +5 -3
- package/dist/{chunk-IVYIMGQC.js → chunk-X44P463Q.js} +45 -10
- package/dist/{chunk-FEVCBT24.js → chunk-X4G64W5Q.js} +2 -2
- package/dist/{chunk-R5KN6IFB.js → chunk-XHWBTV72.js} +2 -2
- package/dist/{chunk-OVHIUZ3K.js → chunk-XQ47NZJC.js} +1 -1
- package/dist/{chunk-LN7XHEPJ.js → chunk-YT4RAUWM.js} +2 -2
- package/dist/{chunk-6VKJM537.js → chunk-ZK4DIDXG.js} +1 -1
- package/dist/{collections-52DJLHWW.js → collections-5TH7H2QP.js} +14 -13
- package/dist/{configuration-UMRBE5RQ.js → configuration-QK2FW2CV.js} +2 -2
- package/dist/{configuration-QEDVL2WF.js → configuration-RYH3VUBV.js} +15 -48
- package/dist/{create-ALUKAFJS.js → create-5M66YUYY.js} +2 -2
- package/dist/{create-ABRPUMHQ.js → create-A6KZEZMH.js} +7 -6
- package/dist/{create-LYNWCP2N.js → create-BTODQ4T4.js} +6 -5
- package/dist/{create-2I3GAX4C.js → create-FI6H4AJE.js} +16 -7
- package/dist/{create-6IRD2CVC.js → create-GF76Z5I7.js} +15 -13
- package/dist/create-ICCAEOSA.js +343 -0
- package/dist/{create-NTZH45DW.js → create-JZLU44WB.js} +14 -12
- package/dist/{create-GEYXN6SW.js → create-ME43PNL6.js} +7 -5
- package/dist/{create-MFGMTZ5A.js → create-MIYJCLAJ.js} +8 -6
- package/dist/{create-7SJ5DSQK.js → create-PRDQJ5WI.js} +20 -17
- package/dist/{create-S7VYYTUD.js → create-Q6B6JR4K.js} +10 -8
- package/dist/{create-5RQ32XPT.js → create-SKQAJNDF.js} +287 -287
- package/dist/{create-7FT7N2NH.js → create-WPN3OUJU.js} +3 -2
- package/dist/{create-H77ZUZG5.js → create-XBGN6XEF.js} +10 -8
- package/dist/{create-G76MVCJU.js → create-ZVGYET6W.js} +5 -4
- package/dist/customer-availability-VAOKKCTK.js +164 -0
- package/dist/{customer-group-add-customers-T7OYWJCB.js → customer-group-add-customers-BSMUKWVO.js} +1 -1
- package/dist/{customer-group-detail-E7HRZ3LE.js → customer-group-detail-QCPC2YWK.js} +2 -2
- package/dist/{customer-groups-26HJ55MF.js → customer-groups-6WGUNFHG.js} +2 -2
- package/dist/{customers-EXFRZX5F.js → customers-7OGYQSGA.js} +2 -2
- package/dist/edit-2BKYNGYL.js +262 -0
- package/dist/{edit-WHGYNDEB.js → edit-3S3EH372.js} +20 -17
- package/dist/{edit-MPOTIGUY.js → edit-4WP5SGH6.js} +23 -39
- package/dist/{edit-QBUYHSE7.js → edit-7D2OZBJS.js} +8 -6
- package/dist/{edit-2RN3OT27.js → edit-7T2JMZG3.js} +7 -56
- package/dist/edit-AK4E63X6.js +179 -0
- package/dist/{edit-NB5VN2E4.js → edit-DRT6VOAA.js} +5 -4
- package/dist/{edit-EGBVEWXS.js → edit-GBDHDJK4.js} +9 -7
- package/dist/{edit-TIBQEQVV.js → edit-P7FNRVGB.js} +10 -8
- package/dist/{edit-6VJWRZHQ.js → edit-PZN7UAJI.js} +7 -5
- package/dist/{edit-M4AP65HO.js → edit-RNSXXJVU.js} +8 -6
- package/dist/edit-SKRFQ4WN.js +81 -0
- package/dist/{edit-H5FJ45ZT.js → edit-ZM7NJVRE.js} +1 -1
- package/dist/{edit-budget-PYPHUJPW.js → edit-budget-MOZETGZV.js} +1 -1
- package/dist/{edit-inventory-item-BCVECCLT.js → edit-inventory-item-HFGHS732.js} +17 -14
- package/dist/{edit-inventory-item-attributes-GWEMP67O.js → edit-inventory-item-attributes-5ORZJF4I.js} +18 -1
- package/dist/{edit-price-GLAEAO7R.js → edit-price-KY7LX5QA.js} +2 -2
- package/dist/edit-reservation-LSYQUDYQ.js +294 -0
- package/dist/{edit-stock-E3PM2YOP.js → edit-stock-77VKJR4Z.js} +2 -2
- package/dist/extension-targets.d.ts +6 -3
- package/dist/{fulfillment-HDU7GATG.js → fulfillment-DEGKZL42.js} +7 -5
- package/dist/{fulfillment-providers-6RZNNT7U.js → fulfillment-providers-LDFPZGNX.js} +12 -11
- package/dist/index.css +17 -14
- package/dist/index.js +265 -155
- package/dist/{inventory-XJ2E6DPC.js → inventory-CMIRAJJY.js} +2 -2
- package/dist/{inventory-CKA34HWM.js → inventory-RKAUTQAU.js} +2 -2
- package/dist/{invite-755AJC3M.js → invite-KAHF2MCE.js} +7 -5
- package/dist/{invite-FD2TXZTW.js → invite-S5O7LFEY.js} +10 -8
- package/dist/{loader-UUSAVCK6.js → loader-3BXYSKPT.js} +1 -1
- package/dist/{loader-B4T2VBGV.js → loader-CF54CDM6.js} +2 -2
- package/dist/{login-UGKYRKMD.js → login-CRSALS6Y.js} +9 -7
- package/dist/manage-items-63FPRK7Z.js +302 -0
- package/dist/{manage-locations-PRQI5TI4.js → manage-locations-5B4HP6NQ.js} +24 -5
- package/dist/{media-TGFAHFBV.js → media-74PEXOLV.js} +8 -6
- package/dist/{media-2KEHXPRU.js → media-NKCXFG6X.js} +11 -9
- package/dist/{metadata-7JWZ4VFM.js → metadata-22BCBKVE.js} +7 -5
- package/dist/{metadata-BQQFHVKF.js → metadata-E3BDAMIO.js} +7 -5
- package/dist/{metadata-5TVRCKWX.js → metadata-FRXIY35J.js} +7 -5
- package/dist/{metadata-4ZZ4ZIWJ.js → metadata-L6IA2Z26.js} +7 -5
- package/dist/metadata-WN6Y35RV.js +69 -0
- package/dist/{metadata-G73TILNE.js → metadata-ZZMJNWS3.js} +7 -5
- package/dist/{offer-create-page-PPXRYET4.js → offer-create-page-N5CKYGSS.js} +12 -9
- package/dist/{offer-detail-page-BFGKAS4L.js → offer-detail-page-AJG6TMJC.js} +3 -3
- package/dist/{offer-variant-detail-page-BLHRF4MK.js → offer-variant-detail-page-CEOS2MVM.js} +40 -8
- package/dist/{offers-7I67VSHI.js → offers-WFJ6UGVG.js} +15 -11
- package/dist/{onboarding-7MURQYXX.js → onboarding-2AZ2KEWJ.js} +7 -5
- package/dist/{orders-D7NZNDUS.js → orders-NWYLN6BE.js} +13 -12
- package/dist/{organization-T6ZTYMMW.js → organization-PAWIWKHV.js} +9 -7
- package/dist/pages/index.d.ts +9 -1
- package/dist/pages/index.js +57 -48
- package/dist/{payment-details-UQ65D5AY.js → payment-details-O57HNHWS.js} +7 -5
- package/dist/{payouts-A336D2HG.js → payouts-26ZOYDRP.js} +2 -2
- package/dist/{price-lists-3WRT4TR2.js → price-lists-U5ASDHMI.js} +5 -8
- package/dist/{pricing-3NLEJYRP.js → pricing-C425JTFQ.js} +2 -2
- package/dist/{pricing-CPPIL627.js → pricing-PDOCJEDS.js} +9 -7
- package/dist/{product-tags-7DTA73YT.js → product-tags-MMQ4ZR4W.js} +20 -17
- package/dist/{product-types-OB26NF2D.js → product-types-CMI33S32.js} +3 -4
- package/dist/{product-variant-detail-4DDE6RJ5.js → product-variant-detail-D73ILATK.js} +7 -5
- package/dist/{product-variant-edit-SAZUI4E3.js → product-variant-edit-XN6WGKI2.js} +10 -8
- package/dist/{products-RYXTZFGT.js → products-OZJHGW2K.js} +19 -16
- package/dist/{products-GJ2KTGBZ.js → products-VWH5TAFY.js} +13 -10
- package/dist/{professional-details-UN5B4YDJ.js → professional-details-ZJT6YKZB.js} +7 -5
- package/dist/{profile-6MIDTK52.js → profile-EU46MXFW.js} +7 -5
- package/dist/{promotions-SQ47TCZL.js → promotions-ALWQ7J7A.js} +5 -5
- package/dist/{receive-ZG6FFN7H.js → receive-RRZK3FP2.js} +4 -3
- package/dist/{refund-KJX74N6T.js → refund-FLCZAMPR.js} +3 -2
- package/dist/{register-RDSK4E4D.js → register-C6ON6OL2.js} +9 -7
- package/dist/reservations-C326XEVA.js +350 -0
- package/dist/{reset-password-C462PDN2.js → reset-password-ASLKY3GK.js} +1 -1
- package/dist/respond-IPRDCH57.js +132 -0
- package/dist/{return-reasons-MY63HNF6.js → return-reasons-2BUKIQBO.js} +9 -7
- package/dist/reviews-LBLCFBRQ.js +14 -0
- package/dist/{settings-TJ6HPHMK.js → settings-Q5GAL2LK.js} +28 -25
- package/dist/{shipment-6CTA2GHU.js → shipment-XOU6F7AS.js} +7 -5
- package/dist/{shipping-TKKMYQHJ.js → shipping-IMCP7UDV.js} +2 -2
- package/dist/{shipping-profile-CFISOMTE.js → shipping-profile-7P3RPEIJ.js} +1 -1
- package/dist/{shipping-profiles-5UAZNYKJ.js → shipping-profiles-647FLCNK.js} +9 -7
- package/dist/{stock-465GEUY3.js → stock-D3HCV5UR.js} +22 -8
- package/dist/{store-2PQB2XWE.js → store-XBNFP6O4.js} +8 -6
- package/dist/{store-closure-DYW54VHB.js → store-closure-55EUSKE4.js} +7 -5
- package/dist/{store-select-6A5YR7WH.js → store-select-DEOEGT2O.js} +8 -6
- package/dist/{team-GXEBC57M.js → team-7MJ3NJUT.js} +10 -8
- package/package.json +12 -9
- package/dist/[id]-HEVGSOAV.js +0 -598
- package/dist/[id]-MU7A6SZO.js +0 -526
- package/dist/chunk-2ZFELO2L.js +0 -13
- package/dist/chunk-6IJMSVC6.js +0 -16
- package/dist/chunk-BNOKKKUU.js +0 -88
- package/dist/chunk-BX3JE7IE.js +0 -247
- package/dist/edit-4B364HGZ.js +0 -222
- package/dist/edit-735HBYH2.js +0 -103
- package/dist/edit-SQU5UOGE.js +0 -105
- package/dist/{chunk-CYE7HVAV.js → chunk-SCJBJQCL.js} +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CreateCampaignFormFields
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-G5NNOOHR.js";
|
|
4
4
|
import {
|
|
5
5
|
VisuallyHidden
|
|
6
6
|
} from "./chunk-54TMLQH3.js";
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
// src/pages/campaigns/create/create-campaign-form/create-campaign-form.tsx
|
|
19
19
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
20
20
|
import { Button, toast } from "@medusajs/ui";
|
|
21
|
+
import { useMemo } from "react";
|
|
21
22
|
import { useForm } from "react-hook-form";
|
|
22
23
|
import { useTranslation } from "react-i18next";
|
|
23
24
|
import * as zod from "zod";
|
|
@@ -32,7 +33,8 @@ var DEFAULT_CAMPAIGN_VALUES = {
|
|
|
32
33
|
budget: {
|
|
33
34
|
type: "usage",
|
|
34
35
|
currency_code: null,
|
|
35
|
-
limit: null
|
|
36
|
+
limit: null,
|
|
37
|
+
attribute: null
|
|
36
38
|
}
|
|
37
39
|
};
|
|
38
40
|
|
|
@@ -45,8 +47,9 @@ var CreateCampaignSchema = zod.object({
|
|
|
45
47
|
starts_at: zod.date().nullable(),
|
|
46
48
|
ends_at: zod.date().nullable(),
|
|
47
49
|
budget: zod.object({
|
|
50
|
+
attribute: zod.string().nullish(),
|
|
48
51
|
limit: zod.number().min(0).nullish(),
|
|
49
|
-
type: zod.enum(["spend", "usage"]),
|
|
52
|
+
type: zod.enum(["spend", "usage", "use_by_attribute"]),
|
|
50
53
|
currency_code: zod.string().nullish()
|
|
51
54
|
})
|
|
52
55
|
});
|
|
@@ -54,11 +57,35 @@ var CreateCampaignForm = () => {
|
|
|
54
57
|
const { t } = useTranslation();
|
|
55
58
|
const { handleSuccess } = useRouteModal();
|
|
56
59
|
const { mutateAsync, isPending } = useCreateCampaign();
|
|
60
|
+
const schema = useMemo(
|
|
61
|
+
() => zod.object({
|
|
62
|
+
name: zod.string().min(1, t("campaigns.validation.name_required")),
|
|
63
|
+
description: zod.string().optional(),
|
|
64
|
+
campaign_identifier: zod.string().min(1, t("campaigns.validation.identifier_required")),
|
|
65
|
+
starts_at: zod.date().nullable(),
|
|
66
|
+
ends_at: zod.date().nullable(),
|
|
67
|
+
budget: zod.object({
|
|
68
|
+
attribute: zod.string().nullish(),
|
|
69
|
+
limit: zod.number().min(0).nullish(),
|
|
70
|
+
type: zod.enum(["spend", "usage", "use_by_attribute"]),
|
|
71
|
+
currency_code: zod.string().nullish()
|
|
72
|
+
})
|
|
73
|
+
}).refine(
|
|
74
|
+
(data) => data.budget.type !== "spend" || !!data.budget.currency_code,
|
|
75
|
+
{
|
|
76
|
+
message: t("campaigns.validation.currency_required"),
|
|
77
|
+
path: ["budget", "currency_code"]
|
|
78
|
+
}
|
|
79
|
+
),
|
|
80
|
+
[t]
|
|
81
|
+
);
|
|
57
82
|
const form = useForm({
|
|
58
83
|
defaultValues: DEFAULT_CAMPAIGN_VALUES,
|
|
59
|
-
resolver: zodResolver(
|
|
84
|
+
resolver: zodResolver(schema)
|
|
60
85
|
});
|
|
61
86
|
const handleSubmit = form.handleSubmit(async (data) => {
|
|
87
|
+
const attribute = data.budget.attribute || null;
|
|
88
|
+
const type = attribute ? "use_by_attribute" : data.budget.type;
|
|
62
89
|
await mutateAsync(
|
|
63
90
|
{
|
|
64
91
|
name: data.name,
|
|
@@ -67,7 +94,8 @@ var CreateCampaignForm = () => {
|
|
|
67
94
|
starts_at: data.starts_at,
|
|
68
95
|
ends_at: data.ends_at,
|
|
69
96
|
budget: {
|
|
70
|
-
type
|
|
97
|
+
type,
|
|
98
|
+
attribute,
|
|
71
99
|
limit: data.budget.limit ? data.budget.limit : void 0,
|
|
72
100
|
currency_code: data.budget.currency_code
|
|
73
101
|
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StarRating,
|
|
3
|
+
getReviewStatusProps
|
|
4
|
+
} from "./chunk-G6J5ZKM3.js";
|
|
5
|
+
import {
|
|
6
|
+
useReviews
|
|
7
|
+
} from "./chunk-MVVFD2JT.js";
|
|
8
|
+
import {
|
|
9
|
+
StatusCell
|
|
10
|
+
} from "./chunk-DB6ANJBO.js";
|
|
11
|
+
import {
|
|
12
|
+
useCustomers
|
|
13
|
+
} from "./chunk-II3CLUXA.js";
|
|
14
|
+
|
|
15
|
+
// src/pages/reviews/review-list-page.tsx
|
|
16
|
+
import { Children } from "react";
|
|
17
|
+
import { SingleColumnPage } from "@mercurjs/dashboard-shared";
|
|
18
|
+
|
|
19
|
+
// src/pages/reviews/_components/review-list-table/review-list-table.tsx
|
|
20
|
+
import { Container } from "@medusajs/ui";
|
|
21
|
+
|
|
22
|
+
// src/pages/reviews/_components/review-list-table/review-list-header.tsx
|
|
23
|
+
import { useTranslation } from "react-i18next";
|
|
24
|
+
import { Heading } from "@medusajs/ui";
|
|
25
|
+
import { jsx } from "react/jsx-runtime";
|
|
26
|
+
var ReviewListHeader = () => {
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Heading, { children: t("reviews.domain") }) }) });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/pages/reviews/_components/review-list-table/review-list-data-table.tsx
|
|
32
|
+
import { useTranslation as useTranslation4 } from "react-i18next";
|
|
33
|
+
import { keepPreviousData } from "@tanstack/react-query";
|
|
34
|
+
import { Star } from "@medusajs/icons";
|
|
35
|
+
import { _DataTable, useDataTable } from "@mercurjs/dashboard-shared";
|
|
36
|
+
|
|
37
|
+
// src/pages/reviews/_components/review-list-table/use-review-table-columns.tsx
|
|
38
|
+
import { createColumnHelper } from "@tanstack/react-table";
|
|
39
|
+
import { useMemo } from "react";
|
|
40
|
+
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
41
|
+
import { Text } from "@medusajs/ui";
|
|
42
|
+
import { DateCell } from "@mercurjs/dashboard-shared";
|
|
43
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
44
|
+
var columnHelper = createColumnHelper();
|
|
45
|
+
var customerName = (customer) => {
|
|
46
|
+
if (!customer) {
|
|
47
|
+
return "-";
|
|
48
|
+
}
|
|
49
|
+
const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
|
|
50
|
+
return name || customer.email || "-";
|
|
51
|
+
};
|
|
52
|
+
var useReviewTableColumns = () => {
|
|
53
|
+
const { t } = useTranslation2();
|
|
54
|
+
return useMemo(
|
|
55
|
+
() => [
|
|
56
|
+
columnHelper.accessor("display_id", {
|
|
57
|
+
header: () => /* @__PURE__ */ jsx2("span", { children: t("reviews.list.columns.reviewId") }),
|
|
58
|
+
cell: ({ getValue }) => /* @__PURE__ */ jsxs(Text, { size: "small", leading: "compact", className: "truncate", children: [
|
|
59
|
+
"#",
|
|
60
|
+
getValue()
|
|
61
|
+
] })
|
|
62
|
+
}),
|
|
63
|
+
columnHelper.accessor("rating", {
|
|
64
|
+
header: () => /* @__PURE__ */ jsx2("span", { children: t("reviews.list.columns.rating") }),
|
|
65
|
+
cell: ({ getValue }) => /* @__PURE__ */ jsx2(StarRating, { rating: getValue() })
|
|
66
|
+
}),
|
|
67
|
+
columnHelper.accessor("customer_note", {
|
|
68
|
+
header: () => /* @__PURE__ */ jsx2("span", { children: t("reviews.list.columns.content") }),
|
|
69
|
+
cell: ({ getValue }) => /* @__PURE__ */ jsx2("div", { className: "w-[240px]", children: /* @__PURE__ */ jsx2(
|
|
70
|
+
Text,
|
|
71
|
+
{
|
|
72
|
+
size: "small",
|
|
73
|
+
leading: "compact",
|
|
74
|
+
className: "text-ui-fg-subtle line-clamp-3",
|
|
75
|
+
children: getValue() || "-"
|
|
76
|
+
}
|
|
77
|
+
) })
|
|
78
|
+
}),
|
|
79
|
+
columnHelper.accessor("customer", {
|
|
80
|
+
header: () => /* @__PURE__ */ jsx2("span", { children: t("reviews.list.columns.customer") }),
|
|
81
|
+
cell: ({ getValue }) => /* @__PURE__ */ jsx2(Text, { size: "small", leading: "compact", className: "truncate", children: customerName(getValue()) })
|
|
82
|
+
}),
|
|
83
|
+
columnHelper.accessor("created_at", {
|
|
84
|
+
header: () => /* @__PURE__ */ jsx2("span", { children: t("reviews.list.columns.date") }),
|
|
85
|
+
cell: ({ getValue }) => /* @__PURE__ */ jsx2(DateCell, { date: new Date(getValue()) })
|
|
86
|
+
}),
|
|
87
|
+
columnHelper.accessor("status", {
|
|
88
|
+
header: () => /* @__PURE__ */ jsx2("span", { children: t("reviews.list.columns.status") }),
|
|
89
|
+
cell: ({ getValue }) => {
|
|
90
|
+
const { color, label } = getReviewStatusProps(getValue(), t);
|
|
91
|
+
return /* @__PURE__ */ jsx2(StatusCell, { color, children: label });
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
columnHelper.accessor("seller_note", {
|
|
95
|
+
header: () => /* @__PURE__ */ jsx2("span", { children: t("reviews.list.columns.response") }),
|
|
96
|
+
cell: ({ getValue }) => /* @__PURE__ */ jsx2("div", { className: "w-[240px]", children: /* @__PURE__ */ jsx2(
|
|
97
|
+
Text,
|
|
98
|
+
{
|
|
99
|
+
size: "small",
|
|
100
|
+
leading: "compact",
|
|
101
|
+
className: "text-ui-fg-subtle line-clamp-3",
|
|
102
|
+
children: getValue() || "-"
|
|
103
|
+
}
|
|
104
|
+
) })
|
|
105
|
+
})
|
|
106
|
+
],
|
|
107
|
+
[t]
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// src/pages/reviews/_components/review-list-table/use-review-table-query.tsx
|
|
112
|
+
import { useQueryParams } from "@mercurjs/dashboard-shared";
|
|
113
|
+
var useReviewTableQuery = ({
|
|
114
|
+
prefix,
|
|
115
|
+
pageSize = 20
|
|
116
|
+
}) => {
|
|
117
|
+
const queryObject = useQueryParams(
|
|
118
|
+
["offset", "q", "status", "rating", "customer_id", "created_at", "order"],
|
|
119
|
+
prefix
|
|
120
|
+
);
|
|
121
|
+
const { offset, status, rating, customer_id, created_at, q, order } = queryObject;
|
|
122
|
+
const searchParams = {
|
|
123
|
+
limit: pageSize,
|
|
124
|
+
offset: offset ? Number(offset) : 0,
|
|
125
|
+
status: status ? status.split(",") : void 0,
|
|
126
|
+
rating: rating ? rating.split(",").map(Number) : void 0,
|
|
127
|
+
customer_id: customer_id ? customer_id.split(",") : void 0,
|
|
128
|
+
created_at: created_at ? JSON.parse(created_at) : void 0,
|
|
129
|
+
order: order ? order : "-display_id",
|
|
130
|
+
q
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
searchParams,
|
|
134
|
+
raw: queryObject
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/pages/reviews/_components/review-list-table/use-review-table-filters.tsx
|
|
139
|
+
import { useTranslation as useTranslation3 } from "react-i18next";
|
|
140
|
+
import { useMemo as useMemo2 } from "react";
|
|
141
|
+
var customerLabel = (customer) => {
|
|
142
|
+
const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
|
|
143
|
+
return name || customer.email || "-";
|
|
144
|
+
};
|
|
145
|
+
var useReviewTableFilters = () => {
|
|
146
|
+
const { t } = useTranslation3();
|
|
147
|
+
const { customers } = useCustomers({ limit: 100 });
|
|
148
|
+
return useMemo2(() => {
|
|
149
|
+
const ratingFilter = {
|
|
150
|
+
key: "rating",
|
|
151
|
+
label: t("reviews.list.columns.rating"),
|
|
152
|
+
type: "select",
|
|
153
|
+
multiple: true,
|
|
154
|
+
options: [5, 4, 3, 2, 1].map((value) => ({
|
|
155
|
+
label: t("reviews.filters.stars", { count: value }),
|
|
156
|
+
value: `${value}`
|
|
157
|
+
}))
|
|
158
|
+
};
|
|
159
|
+
const customerFilter = {
|
|
160
|
+
key: "customer_id",
|
|
161
|
+
label: t("reviews.list.columns.customer"),
|
|
162
|
+
type: "select",
|
|
163
|
+
multiple: true,
|
|
164
|
+
options: (customers ?? []).map((customer) => ({
|
|
165
|
+
label: customerLabel(customer),
|
|
166
|
+
value: customer.id
|
|
167
|
+
}))
|
|
168
|
+
};
|
|
169
|
+
const createdFilter = {
|
|
170
|
+
key: "created_at",
|
|
171
|
+
label: t("fields.createdAt"),
|
|
172
|
+
type: "date"
|
|
173
|
+
};
|
|
174
|
+
const statusFilter = {
|
|
175
|
+
key: "status",
|
|
176
|
+
label: t("reviews.list.columns.status"),
|
|
177
|
+
type: "select",
|
|
178
|
+
multiple: true,
|
|
179
|
+
options: [
|
|
180
|
+
{ label: t("reviews.status.published"), value: "published" },
|
|
181
|
+
{ label: t("reviews.status.pending"), value: "pending" },
|
|
182
|
+
{ label: t("reviews.status.rejected"), value: "rejected" }
|
|
183
|
+
]
|
|
184
|
+
};
|
|
185
|
+
return [ratingFilter, customerFilter, createdFilter, statusFilter];
|
|
186
|
+
}, [t, customers]);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/pages/reviews/_components/review-list-table/review-list-data-table.tsx
|
|
190
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
191
|
+
var PAGE_SIZE = 20;
|
|
192
|
+
var ReviewListDataTable = () => {
|
|
193
|
+
const { t } = useTranslation4();
|
|
194
|
+
const { raw, searchParams } = useReviewTableQuery({ pageSize: PAGE_SIZE });
|
|
195
|
+
const { reviews, count, isPending: isLoading, isError, error } = useReviews(
|
|
196
|
+
searchParams,
|
|
197
|
+
{
|
|
198
|
+
placeholderData: keepPreviousData
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
const columns = useReviewTableColumns();
|
|
202
|
+
const filters = useReviewTableFilters();
|
|
203
|
+
const { table } = useDataTable({
|
|
204
|
+
data: reviews ?? [],
|
|
205
|
+
columns,
|
|
206
|
+
count,
|
|
207
|
+
enablePagination: true,
|
|
208
|
+
getRowId: (row) => row.id,
|
|
209
|
+
pageSize: PAGE_SIZE
|
|
210
|
+
});
|
|
211
|
+
if (isError) {
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
return /* @__PURE__ */ jsx3(
|
|
215
|
+
_DataTable,
|
|
216
|
+
{
|
|
217
|
+
table,
|
|
218
|
+
columns,
|
|
219
|
+
count,
|
|
220
|
+
pageSize: PAGE_SIZE,
|
|
221
|
+
pagination: true,
|
|
222
|
+
search: true,
|
|
223
|
+
filters,
|
|
224
|
+
navigateTo: (row) => `/reviews/${row.original.id}`,
|
|
225
|
+
isLoading,
|
|
226
|
+
queryObject: raw,
|
|
227
|
+
orderBy: [
|
|
228
|
+
{ key: "display_id", label: t("reviews.list.columns.reviewId") },
|
|
229
|
+
{ key: "created_at", label: t("fields.createdAt") },
|
|
230
|
+
{ key: "updated_at", label: t("fields.updatedAt") }
|
|
231
|
+
],
|
|
232
|
+
noRecords: {
|
|
233
|
+
title: t("reviews.list.noRecordsTitle"),
|
|
234
|
+
message: t("reviews.list.noRecordsMessage"),
|
|
235
|
+
icon: /* @__PURE__ */ jsx3(Star, { className: "text-ui-fg-subtle" })
|
|
236
|
+
},
|
|
237
|
+
noResults: {
|
|
238
|
+
title: t("reviews.list.noResultsTitle"),
|
|
239
|
+
message: t("reviews.list.noResultsMessage"),
|
|
240
|
+
icon: /* @__PURE__ */ jsx3(Star, { className: "text-ui-fg-subtle" })
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// src/pages/reviews/_components/review-list-table/review-list-table.tsx
|
|
247
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
248
|
+
var ReviewListTable = () => {
|
|
249
|
+
return /* @__PURE__ */ jsxs2(Container, { className: "divide-y p-0", children: [
|
|
250
|
+
/* @__PURE__ */ jsx4(ReviewListHeader, {}),
|
|
251
|
+
/* @__PURE__ */ jsx4(ReviewListDataTable, {})
|
|
252
|
+
] });
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// src/pages/reviews/review-list-page.tsx
|
|
256
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
257
|
+
var Root = ({ children }) => {
|
|
258
|
+
return /* @__PURE__ */ jsx5(SingleColumnPage, { hasOutlet: true, children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx5(ReviewListTable, {}) });
|
|
259
|
+
};
|
|
260
|
+
var ReviewListPage = Object.assign(Root, {
|
|
261
|
+
Table: ReviewListTable,
|
|
262
|
+
Header: ReviewListHeader,
|
|
263
|
+
DataTable: ReviewListDataTable
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
export {
|
|
267
|
+
ReviewListPage
|
|
268
|
+
};
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PriceListUpdateOffersSchema,
|
|
3
|
+
usePriceListCurrencyData,
|
|
4
|
+
usePriceListGridColumns
|
|
5
|
+
} from "./chunk-DAOSTHVB.js";
|
|
6
|
+
import {
|
|
7
|
+
DataGrid
|
|
8
|
+
} from "./chunk-5FBQOAXU.js";
|
|
9
|
+
import {
|
|
10
|
+
castNumber
|
|
11
|
+
} from "./chunk-SMQT3ZNO.js";
|
|
12
|
+
import {
|
|
13
|
+
KeyboundForm
|
|
14
|
+
} from "./chunk-SITRHMZZ.js";
|
|
15
|
+
import {
|
|
16
|
+
RouteFocusModal,
|
|
17
|
+
useRouteModal
|
|
18
|
+
} from "./chunk-GDWBOQI5.js";
|
|
19
|
+
import {
|
|
20
|
+
useBatchPriceListPrices,
|
|
21
|
+
usePriceList
|
|
22
|
+
} from "./chunk-NV2RZAHW.js";
|
|
23
|
+
import {
|
|
24
|
+
useOffers
|
|
25
|
+
} from "./chunk-AHR2FIMC.js";
|
|
26
|
+
import {
|
|
27
|
+
useProducts
|
|
28
|
+
} from "./chunk-EMUCGKHP.js";
|
|
29
|
+
|
|
30
|
+
// src/pages/price-lists/[id]/products/[variant_id]/edit/price-list-prices-edit-form/use-price-list-edit-grid.tsx
|
|
31
|
+
import { buildOfferGridData } from "@mercurjs/dashboard-shared";
|
|
32
|
+
import { useMemo } from "react";
|
|
33
|
+
var extractOfferId = (price) => price.rules?.offer_id ?? price.price_rules?.find((r) => r.attribute === "offer_id")?.value ?? void 0;
|
|
34
|
+
var usePriceListEditGrid = (id, productFilter) => {
|
|
35
|
+
const { price_list, isLoading, isError, error } = usePriceList(id, {
|
|
36
|
+
fields: "id,title,+prices.amount,+prices.currency_code,+prices.price_set.variant.id,+prices.price_rules.attribute,+prices.price_rules.value"
|
|
37
|
+
});
|
|
38
|
+
const offerIds = useMemo(() => {
|
|
39
|
+
const set = /* @__PURE__ */ new Set();
|
|
40
|
+
for (const price of price_list?.prices ?? []) {
|
|
41
|
+
const offerId = extractOfferId(price);
|
|
42
|
+
if (offerId) {
|
|
43
|
+
set.add(offerId);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return Array.from(set);
|
|
47
|
+
}, [price_list]);
|
|
48
|
+
const { offers: pricedOffers } = useOffers(
|
|
49
|
+
{
|
|
50
|
+
id: offerIds,
|
|
51
|
+
limit: offerIds.length || 1,
|
|
52
|
+
fields: "id,product_id"
|
|
53
|
+
},
|
|
54
|
+
{ enabled: offerIds.length > 0 }
|
|
55
|
+
);
|
|
56
|
+
const pricedProductIds = useMemo(() => {
|
|
57
|
+
const set = /* @__PURE__ */ new Set();
|
|
58
|
+
for (const offer of pricedOffers ?? []) {
|
|
59
|
+
set.add(offer.product_id);
|
|
60
|
+
}
|
|
61
|
+
return set;
|
|
62
|
+
}, [pricedOffers]);
|
|
63
|
+
const { offers: allOffers } = useOffers(
|
|
64
|
+
{
|
|
65
|
+
limit: 1e3,
|
|
66
|
+
fields: "id,variant_id,product_id,sku,product.title,product.thumbnail"
|
|
67
|
+
},
|
|
68
|
+
{ enabled: pricedProductIds.size > 0 }
|
|
69
|
+
);
|
|
70
|
+
const scopedOffers = useMemo(() => {
|
|
71
|
+
const allowed = productFilter ? new Set(productFilter) : void 0;
|
|
72
|
+
return (allOffers ?? []).filter(
|
|
73
|
+
(o) => pricedProductIds.has(o.product_id) && (!allowed || allowed.has(o.product_id))
|
|
74
|
+
);
|
|
75
|
+
}, [allOffers, pricedProductIds, productFilter]);
|
|
76
|
+
const productIds = useMemo(
|
|
77
|
+
() => Array.from(new Set(scopedOffers.map((o) => o.product_id))),
|
|
78
|
+
[scopedOffers]
|
|
79
|
+
);
|
|
80
|
+
const {
|
|
81
|
+
products,
|
|
82
|
+
isLoading: isProductsLoading,
|
|
83
|
+
isError: isProductsError,
|
|
84
|
+
error: productError
|
|
85
|
+
} = useProducts(
|
|
86
|
+
{
|
|
87
|
+
id: productIds,
|
|
88
|
+
limit: productIds.length || 1,
|
|
89
|
+
fields: "id,*variants"
|
|
90
|
+
},
|
|
91
|
+
{ enabled: productIds.length > 0 }
|
|
92
|
+
);
|
|
93
|
+
const { gridData, variantIdByOffer } = useMemo(
|
|
94
|
+
() => buildOfferGridData(
|
|
95
|
+
scopedOffers,
|
|
96
|
+
products ?? []
|
|
97
|
+
),
|
|
98
|
+
[scopedOffers, products]
|
|
99
|
+
);
|
|
100
|
+
const currencyData = usePriceListCurrencyData();
|
|
101
|
+
const gridDataReady = offerIds.length === 0 || allOffers !== void 0 && (productIds.length === 0 || products !== void 0);
|
|
102
|
+
const ready = currencyData.isReady && !isLoading && !!price_list && !isProductsLoading && gridDataReady;
|
|
103
|
+
return {
|
|
104
|
+
price_list,
|
|
105
|
+
gridData,
|
|
106
|
+
variantIdByOffer,
|
|
107
|
+
currencyData,
|
|
108
|
+
ready,
|
|
109
|
+
isError,
|
|
110
|
+
error,
|
|
111
|
+
isProductsError,
|
|
112
|
+
productError
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/pages/price-lists/[id]/products/[variant_id]/edit/price-list-prices-edit-form/price-list-prices-edit-form.tsx
|
|
117
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
118
|
+
import { Button, toast } from "@medusajs/ui";
|
|
119
|
+
import { useRef } from "react";
|
|
120
|
+
import { useForm } from "react-hook-form";
|
|
121
|
+
import { useTranslation } from "react-i18next";
|
|
122
|
+
import { z } from "zod";
|
|
123
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
124
|
+
var PricingOfferPricesSchema = z.object({
|
|
125
|
+
offers: PriceListUpdateOffersSchema
|
|
126
|
+
});
|
|
127
|
+
var PriceListPricesEditForm = ({
|
|
128
|
+
priceList,
|
|
129
|
+
gridData,
|
|
130
|
+
variantIdByOffer,
|
|
131
|
+
regions,
|
|
132
|
+
currencies,
|
|
133
|
+
pricePreferences
|
|
134
|
+
}) => {
|
|
135
|
+
const { t } = useTranslation();
|
|
136
|
+
const { handleSuccess, setCloseOnEscape } = useRouteModal();
|
|
137
|
+
const initialValue = useRef(initRecord(priceList, variantIdByOffer));
|
|
138
|
+
const form = useForm({
|
|
139
|
+
defaultValues: {
|
|
140
|
+
offers: initialValue.current
|
|
141
|
+
},
|
|
142
|
+
resolver: zodResolver(PricingOfferPricesSchema)
|
|
143
|
+
});
|
|
144
|
+
const { mutateAsync, isPending } = useBatchPriceListPrices(priceList.id);
|
|
145
|
+
const handleSubmit = form.handleSubmit(async (values) => {
|
|
146
|
+
const { pricesToDelete, pricesToCreate, pricesToUpdate } = sortPrices(
|
|
147
|
+
values.offers,
|
|
148
|
+
initialValue.current,
|
|
149
|
+
regions,
|
|
150
|
+
variantIdByOffer
|
|
151
|
+
);
|
|
152
|
+
mutateAsync(
|
|
153
|
+
{
|
|
154
|
+
delete: pricesToDelete,
|
|
155
|
+
update: pricesToUpdate,
|
|
156
|
+
create: pricesToCreate
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
onSuccess: () => {
|
|
160
|
+
toast.success(t("priceLists.products.edit.successToast"));
|
|
161
|
+
handleSuccess();
|
|
162
|
+
},
|
|
163
|
+
onError: (error) => {
|
|
164
|
+
toast.error(error.message);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
const columns = usePriceListGridColumns({
|
|
170
|
+
currencies,
|
|
171
|
+
regions,
|
|
172
|
+
pricePreferences
|
|
173
|
+
});
|
|
174
|
+
return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { onSubmit: handleSubmit, className: "flex size-full flex-col", children: [
|
|
175
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
176
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
177
|
+
DataGrid,
|
|
178
|
+
{
|
|
179
|
+
columns,
|
|
180
|
+
data: gridData,
|
|
181
|
+
state: form,
|
|
182
|
+
onEditingChange: (editing) => setCloseOnEscape(!editing)
|
|
183
|
+
}
|
|
184
|
+
) }),
|
|
185
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
186
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: t("actions.cancel") }) }),
|
|
187
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: t("actions.save") })
|
|
188
|
+
] }) })
|
|
189
|
+
] }) });
|
|
190
|
+
};
|
|
191
|
+
function initRecord(priceList, variantIdByOffer = {}) {
|
|
192
|
+
const record = {};
|
|
193
|
+
for (const [offerId, variantId] of Object.entries(variantIdByOffer)) {
|
|
194
|
+
record[offerId] = {
|
|
195
|
+
variant_id: variantId,
|
|
196
|
+
currency_prices: {},
|
|
197
|
+
region_prices: {}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
for (const price of priceList.prices ?? []) {
|
|
201
|
+
const offerId = price.rules?.offer_id;
|
|
202
|
+
const variantId = price.variant_id;
|
|
203
|
+
if (!offerId || !variantId) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const entry = record[offerId] ?? (record[offerId] = {
|
|
207
|
+
variant_id: variantId,
|
|
208
|
+
currency_prices: {},
|
|
209
|
+
region_prices: {}
|
|
210
|
+
});
|
|
211
|
+
const regionId = price.rules?.region_id;
|
|
212
|
+
if (regionId) {
|
|
213
|
+
entry.region_prices[regionId] = {
|
|
214
|
+
amount: price.amount.toString(),
|
|
215
|
+
id: price.id
|
|
216
|
+
};
|
|
217
|
+
} else {
|
|
218
|
+
entry.currency_prices[price.currency_code] = {
|
|
219
|
+
amount: price.amount.toString(),
|
|
220
|
+
id: price.id
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return record;
|
|
225
|
+
}
|
|
226
|
+
function convertToPriceArray(data, regions) {
|
|
227
|
+
const prices = [];
|
|
228
|
+
const regionCurrencyMap = regions.reduce(
|
|
229
|
+
(map, region) => {
|
|
230
|
+
map[region.id] = region.currency_code;
|
|
231
|
+
return map;
|
|
232
|
+
},
|
|
233
|
+
{}
|
|
234
|
+
);
|
|
235
|
+
for (const [offerId, offer] of Object.entries(data || {})) {
|
|
236
|
+
const { variant_id, currency_prices, region_prices } = offer || {};
|
|
237
|
+
for (const [currencyCode, price] of Object.entries(currency_prices || {})) {
|
|
238
|
+
if (price?.amount !== "" && typeof price?.amount !== "undefined") {
|
|
239
|
+
prices.push({
|
|
240
|
+
offerId,
|
|
241
|
+
variantId: variant_id,
|
|
242
|
+
currencyCode,
|
|
243
|
+
amount: castNumber(price.amount),
|
|
244
|
+
id: price.id
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
for (const [regionId, price] of Object.entries(region_prices || {})) {
|
|
249
|
+
if (price?.amount !== "" && typeof price?.amount !== "undefined") {
|
|
250
|
+
prices.push({
|
|
251
|
+
offerId,
|
|
252
|
+
variantId: variant_id,
|
|
253
|
+
regionId,
|
|
254
|
+
currencyCode: regionCurrencyMap[regionId],
|
|
255
|
+
amount: castNumber(price.amount),
|
|
256
|
+
id: price.id
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return prices;
|
|
262
|
+
}
|
|
263
|
+
function createMapKey(obj) {
|
|
264
|
+
return `${obj.offerId}-${obj.currencyCode}-${obj.regionId || "none"}-${obj.id || "none"}`;
|
|
265
|
+
}
|
|
266
|
+
function buildRules(price) {
|
|
267
|
+
return {
|
|
268
|
+
offer_id: price.offerId,
|
|
269
|
+
...price.regionId ? { region_id: price.regionId } : {}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function comparePrices(initialPrices, newPrices) {
|
|
273
|
+
const pricesToUpdate = [];
|
|
274
|
+
const pricesToCreate = [];
|
|
275
|
+
const pricesToDelete = [];
|
|
276
|
+
const initialPriceMap = initialPrices.reduce(
|
|
277
|
+
(map, price) => {
|
|
278
|
+
map[createMapKey(price)] = price;
|
|
279
|
+
return map;
|
|
280
|
+
},
|
|
281
|
+
{}
|
|
282
|
+
);
|
|
283
|
+
const newPriceMap = newPrices.reduce(
|
|
284
|
+
(map, price) => {
|
|
285
|
+
map[createMapKey(price)] = price;
|
|
286
|
+
return map;
|
|
287
|
+
},
|
|
288
|
+
{}
|
|
289
|
+
);
|
|
290
|
+
const keys = /* @__PURE__ */ new Set([
|
|
291
|
+
...Object.keys(initialPriceMap),
|
|
292
|
+
...Object.keys(newPriceMap)
|
|
293
|
+
]);
|
|
294
|
+
for (const key of keys) {
|
|
295
|
+
const initialPrice = initialPriceMap[key];
|
|
296
|
+
const newPrice = newPriceMap[key];
|
|
297
|
+
if (initialPrice && newPrice) {
|
|
298
|
+
if (isNaN(newPrice.amount) && newPrice.id) {
|
|
299
|
+
pricesToDelete.push(newPrice.id);
|
|
300
|
+
}
|
|
301
|
+
if (initialPrice.amount !== newPrice.amount && newPrice.id) {
|
|
302
|
+
pricesToUpdate.push({
|
|
303
|
+
id: newPrice.id,
|
|
304
|
+
variant_id: newPrice.variantId,
|
|
305
|
+
currency_code: newPrice.currencyCode,
|
|
306
|
+
rules: buildRules(newPrice),
|
|
307
|
+
amount: newPrice.amount
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (!initialPrice && newPrice) {
|
|
312
|
+
pricesToCreate.push({
|
|
313
|
+
variant_id: newPrice.variantId,
|
|
314
|
+
currency_code: newPrice.currencyCode,
|
|
315
|
+
rules: buildRules(newPrice),
|
|
316
|
+
amount: newPrice.amount
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
if (initialPrice && !newPrice && initialPrice.id) {
|
|
320
|
+
pricesToDelete.push(initialPrice.id);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return { pricesToDelete, pricesToCreate, pricesToUpdate };
|
|
324
|
+
}
|
|
325
|
+
function sortPrices(data, initialValue, regions, _variantIdByOffer) {
|
|
326
|
+
const initialPrices = convertToPriceArray(initialValue, regions);
|
|
327
|
+
const newPrices = convertToPriceArray(data, regions);
|
|
328
|
+
return comparePrices(initialPrices, newPrices);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export {
|
|
332
|
+
usePriceListEditGrid,
|
|
333
|
+
PriceListPricesEditForm
|
|
334
|
+
};
|