From 837905ccb6369dd877fe1ab3f82764d9582325f7 Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Thu, 23 May 2024 18:57:12 +0530 Subject: [PATCH 1/3] Issue #0000 fix: login page issues fixed --- src/pages/dashboard.tsx | 14 ++++++++------ src/pages/login.tsx | 16 +++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 575216e3..4c30b71b 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -111,8 +111,8 @@ const Dashboard: React.FC = () => { useEffect(() => { if (typeof window !== 'undefined' && window.localStorage) { - const refreshToken = localStorage.getItem('refreshToken'); - if (refreshToken) { + const token = localStorage.getItem('token'); + if (token) { setIsAuthenticated(true); } else { router.push('/login'); @@ -209,10 +209,12 @@ const Dashboard: React.FC = () => { const attendance = response.find( (status) => status.userId === userId ); - userAttendanceArray.push({ - userId, - attendance: attendance?.attendance ? attendance.attendance : '', - }); + userAttendanceArray.push({ + userId, + attendance: attendance?.attendance + ? attendance.attendance + : '', + }); }); return userAttendanceArray; }; diff --git a/src/pages/login.tsx b/src/pages/login.tsx index 1de491f7..000ba5c3 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -51,7 +51,7 @@ const LoginPage = () => { // const location = useLocation(); const DEFAULT_POSITION: Pick = { - vertical: 'top', + vertical: 'bottom', horizontal: 'center', }; const [state, setState] = React.useState({ @@ -64,8 +64,8 @@ const LoginPage = () => { if (typeof window !== 'undefined' && window.localStorage) { const lang = localStorage.getItem('preferredLanguage') || 'en'; setLanguage(lang); - const refreshToken = localStorage.getItem('refreshToken'); - if (refreshToken) { + const token = localStorage.getItem('token'); + if (token) { router.push('/dashboard'); } } @@ -222,7 +222,7 @@ const LoginPage = () => { style={{ borderRadius: '0.5rem', color: theme.palette.warning['200'], - width: 'auto', + width: '7rem', marginBottom: '0rem', }} > @@ -244,7 +244,6 @@ const LoginPage = () => { }} > { > { /> - + @@ -313,7 +311,7 @@ const LoginPage = () => { From e49fb830224d1d929c56808d16c2e9d78bdbe52b Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Thu, 23 May 2024 19:00:22 +0530 Subject: [PATCH 2/3] Issue #0000 fix: weekday pattern corrected --- src/components/WeekDays.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/WeekDays.tsx b/src/components/WeekDays.tsx index f181e665..7039a04f 100644 --- a/src/components/WeekDays.tsx +++ b/src/components/WeekDays.tsx @@ -21,7 +21,7 @@ const WeekDays: React.FC = ({ useAbbreviation }) => { const days = useAbbreviation ? ['S', 'M', 'T', 'W', 'T', 'F', 'S'] - : ['Sun', 'Mon', 'Tues', 'Wed', 'Thu', 'Fri', 'Sat']; + : ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; const currentDate = new Date(); const currentDayIndex = currentDate.getDay(); From a3962eab6cefdb6b7da4b4d8371dc905ae42981a Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Thu, 23 May 2024 19:26:38 +0530 Subject: [PATCH 3/3] Issue #0000 fix: changes done on all pages --- src/pages/attendance-history.tsx | 14 +++++++++++++- src/pages/index.tsx | 12 ++++-------- src/pages/teacher-profile.tsx | 5 ++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/pages/attendance-history.tsx b/src/pages/attendance-history.tsx index 97e94ef1..d7bb219b 100644 --- a/src/pages/attendance-history.tsx +++ b/src/pages/attendance-history.tsx @@ -48,7 +48,6 @@ import { usePathname } from 'next/navigation'; import { useRouter } from 'next/router'; import { useTheme } from '@mui/material/styles'; import { useTranslation } from 'next-i18next'; - interface user { userId: string; name: string; @@ -59,6 +58,7 @@ interface user { const UserAttendanceHistory = () => { const theme = useTheme(); const { t } = useTranslation(); + const { push } = useRouter(); const [selectedDate, setSelectedDate] = useState(new Date()); const [classId, setClassId] = React.useState(''); const [cohortsData, setCohortsData] = React.useState>([]); @@ -108,6 +108,18 @@ const UserAttendanceHistory = () => { setOpen(false); }; + useEffect(() => { + if (typeof window !== 'undefined' && window.localStorage) { + const token = localStorage.getItem('token'); + setLoading(false); + if (token) { + push('/dashboard'); + } else { + push('/login', undefined, { locale: 'en' }); + } + } + }, []); + // API call to get center list useEffect(() => { const fetchCohortList = async () => { diff --git a/src/pages/index.tsx b/src/pages/index.tsx index b7908f88..bae160fa 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -8,16 +8,16 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; // const Dashboard = dynamic(() => import('./Dashboard'), { ssr: false }); const Home: React.FC = () => { - const { push } = useRouter(); + const { push } = useRouter(); const { t } = useTranslation(); const [loading, setLoading] = React.useState(true); useEffect(() => { if (typeof window !== 'undefined' && window.localStorage) { - const refreshToken = localStorage.getItem('refreshToken'); + const token = localStorage.getItem('token'); setLoading(false); - if (refreshToken) { + if (token) { push('/dashboard'); } else { push('/login', undefined, { locale: 'en' }); @@ -25,11 +25,7 @@ const Home: React.FC = () => { } }, []); - return ( - <> - {loading &&

{t('COMMON.LOADING')}...

} - - ); + return <>{loading &&

{t('COMMON.LOADING')}...

}; }; export async function getStaticProps({ locale }: any) { diff --git a/src/pages/teacher-profile.tsx b/src/pages/teacher-profile.tsx index 6ea8e0e5..909f77b9 100644 --- a/src/pages/teacher-profile.tsx +++ b/src/pages/teacher-profile.tsx @@ -75,8 +75,8 @@ const TeacherProfile = () => { useEffect(() => { if (typeof window !== 'undefined' && window.localStorage) { - const refreshToken = localStorage.getItem('refreshToken'); - if (refreshToken) { + const token = localStorage.getItem('token'); + if (token) { setIsAuthenticated(true); } else { router.push('/login'); @@ -84,7 +84,6 @@ const TeacherProfile = () => { } }, []); - const handleUpdateClick = async () => { setLoading(true); try {