Skip to content

Commit

Permalink
Redirect for specific dashboard after login
Browse files Browse the repository at this point in the history
  • Loading branch information
Disura-Randunu committed Dec 7, 2024
1 parent 991d87b commit 43baf3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/components/LoginModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import axios, { AxiosError } from 'axios';
import { API_URL } from '../../constants';
import closeIcon from '../../assets/svg/closeIcon.svg';
import useProfile from '../../hooks/useProfile';
import GoogleLoginButton from '../OAuth/Google';
import LinkedInLoginButton from '../OAuth/LinkedIn';
import { useNavigate } from 'react-router';
import { UserContext, UserContextType } from '../../contexts/UserContext';

interface LoginModalProps {
handleClose: () => void;
Expand All @@ -22,6 +24,20 @@ const LoginModal: React.FC<LoginModalProps> = ({
const [error, setError] = useState('');
const [isLoading, setIsLoading] = useState(false);
const { refetch } = useProfile();
const navigate = useNavigate();
const userContext = useContext(UserContext) as UserContextType;

useEffect(() => {
if (userContext.user) {
if (userContext.isUserMentor) {
navigate('/mentor/dashboard');
} else if (userContext.isUserAdmin) {
navigate('/admin/dashboard/mentor-applications');
} else if (userContext.isUserMentee) {
navigate('/mentee/dashboard');
}
}
}, [userContext, navigate]);

const handleLogin = async (e: React.FormEvent): Promise<void> => {
e.preventDefault();
Expand Down
6 changes: 4 additions & 2 deletions src/pages/MentorProfile/MentorProfile.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ const MentorProfile: React.FC = () => {
<span className="w-0.5 h-24 bg-gray-300 md:block hidden"></span>

{mentor?.application.linkedin && (
<a href={mentor.application.linkedin}
<a
href={mentor.application.linkedin}
target="_blank"
rel="noreferrer"
className="text-blue-500 underline"
Expand All @@ -205,7 +206,8 @@ const MentorProfile: React.FC = () => {
)}

{mentor?.application.website && (
<a href={mentor.application.website}
<a
href={mentor.application.website}
target="_blank"
rel="noreferrer"
className="text-blue-500 underline"
Expand Down

0 comments on commit 43baf3c

Please sign in to comment.