-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'nishant0708:master' into master
- Loading branch information
Showing
12 changed files
with
636 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
top: 0; | ||
left: 0; | ||
right: 0; | ||
z-index: 2; | ||
bottom: 0; | ||
display: flex; | ||
backdrop-filter: blur(12px); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
import React, { useState } from 'react'; | ||
import ReactDatePicker from 'react-datepicker'; | ||
import 'react-datepicker/dist/react-datepicker.css'; | ||
import '../papers/papers.css'; | ||
import PropTypes from 'prop-types'; | ||
import Navbar from '../Navbar/Navbar'; | ||
import axios from 'axios'; | ||
import { useNavigate,useLocation } from 'react-router-dom'; | ||
import AlertModal from '../AlertModal/AlertModal'; // Import AlertModal | ||
|
||
const Editpaper = () => { | ||
const location = useLocation(); // Taking Current Values | ||
const current_values = location.state; | ||
|
||
const [date, setDate] = useState(current_values.date); | ||
const [time, setTime] = useState(current_values.time); | ||
const [duration, setDuration] = useState({ hours: current_values.duration.hours, minutes: current_values.duration.minutes }); | ||
const [marks, setMarks] = useState(current_values.marks); | ||
const [testType, setTestType] = useState(current_values.testType); | ||
const [className, setClassName] = useState(current_values.className); | ||
const [semester, setSemester] = useState(current_values.semester); | ||
const [subject, setSubject] = useState(current_values.subject); | ||
const [subjectCode, setSubjectCode] = useState(current_values.subjectCode); | ||
const teacherId = localStorage.getItem("teacherId"); | ||
|
||
const [modalIsOpen, setModalIsOpen] = useState(false); | ||
const [modalMessage, setModalMessage] = useState(''); | ||
const [isError, setIsError] = useState(false); | ||
const navigate = useNavigate(); | ||
const handleDurationChange = (field, value) => { | ||
if (value >= 0) { | ||
setDuration({ ...duration, [field]: value }); | ||
} | ||
}; | ||
|
||
const handleMarksChange = (e) => { | ||
const value = e.target.value.replace(/[^0-9]/g, ''); | ||
setMarks(value); | ||
}; | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
|
||
const paperData = { | ||
_id:current_values._id, | ||
className, | ||
semester, | ||
subject, | ||
marks, | ||
duration: { | ||
hours: duration.hours, | ||
minutes: duration.minutes, | ||
}, | ||
subjectCode, | ||
time, | ||
date, | ||
testType, | ||
teacherId, | ||
}; | ||
|
||
try { | ||
await axios.post('http://localhost:5000/paper/edit-paper', paperData); | ||
// console.log('Paper created successfully:', response.data); | ||
|
||
setModalMessage('Paper edited successfully!'); | ||
setIsError(false); | ||
setModalIsOpen(true); | ||
|
||
|
||
// const { paperId } = response.data; | ||
|
||
// Navigate to the QuestionPaperDashboard with the created paper's ID | ||
navigate(`/teacherDashboard`); | ||
} catch (error) { | ||
console.error('Error creating paper:', error); | ||
|
||
setModalMessage('Failed to create paper. Please try again.'); | ||
setIsError(true); | ||
setModalIsOpen(true); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Navbar /> | ||
<div className="create_paper_container"> | ||
<form className="create_paper_form" onSubmit={handleSubmit}> | ||
<div className='create_paper_row'> | ||
<FormGroup label="Class:" className="create_paper_class"> | ||
<select className="create_paper_input" value={className} onChange={(e) => setClassName(e.target.value)}> | ||
<option value="">Select Class</option> | ||
<option value="Mtech">Mtech</option> | ||
<option value="Mca">Mca</option> | ||
</select> | ||
</FormGroup> | ||
|
||
<FormGroup label="Semester:" className="create_paper_semester"> | ||
<select className="create_paper_input" value={semester} onChange={(e) => setSemester(e.target.value)}> | ||
<option value="">Select Semester</option> | ||
{Array.from({ length: 10 }, (_, i) => ( | ||
<option key={i + 1} value={`${i + 1}th Sem`}>{`${i + 1}th Sem`}</option> | ||
))} | ||
</select> | ||
</FormGroup> | ||
</div> | ||
|
||
<FormGroup label="Subject:" className="create_paper_subject"> | ||
<input | ||
type="text" | ||
className="create_paper_input" | ||
placeholder="Subject" | ||
value={subject} | ||
onChange={(e) => setSubject(e.target.value)} | ||
/> | ||
</FormGroup> | ||
|
||
<div className='create_paper_row'> | ||
<FormGroup label="Marks:" className="create_paper_marks"> | ||
<input | ||
type="tel" | ||
className="create_paper_input" | ||
placeholder="Marks" | ||
value={marks} | ||
onChange={handleMarksChange} | ||
/> | ||
</FormGroup> | ||
|
||
<FormGroup label="Duration:" className="create_paper_duration"> | ||
<div className="create_paper_duration_inputs"> | ||
<input | ||
type="number" | ||
placeholder="Hours" | ||
className="create_paper_input create_paper_duration_hours" | ||
value={duration.hours} | ||
onChange={(e) => handleDurationChange('hours', e.target.value)} | ||
/> | ||
: | ||
<input | ||
type="number" | ||
placeholder="Minutes" | ||
className="create_paper_input create_paper_duration_minutes" | ||
value={duration.minutes} | ||
onChange={(e) => handleDurationChange('minutes', e.target.value)} | ||
/> | ||
</div> | ||
</FormGroup> | ||
</div> | ||
|
||
<div className='create_paper_row'> | ||
<FormGroup label="Subject Code:" className="create_paper_subject_code"> | ||
<input | ||
type="text" | ||
className="create_paper_input" | ||
placeholder="Subject Code" | ||
value={subjectCode} | ||
onChange={(e) => setSubjectCode(e.target.value)} | ||
/> | ||
|
||
|
||
</FormGroup> | ||
|
||
<FormGroup label="Time: (24 hrs format)" className="create_paper_time"> | ||
<input | ||
type="time" | ||
className="create_paper_input" | ||
value={time} | ||
onChange={(e) => setTime(e.target.value)} | ||
/> | ||
</FormGroup> | ||
</div> | ||
|
||
<div className='create_paper_row'> | ||
<FormGroup label="Date of Examination:" className="create_paper_date"> | ||
<ReactDatePicker | ||
selected={date} | ||
onChange={(date) => setDate(date)} | ||
dateFormat="dd/MM/yyyy" | ||
className="create_paper_input" | ||
placeholderText="DD / MM / YYYY" | ||
/> | ||
</FormGroup> | ||
|
||
<FormGroup label="Test Type:" className="create_paper_test_type"> | ||
<select className="create_paper_input" value={testType} onChange={(e) => setTestType(e.target.value)}> | ||
<option value="">Select Test Type</option> | ||
<option value="Internal 1">Internal 1</option> | ||
<option value="Internal 2">Internal 2</option> | ||
<option value="Internal 3">Internal 3</option> | ||
<option value="Endsem">Endsem</option> | ||
</select> | ||
</FormGroup> | ||
</div> | ||
|
||
<button type="submit" className="create_paper_submit_btn">EDIT</button> | ||
</form> | ||
</div> | ||
|
||
{/* Alert Modal */} | ||
<AlertModal | ||
isOpen={modalIsOpen} | ||
onClose={() => setModalIsOpen(false)} | ||
message={modalMessage} | ||
iserror={isError} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
const FormGroup = ({ label, children, className }) => { | ||
return ( | ||
<div className={`create_paper_group ${className}`}> | ||
<label className="create_paper_label">{label}</label> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
FormGroup.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
children: PropTypes.node.isRequired, | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default Editpaper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.