From e977c20638e530f9f474b4dc3b1b544b1e6dd5bd Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Thu, 14 Nov 2024 17:01:22 +0530 Subject: [PATCH] Issue feat PS-2462:clear cache upon changing academic year and logout --- src/components/layouts/header/Header.tsx | 7 ++++++- src/pages/logout.tsx | 10 +++++----- src/services/CohortService/cohortService.ts | 1 - 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/layouts/header/Header.tsx b/src/components/layouts/header/Header.tsx index 3e4f88e4..d71ef40a 100644 --- a/src/components/layouts/header/Header.tsx +++ b/src/components/layouts/header/Header.tsx @@ -16,11 +16,14 @@ import { createTheme, useTheme } from "@mui/material/styles"; import Profile from "./Profile"; import { AcademicYear } from "@/utils/Interfaces"; import useStore from "@/store/store"; +import { useQueryClient } from '@tanstack/react-query'; const Header = ({ sx, customClass, toggleMobileSidebar, position }: any) => { const { t } = useTranslation(); const theme = useTheme(); const [lang, setLang] = useState(""); + const queryClient = useQueryClient(); + const router = useRouter(); const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); @@ -68,7 +71,9 @@ const Header = ({ sx, customClass, toggleMobileSidebar, position }: any) => { const isActive = selectedYear ? selectedYear.isActive : false; // localStorage.setItem('isActiveYearSelected', JSON.stringify(isActive)); setIsActiveYearSelected(isActive); - // window.location.reload(); + + queryClient.clear(); + // window.location.reload(); window.location.href = "/centers"; }; diff --git a/src/pages/logout.tsx b/src/pages/logout.tsx index 04fd9002..195d8e52 100644 --- a/src/pages/logout.tsx +++ b/src/pages/logout.tsx @@ -4,10 +4,13 @@ import { logout } from "../services/LoginService"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import Loader from "@/components/Loader"; import { useTranslation } from "react-i18next"; +import { useQueryClient } from '@tanstack/react-query'; function Logout() { const router = useRouter(); const { t } = useTranslation(); + const queryClient = useQueryClient(); + useEffect(() => { const userLogout = async () => { try { @@ -46,11 +49,8 @@ function Logout() { } }); } - - - - - router.replace("/login"); + queryClient.clear(); + router.replace("/login"); }, []); return ; diff --git a/src/services/CohortService/cohortService.ts b/src/services/CohortService/cohortService.ts index 761be7b8..dbc38500 100644 --- a/src/services/CohortService/cohortService.ts +++ b/src/services/CohortService/cohortService.ts @@ -2,7 +2,6 @@ import { CohortMemberList } from "@/utils/Interfaces"; import { get, post, put } from "../RestClient"; import axios from 'axios'; import { showToastMessage } from "@/components/Toastify"; -import { useTranslation } from "next-i18next"; export interface cohortListFilter { type: string;