From 82beabe0a810154d1d7e2668c23c5241a89d56d9 Mon Sep 17 00:00:00 2001 From: Abhishek P Anil Date: Tue, 27 Aug 2024 12:14:19 +0530 Subject: [PATCH 1/2] fix: changed calendarId from cookies to session storage --- src/components/Dropdown/Calendar/Calendar.jsx | 5 ++--- src/pages/Dashboard/Dashboard.jsx | 10 +++++----- src/pages/Login/Login.jsx | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/components/Dropdown/Calendar/Calendar.jsx b/src/components/Dropdown/Calendar/Calendar.jsx index e50ad87c4..da23fe1eb 100644 --- a/src/components/Dropdown/Calendar/Calendar.jsx +++ b/src/components/Dropdown/Calendar/Calendar.jsx @@ -7,12 +7,11 @@ import { PathName } from '../../../constants/pathName'; import { contentLanguageBilingual } from '../../../utils/bilingual'; import { useSelector } from 'react-redux'; import { getUserDetails } from '../../../redux/reducer/userSlice'; -import Cookies from 'js-cookie'; function Calendar({ children, allCalendarsData, setPageNumber }) { const dispatch = useDispatch(); const { user } = useSelector(getUserDetails); - const calendarIdInCookies = Cookies.get('calendarId'); + const calendarIdInCookies = sessionStorage.getItem('calendarId'); const [open, setOpen] = useState(false); const items = allCalendarsData?.data?.map((item) => { @@ -47,7 +46,7 @@ function Calendar({ children, allCalendarsData, setPageNumber }) { const onClick = ({ key }) => { if (calendarIdInCookies != key) { dispatch(setSelectedCalendar(String(key))); - Cookies.set('calendarId', key); + sessionStorage.setItem('calendarId', key); setPageNumber(1); sessionStorage.clear(); setOpen(false); diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsx index ccad3c1c6..f46bf66fb 100644 --- a/src/pages/Dashboard/Dashboard.jsx +++ b/src/pages/Dashboard/Dashboard.jsx @@ -79,10 +79,10 @@ function Dashboard() { useEffect(() => { const accessTokenFromCookie = Cookies.get('accessToken'); const refreshTokenFromCookie = Cookies.get('refreshToken'); - const calendarIdFromCookie = Cookies.get('calendarId'); + const calendarIdFromCookie = sessionStorage.getItem('calendarId'); const calId = calendarId || calendarIdFromCookie; - if (calendarId) Cookies.set('calendarId', calId); + if (calendarId) sessionStorage.setItem('calendarId', calId); if (!checkToken(accessToken, accessTokenFromCookie)) navigate(PathName.Login); @@ -111,7 +111,7 @@ function Dashboard() { const checkedCalendarId = findActiveCalendar(); if (checkedCalendarId != null) { - Cookies.set('calendarId', checkedCalendarId); + sessionStorage.setItem('calendarId', checkedCalendarId); } if (calendarId && accessToken) { @@ -130,12 +130,12 @@ function Dashboard() { }); dispatch(setSelectedCalendar(String(calendarId))); } else { - let activeCalendarId = Cookies.get('calendarId'); + let activeCalendarId = sessionStorage.getItem('calendarId'); if (activeCalendarId && accessToken) { navigate(`${PathName.Dashboard}/${activeCalendarId}${PathName.Events}`); } else if (!isLoading && allCalendarsData?.data) { activeCalendarId = allCalendarsData?.data[0]?.id; - Cookies.set('calendarId', activeCalendarId); + sessionStorage.setItem('calendarId', activeCalendarId); navigate(`${PathName.Dashboard}/${activeCalendarId}${PathName.Events}`); } } diff --git a/src/pages/Login/Login.jsx b/src/pages/Login/Login.jsx index bf3e906dd..aa798b6c1 100644 --- a/src/pages/Login/Login.jsx +++ b/src/pages/Login/Login.jsx @@ -36,7 +36,7 @@ const Login = () => { }; useEffect(() => { const savedAccessToken = Cookies.get('accessToken'); - const calenderId = Cookies.get('calendarId'); + const calenderId = sessionStorage.getItem('calendarId'); if (location?.state?.previousPath === 'logout') { dispatch(clearUser()); } @@ -50,7 +50,7 @@ const Login = () => { }, []); useEffect(() => { - const calenderId = Cookies.get('calendarId'); + const calenderId = sessionStorage.getItem('calendarId'); if (accessToken && accessToken != '' && calenderId && calenderId != '') { navigate(PathName.Dashboard, { state: { previousPath: 'login' } }); } From 68b401ff6e4b6bc5eeebfaa539af4f2c8d009755 Mon Sep 17 00:00:00 2001 From: Abhishek P Anil Date: Tue, 27 Aug 2024 12:14:44 +0530 Subject: [PATCH 2/2] refactor: optimised code --- src/utils/clearSessionStoredSearchQueries.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/utils/clearSessionStoredSearchQueries.js b/src/utils/clearSessionStoredSearchQueries.js index 3250ed014..33b574eb0 100644 --- a/src/utils/clearSessionStoredSearchQueries.js +++ b/src/utils/clearSessionStoredSearchQueries.js @@ -1,8 +1,12 @@ export const clearSessionStoredSearchQueries = () => { - sessionStorage.removeItem('query'); - sessionStorage.removeItem('queryTaxonomy'); - sessionStorage.removeItem('peopleSearchQuery'); - sessionStorage.removeItem('organizationSearchQuery'); - sessionStorage.removeItem('placesSearchQuery'); - sessionStorage.removeItem('queryUserListing'); + [ + 'query', + 'queryTaxonomy', + 'peopleSearchQuery', + 'organizationSearchQuery', + 'placesSearchQuery', + 'queryUserListing', + ].forEach((key) => { + sessionStorage.removeItem(key); + }); };