Skip to content

Commit

Permalink
Merge pull request #147 from suvarnakale/shiksha-2.0
Browse files Browse the repository at this point in the history
Issue #0000 fix: login page issues fixed
  • Loading branch information
itsvick authored May 23, 2024
2 parents 3cf3e2c + a3962ea commit 33f9ccc
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/components/WeekDays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const WeekDays: React.FC<WeekDaysProps> = ({ 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();
Expand Down
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
14 changes: 8 additions & 6 deletions src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ const Dashboard: React.FC<DashboardProps> = () => {

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');
Expand Down Expand Up @@ -209,10 +209,12 @@ const Dashboard: React.FC<DashboardProps> = () => {
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;
};
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
16 changes: 7 additions & 9 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const LoginPage = () => {
// const location = useLocation();

const DEFAULT_POSITION: Pick<State, 'vertical' | 'horizontal'> = {
vertical: 'top',
vertical: 'bottom',
horizontal: 'center',
};
const [state, setState] = React.useState<State>({
Expand All @@ -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');
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ const LoginPage = () => {
style={{
borderRadius: '0.5rem',
color: theme.palette.warning['200'],
width: 'auto',
width: '7rem',
marginBottom: '0rem',
}}
>
Expand All @@ -244,7 +244,6 @@ const LoginPage = () => {
}}
>
<TextField
required
id="username"
InputLabelProps={{
shrink: true,
Expand All @@ -267,7 +266,6 @@ const LoginPage = () => {
>
<TextField
type={showPassword ? 'text' : 'password'}
required
id="password"
InputLabelProps={{
shrink: true,
Expand All @@ -294,9 +292,9 @@ const LoginPage = () => {
/>
</Box>

<Box marginTop={'-1rem'} marginLeft={'0.5rem'}>
<Box marginTop={'1rem'} marginLeft={'0.5rem'}>
<Link
sx={{ color: 'blue' }}
sx={{ color: theme.palette.secondary.main }}
href="https://qa.prathamteacherapp.tekdinext.com/auth/realms/pratham/login-actions/reset-credentials?client_id=security-admin-console&tab_id=R-3zEZbbbyM"
underline="none"
>
Expand All @@ -313,7 +311,7 @@ const LoginPage = () => {
<Box
alignContent={'center'}
textAlign={'center'}
marginTop={'1rem'}
marginTop={'5rem'}
bottom={'1rem'}
width={'100%'}
>
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 33f9ccc

Please sign in to comment.