Skip to content

Commit

Permalink
BitWebApp#82 issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Hritabhash1 committed Jul 12, 2024
1 parent 74429f5 commit f72a230
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
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
12 changes: 5 additions & 7 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 Down Expand Up @@ -108,7 +109,7 @@ export default function ProjectForm() {

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 Down Expand Up @@ -273,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 @@ -325,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 f72a230

Please sign in to comment.