Skip to content

Commit

Permalink
Issue #0000 fix: changes done on all pages
Browse files Browse the repository at this point in the history
  • Loading branch information
suvarnakale committed May 23, 2024
1 parent e49fb83 commit a3962ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
14 changes: 13 additions & 1 deletion src/pages/attendance-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,6 +58,7 @@ interface user {
const UserAttendanceHistory = () => {
const theme = useTheme<any>();
const { t } = useTranslation();
const { push } = useRouter();
const [selectedDate, setSelectedDate] = useState<Date>(new Date());
const [classId, setClassId] = React.useState('');
const [cohortsData, setCohortsData] = React.useState<Array<cohort>>([]);
Expand Down Expand Up @@ -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 () => {
Expand Down
12 changes: 4 additions & 8 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,24 @@ 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' });
}
}
}, []);

return (
<>
{loading && <p>{t('COMMON.LOADING')}...</p>}
</>
);
return <>{loading && <p>{t('COMMON.LOADING')}...</p>}</>;
};

export async function getStaticProps({ locale }: any) {
Expand Down
5 changes: 2 additions & 3 deletions src/pages/teacher-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ 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');
}
}
}, []);


const handleUpdateClick = async () => {
setLoading(true);
try {
Expand Down

0 comments on commit a3962ea

Please sign in to comment.