Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/pages/auth/Singup.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -18,7 +18,7 @@ const Signup = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState<SignUpError | null>(null);

const navigate = useNavigate();
const [togglePassword, setTogglePassword] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [signupSuccess, setSignupSuccess] = useState(false);
Expand All @@ -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);
Expand Down
47 changes: 13 additions & 34 deletions src/pages/root/mentor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -125,6 +123,7 @@ const Mentors = () => {
};

const handleMentorClick = (mentor: Mentor) => {
fetchUnallocatedStudents(mentor._id);
navigate(`/studentdetails/${mentor._id}`);
};

Expand Down Expand Up @@ -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]
);




Expand Down Expand Up @@ -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) => {
Expand Down