Skip to content

Commit

Permalink
Merge pull request #14 from tech-bash/main
Browse files Browse the repository at this point in the history
Add add gate result
  • Loading branch information
anurag629 authored Jul 7, 2024
2 parents ba1dc09 + 4389b65 commit 5a2e9fb
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useState } from 'react';
import { Box, TextField, MenuItem, Typography, Checkbox, Button, CircularProgress } from '@mui/material';

function AddCourse() {
const [formData, setFormData] = useState({
student_name: "",
student_batch: "",
roll_number: "",
student_photo: "",
});

const handleChange = (e) => {
const { name, value } = e.target;
setFormData({ ...formData, [name]: value });
};

const handleSubmit = (event) => {
event.preventDefault();
const token = localStorage.getItem('access_token');
var reqHeaders = new Headers();

reqHeaders = {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
};

const response = fetch("https://project-iet-tnp-bk.vercel.app/api/gate/gate-create/", {
method: 'POST',
headers: reqHeaders,
body: JSON.stringify(formData),
redirect: 'follow'
})
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
};

return (
<div>
<script src="https://static.airtable.com/js/embed/embed_snippet_v1.js"></script>
<iframe
className="airtable-embed airtable-dynamic-height"
src="https://airtable.com/embed/appZduFY0weOWiejW/shrF8ucBHliPSJRwJ?backgroundColor=cyan"
frameborder="0"
onmousewheel=""
width="1000px"
height="1717"
style={{background: 'transparent', border: '1px solid #ccc'}}
>

</iframe>
</div>
);
}

export default AddCourse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// ViewPlacementDetails.js

import React, { useEffect, useState } from 'react';

const ViewPlacementDetails = ({ gateResult, onClose, onUpdate }) => {
const [editedGateResult, setEditedGateResult] = useState({ ...gateResult });
const [offerLetterFile, setOfferLetterFile] = useState(null);
const [batch, setBatch] = useState([]);

const handleInputChange = (e) => {
const { name, value } = e.target;
setEditedGateResult((prevPlacement) => ({
...prevPlacement,
fields: {
...prevPlacement.fields,
[name]: value,
},
}));
};

const handleFileChange = (e) => {
const file = e.target.files[0];
// console.log(file);
setOfferLetterFile(file);
};

console.log(offerLetterFile);

const handleUpdate = () => {
// Make a PUT request to update the details
// Using the provided API endpoint 'https://project-iet-tnp-bk.vercel.app/api/gateResult/gateResult-update/id/'
const apiUrl = `https://project-iet-tnp-bk.vercel.app/api/gate/gate-update/${gateResult.record_id}/`;

const requestOptions = {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
roll_number: editedGateResult.roll_number,
student_name: editedGateResult.student_name,
student_branch: editedGateResult.student_branch,
student_batch: editedGateResult.student_batch[0],
registration_no: editedGateResult.registration_no,
rank: editedGateResult.rank,
}),

};

console.log(requestOptions.body);

fetch(apiUrl, requestOptions)
.then((response) => {
if (!response.ok) {
throw new Error(`Failed to update gateResult. Status: ${response.status}`);
}
return response.json();
})
.then((updatedPlacement) => {
onClose();
onUpdate(updatedPlacement);
console.log('Placement updated successfully!');
})
.catch((error) => {
console.error('Error updating gateResult:', error);
});
};

// Get all the batches from the API
const getAllBatches = () => {
const apiUrl = `https://project-iet-tnp-bk.vercel.app/api/gate/gate-list-all/`;

fetch(apiUrl)
.then((response) => response.json())
.then((result) => {
setBatch(result);
})
.catch((error) => {
console.error('Error fetching batches:', error);
});

return batch;
}



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

return (
<div className="fixed top-0 left-0 w-full h-full flex items-center justify-center">
<div className="absolute bg-white w-1/2 p-4 rounded shadow-lg">

<div className="mt-4">
<h3 className="text-lg font-semibold mb-2">Edit Details</h3>
<form>
<label className="block mb-2">
Batch:
<select
name="student_batch"
value={editedGateResult.student_batch}
onChange={handleInputChange}
className="form-select mt-1 block w-full"
>
{batch && batch.map((batch) => (
<option value={batch.id}>{batch.fields.batch}</option>
))}
</select>
</label>
<label name="student_name">
Student Name:
<input
type="text"
name="student_name"
value={editedGateResult.student_name}
onChange={handleInputChange}
className="form-input mt-1 block w-full"
/>
</label>
<label className="block mb-2">
Branch:
<select
name="student_branch"
value={editedGateResult.student_branch}
onChange={handleInputChange}
className="form-select mt-1 block w-full"
>
<option value="Computer Science & Engineering">Computer Science & Engineering</option>
<option value="Electronics & Communication Engineering">Electronics & Communication Engineering</option>
<option value="Mechanical Engineering">Mechanical Engineering</option>
<option value="Civil Engineering">Civil Engineering</option>
<option value="Electrical Engineering">Electrical Engineering</option>
</select>
</label>
<label name="registration_no">
Registration Number:
<input
type="number"
name="registration_no"
value={editedGateResult.student_salary}
onChange={handleInputChange}
min="0"
max="10000"
className="form-input mt-1 block w-full"
/>
</label>
<label name="status">
Status:
<select
name="status"
value={editedGateResult.fields.status}
onChange={handleInputChange}
className="form-select mt-1 block w-full"
>
<option value="selected">Approved</option>
<option value="not selected">Not Approved</option>
<option value="pending">Pending</option>
</select>
</label>
<label name="rank">
Rank:
<input
type="number"
name="rank"
value={editedGateResult.rank}
onChange={handleInputChange}
className="form-input mt-1 block w-full"
/>
</label>
</form>
</div>
<div className="flex mt-4">
<button
onClick={handleUpdate}
className="mr-2 bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
>
Update
</button>
<button
onClick={onClose}
className="bg-gray-500 text-white px-4 py-2 rounded hover:bg-gray-600"
>
Close
</button>
</div>
</div>
</div>
);
};

export default ViewPlacementDetails;
25 changes: 25 additions & 0 deletions src/components/dashboard/SideNavDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SideNavItemDashboard from "./SideNavItemDashboard"; // Import the new com
import Profile from "./DashboardComponent/Profile";
import AddCourse from "./DashboardComponent/Student/AddCourse";
import AddPlacement from "./DashboardComponent/Student/AddPlacement";
import AddGateResult from "./DashboardComponent/Student/AddGateResult";
import ViewCourseTeacher from "./DashboardComponent/Teacher/ViewCourseTeacher";
import ViewPlacementTeacher from "./DashboardComponent/Teacher/ViewPlacementTeacher";

Expand Down Expand Up @@ -124,6 +125,30 @@ const SideNavDashboard = () => {
},
]
: []),
...(userTypes[userData.user_type] === "Student"
? [
{
title: "Add Gate Result",
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25"
/>
</svg>
),
component: <AddGateResult />,
},
]
: []),
...(userTypes[userData.user_type] === "Teacher"
? [
{
Expand Down

0 comments on commit 5a2e9fb

Please sign in to comment.