From fab74d20b9f62d18384f1b5ebab390692ab915a7 Mon Sep 17 00:00:00 2001 From: Egor Kliuchantsev Date: Wed, 6 Aug 2025 17:35:44 +0200 Subject: [PATCH] fix(ConsentPopup): apply defaultChecked to initial cookieList --- .../components/ConsentPopup/ConsentPopup.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/CookieConsent/components/ConsentPopup/ConsentPopup.tsx b/src/components/CookieConsent/components/ConsentPopup/ConsentPopup.tsx index 4d464973..7e1806f8 100644 --- a/src/components/CookieConsent/components/ConsentPopup/ConsentPopup.tsx +++ b/src/components/CookieConsent/components/ConsentPopup/ConsentPopup.tsx @@ -180,9 +180,20 @@ export const ConsentPopup = ({ ...buttonsParams }: ConsentPopupProps) => { const mobile = useMobile(); - const [currentConsents, setCurrentConsents] = React.useState( - consentManager.getConsents(), - ); + const [currentConsents, setCurrentConsents] = React.useState(() => { + const existingConsents = consentManager.getConsents(); + + if (cookieList) { + return cookieList.reduce((acc: Consents, item) => { + if (item.defaultChecked) { + return {...acc, [item.type]: true}; + } + return acc; + }, existingConsents); + } + + return existingConsents; + }); const [currentStep, setCurrentStep] = React.useState<`${ConsentPopupStep}`>(step); const onChangeStep = (newStep: `${ConsentPopupStep}`) => { setCurrentStep(newStep);