Skip to content

Commit

Permalink
Merge pull request #90 from Hritabhash1/main
Browse files Browse the repository at this point in the history
#82 issue fixed
  • Loading branch information
BitWebApp authored Jul 12, 2024
2 parents e962212 + f72a230 commit 8ec1a55
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 43 deletions.
10 changes: 10 additions & 0 deletions frontend/src/components/ExamForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ const ExamForm = () => {
});
return;
}
const htmlContent = `
<div style="text-align: left; padding: 20px;">
<p><strong>Exam Roll:</strong> ${examRoll}</p>
<p><strong>Exam Name:</strong> ${examName}</p>
<p><strong>Academic Year:</strong> ${academicYear}</p>
<p><strong>Score:</strong> ${score}</p>
<p><strong>Cleared:</strong> ${isSel ? 'Yes' : 'No'}</p>
</div>
<p>Do you want to submit the form?</p>
`;
Swal.fire({
title: 'Are you sure?',
html: htmlContent,
Expand Down
19 changes: 15 additions & 4 deletions frontend/src/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,22 @@ export default function Header() {

const handleLogout = async () => {
try {
await axios.post('/api/v1/users/logout');
localStorage.removeItem('user');
navigate('/');
const response = await axios.post("/api/v1/users/logout");
console.log(response);
localStorage.removeItem("user");
navigate("/");
} catch (error) {
console.error(error);
console.log(error);
try {
const resp = await axios.post("/api/v1/admin/logout");
console.log(resp);
localStorage.removeItem("user");
navigate("/");
} catch (err) {
console.log(err);
}
} finally {
navigate("/");
}
};

Expand Down
55 changes: 29 additions & 26 deletions frontend/src/components/ProjectForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toast } from 'react-toastify';
import { ClipLoader } from 'react-spinners';
import Swal from 'sweetalert2';


export default function ProjectForm() {
const [projectName, setProjectName] = useState("");
const [domain, setDomain] = useState("");
Expand All @@ -18,7 +19,6 @@ export default function ProjectForm() {
const [editId, setEditId] = useState(null);
const [searchQuery, setSearchQuery] = useState('');
const [sortConfigs, setSortConfigs] = useState([]);
const [doc, setDoc] = useState([]);
const [loading, setLoading] = useState(false);

const navigate = useNavigate();
Expand All @@ -27,19 +27,18 @@ export default function ProjectForm() {
try {
const response = await axios.get(`/api/v1/project/show`, { withCredentials: true });
console.log('API Response:', response.data.data);
console.log(response.data.data);
setProj(response.data.data);
console.log(proj);
} catch (error) {
console.log(error.message, error);
toast.error('Failed to fetch projects');
}
};

const handleSubmit = async (e) => {
e.preventDefault();

const documentLink = idCard ? `<a href="${URL.createObjectURL(idCard)}" target="_blank" style=" margin-top: 10px;">(Click to View)</a>` : '';

const htmlContent = `
<div style="text-align: left; padding: 20px;">
<p style="font-size: 18px; margin: 10px 0; color: #333;">
Expand All @@ -66,13 +65,12 @@ export default function ProjectForm() {
Do you want to submit the form?
</p>
`;

Swal.fire({
title: 'Are you sure?',
html: htmlContent,
icon: 'warning',
showCancelButton: true,

confirmButtonText: 'Yes, submit it!',
cancelButtonText: 'No, cancel!',
buttonsStyling: true,
Expand All @@ -90,17 +88,28 @@ export default function ProjectForm() {
formData.append('projectLink', projectLink);
formData.append('techStack', techStack);
formData.append('guide', guide);
formData.append('projectId', idCard);

if (idCard) {
formData.append('project', idCard);
}

console.log('Form Data:', {
projectName,
domain,
projectLink,
techStack,
guide,
project: idCard,
});

const token = localStorage.getItem('accessToken');
const config = {
headers: { Authorization: `Bearer ${token}` },
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'multipart/form-data' },
withCredentials: true,
};

const response = await axios.post("/api/v1/project/projectCreate", formData, config);

if (response.data.success) {
if (response.success) {
toast.success("Data uploaded successfully!");
Swal.fire(
'Submitted!',
Expand All @@ -113,28 +122,25 @@ export default function ProjectForm() {
} else {
toast.error(response.data.message || 'Failed to create project record. Please try again.');
}

} catch (err) {
console.log(err);
console.log('Error:', err.response ? err.response.data : err);
toast.error("Error uploading data!");
} finally {
setSpin(false);
// setProj('');
setDoc([]);
setLoading(false);
fetchProject();
clearForm();
}
}
});
};


useEffect(() => {
fetchProject();
}, []);



const handleEdit = (project) => {
setProjectName(project.projectName);
setDomain(project.domain);
Expand Down Expand Up @@ -186,7 +192,7 @@ export default function ProjectForm() {
const filteredAndSortedProjects = sortProjects(proj.filter(project =>
project.projectName.toLowerCase().includes(searchQuery.toLowerCase())
));
console.log(filteredAndSortedProjects);

return (
<>
<div className="w-full min-h-screen flex justify-center items-center">
Expand Down Expand Up @@ -268,7 +274,7 @@ export default function ProjectForm() {
</div>
</div>
</div>
<table className="min-w-full divide-y divide-gray-200">
{/* <table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Expand Down Expand Up @@ -320,14 +326,11 @@ export default function ProjectForm() {
<span>No document available</span>
)}
</td>
{/* Uncomment this if you need the edit functionality */}
{/* <td className="px-6 py-4 whitespace-nowrap">
<button onClick={() => handleEdit(project)} className="text-blue-600 hover:text-blue-900">Edit</button>
</td> */}
</tr>
))}
</tbody>
</table>
</table> */}
</>
);
}
39 changes: 28 additions & 11 deletions frontend/src/components/StudentTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ const StudentTable = () => {
setSortConfigs(newSortConfigs);
};

const calculateProfileCompletion = (student) => {
const fields = [
"username",
"fullName",
"rollNumber",
"email",
"branch",
"section",
"semester",
"mobileNumber",
"placement",
"projects",
"awards",
"isVerified",
];
const filledFields = fields.filter(
(field) => student[field] && student[field] !== ""
);
return ((filledFields.length / fields.length) * 100).toFixed(2);
};

const sortedStudents = [...students].sort((a, b) => {
for (const config of sortConfigs) {
const aValue =
Expand Down Expand Up @@ -102,8 +123,7 @@ const StudentTable = () => {
record.section.toLowerCase().includes(query) ||
record.semester.toLowerCase().includes(query) ||
record.mobileNumber.toLowerCase().includes(query) ||
(record.placement &&
record.placement.toLowerCase().includes(query)) ||
(record.placement && record.placement.toLowerCase().includes(query)) ||
(record.projects &&
record.projects.some((project) => project.toLowerCase().includes(query))) ||
(record.awards &&
Expand All @@ -130,9 +150,10 @@ const StudentTable = () => {
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<input type="checkbox" />
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Profile Completion
</th>

<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Username
<div>
Expand Down Expand Up @@ -289,18 +310,13 @@ const StudentTable = () => {
</select>
</div>
</th>

</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{filteredStudents.map((student) => (
<tr key={student._id}>
<td className="px-6 py-4 whitespace-nowrap">
<input
type="checkbox"
checked={selectedRows.indexOf(student._id) !== -1}
onChange={() => handleRowSelect(student._id)}
/>
</td>
<td className="px-6 py-4 whitespace-nowrap">{calculateProfileCompletion(student)}%</td>
<td className="px-6 py-4 whitespace-nowrap">{student.username}</td>
<td className="px-6 py-4 whitespace-nowrap">{student.fullName}</td>
<td className="px-6 py-4 whitespace-nowrap">{student.rollNumber}</td>
Expand All @@ -313,6 +329,7 @@ const StudentTable = () => {
<td className="px-6 py-4 whitespace-nowrap">{student.projects ? "Yes" : "No"}</td>
<td className="px-6 py-4 whitespace-nowrap">{student.awards ? "Yes" : "No"}</td>
<td className="px-6 py-4 whitespace-nowrap">{student.isVerified ? "Yes" : "No"}</td>

</tr>
))}
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import react from "@vitejs/plugin-react";
export default defineConfig({
server: {
proxy: {
// "/api": "https://bitwebapp-24.onrender.com",
"/api": "http://localhost:8000",
"/api": "https://bitwebapp-24.onrender.com",
// "/api": "http://localhost:8000",
},
},
plugins: [react()],
Expand Down

0 comments on commit 8ec1a55

Please sign in to comment.