From fc7c54d887c1184f31fcb258bd7a29cf00168324 Mon Sep 17 00:00:00 2001 From: nzambello Date: Mon, 2 Dec 2024 12:41:26 +0200 Subject: [PATCH] fix: recover birthdate from localstorage or login --- src/components/MemoriWidget/MemoriWidget.tsx | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/MemoriWidget/MemoriWidget.tsx b/src/components/MemoriWidget/MemoriWidget.tsx index 10d808ef..10849393 100644 --- a/src/components/MemoriWidget/MemoriWidget.tsx +++ b/src/components/MemoriWidget/MemoriWidget.tsx @@ -473,6 +473,11 @@ const MemoriWidget = ({ if (user && resultCode === 0) { setUser(user); setLocalConfig('loginToken', loginToken); + + if (user.birthDate) { + setBirthDate(user.birthDate); + setLocalConfig('birthDate', user.birthDate); + } } else { removeLocalConfig('loginToken'); } @@ -612,6 +617,8 @@ const MemoriWidget = ({ if (!additionalInfo?.loginToken && !authToken) { setLoginToken(getLocalConfig('loginToken', undefined)); userToken = getLocalConfig('loginToken', undefined); + + setBirthDate(getLocalConfig('birthDate', undefined)); } }, []); @@ -1092,11 +1099,7 @@ const MemoriWidget = ({ dialogState: DialogState; sessionID: string; } | void> => { - let storageBirthDate = getLocalConfig( - 'birthDate', - undefined - ); - if (!(birthDate || storageBirthDate) && !!minAge) { + if (!birthDate && !!minAge) { setShowAgeVerification(true); return; } @@ -1190,11 +1193,7 @@ const MemoriWidget = ({ ) => { setLoading(true); try { - let storageBirthDate = getLocalConfig( - 'birthDate', - undefined - ); - if (!(birthDate || storageBirthDate) && !!minAge) { + if (!birthDate && !!minAge) { setShowAgeVerification(true); return; } @@ -1232,7 +1231,7 @@ const MemoriWidget = ({ ...(initialContextVars || {}), }, initialQuestion, - birthDate: birthDate || storageBirthDate || undefined, + birthDate: birthDate || undefined, additionalInfo: { ...(additionalInfo || {}), loginToken: