diff --git a/src/pages/auth/Singup.tsx b/src/pages/auth/Singup.tsx index f49b803..ba52bee 100644 --- a/src/pages/auth/Singup.tsx +++ b/src/pages/auth/Singup.tsx @@ -1,7 +1,7 @@ import { CheckCircle, Eye, EyeOff, Key, Loader2, Mail, User } from 'lucide-react'; import { useState } from 'react'; - +import { useNavigate } from "react-router-dom"; import { Input } from '../../components/ui/input'; import { Button } from '../../components/ui/button'; import apiClient from '../../apiClient/apiClient'; @@ -18,7 +18,7 @@ const Signup = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); - + const navigate = useNavigate(); const [togglePassword, setTogglePassword] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const [signupSuccess, setSignupSuccess] = useState(false); @@ -38,6 +38,7 @@ const Signup = () => { if (response.status === 200) { console.log('User registered successfully'); + navigate('/mentors'); } else { console.log('Error registering user:', response.data); diff --git a/src/pages/root/mentor/index.tsx b/src/pages/root/mentor/index.tsx index 6e12fff..1e0579d 100644 --- a/src/pages/root/mentor/index.tsx +++ b/src/pages/root/mentor/index.tsx @@ -79,24 +79,22 @@ const Mentors = () => { } else { setError(response.data.error); } - } catch (error) { + } catch (err) { setError(error as string); } setLoading(false); }; - const fetchUnallocatedStudents = async (query = "") => { - + const fetchUnallocatedStudents = async (mentorId: string, query = "") => { setLoadingStudents(true); - try { - const response = await apiClient.get(`/api/student/getmentorstudent`, { - params: { query }, + const response = await apiClient.get(`/api/mentor/getmentorstudent`, { + params: { mentorId, query }, }); if (response.data.success) { setStudents(response.data.students); } else { - setError(response.data.error); + setError(response.data.message); setStudents([]); } } catch (error) { @@ -125,6 +123,7 @@ const Mentors = () => { }; const handleMentorClick = (mentor: Mentor) => { + fetchUnallocatedStudents(mentor._id); navigate(`/studentdetails/${mentor._id}`); }; @@ -265,33 +264,13 @@ const Mentors = () => { const handleSearch = useCallback( debounce(async (query: string) => { - if (query) { - setLoadingStudents(true); - try { - const response = await apiClient.get( - `/api/student/getmentorstudent`, - { - params: { query }, - } - ); - if (response.data.success) { - setStudents(response.data.students); - } else { - setError(response.data.error); - setStudents([]); - } - } catch (error) { - setError("An error occurred while searching students."); - setStudents([]); - } finally { - setLoadingStudents(false); - } - } else { - fetchUnallocatedStudents(); + if (selectedMentor) { + fetchUnallocatedStudents(selectedMentor._id, query); } }, 500), - [] + [selectedMentor] ); + @@ -319,13 +298,13 @@ const Mentors = () => { const clearSearch = () => { setSearchQuery(""); setDebouncedSearchQuery(""); - fetchUnallocatedStudents(); + const mentorId = selectedMentor ? selectedMentor._id : null; + fetchUnallocatedStudents(mentorId ?? ""); }; useEffect(() => { fetchMentors(); - fetchUnallocatedStudents(); - }, []); + }, []); useEffect(() => { const handleClickOutside = (event: MouseEvent) => {