Skip to content

Commit

Permalink
Merge branch 'nishant0708:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartikey2011yadav authored Sep 7, 2024
2 parents deb211f + 6f10f9c commit 36f5d09
Show file tree
Hide file tree
Showing 12 changed files with 636 additions and 98 deletions.
1 change: 1 addition & 0 deletions src/AlertModal/AlertModal.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
top: 0;
left: 0;
right: 0;
z-index: 2;
bottom: 0;
display: flex;
backdrop-filter: blur(12px);
Expand Down
29 changes: 21 additions & 8 deletions src/AlertModal/AlertModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
// iserror={true} if there is an error then iserror will be true else false
// />


import React from 'react';
import PropTypes from 'prop-types';
import Modal from 'react-modal';
import './AlertModal.css';
import cross from "../Assets/cross-mark.svg";
import tick from "../Assets/accept-check-good-mark-ok-tick.svg";

const AlertModal = ({ isOpen, onClose, onConfirm, message, iserror }) => {
var image = iserror ? cross : tick;

const handleClose = () => {
if (onConfirm) {
onConfirm(); // Trigger the callback for any action
}
onClose(); // Always close the modal
};

const AlertModal = ({ isOpen, onClose, message,iserror }) => {
var image = iserror? cross : tick
return (
<Modal
isOpen={isOpen}
Expand All @@ -32,22 +39,28 @@ const AlertModal = ({ isOpen, onClose, message,iserror }) => {
alt="Success"
className="alert_success-icon"
/>
<h2>
{iserror?"failed":"success"}
</h2>
<p>{message}</p> {/* Message passed as a prop */}
<button onClick={onClose} className="alert_close-button">Close</button>
<h2>{iserror ? "Failed" : "Success"}</h2>
<p>{message}</p>
<button onClick={handleClose} className="alert_close-button">
Close
</button>
</div>
</Modal>
);
};

// Define prop types
AlertModal.propTypes = {
isOpen: PropTypes.bool.isRequired, // isOpen should be a boolean
onClose: PropTypes.func.isRequired, // onClose should be a function
message: PropTypes.string.isRequired, // message should be a string
iserror: PropTypes.bool.isRequired
iserror: PropTypes.bool.isRequired, // iserror should be a boolean
onConfirm: PropTypes.func // onConfirm is optional and should be a function
};

// Set default prop for optional onConfirm
AlertModal.defaultProps = {
onConfirm: null
};

export default AlertModal;
5 changes: 5 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Reset_Password from './Reset_Password/Reset_Password';
import axios from 'axios';
import Question from './question/question';
import QuestionPaperDashboard from './QuestionPaperDashboard/QuestionPaperDashboard';
import Editpaper from './Edit_paper/Editpaper';
import ReadyPaperDashboard from './ReadyPaperDashboard/ReadyPaperDashboard';

const App = () => {
const [isAuthenticated, setIsAuthenticated] = useState(false);
Expand Down Expand Up @@ -61,8 +63,11 @@ const App = () => {
<>
<Route path="/teacherDashboard" element={<TeacherDashboard />} />
<Route path="/create-paper" element={<Createpaper />} />
<Route path="/edit-paper" element={<Editpaper/>} />
<Route path="/add-question/:paperId" element={<Question />} />
<Route path="/edit-question/:paperId/:questionId" element={<Question/>} />
<Route path="/questionPaperDashboard/:paperId" element={<QuestionPaperDashboard />}/>
<Route path="/ready_papers" element={<ReadyPaperDashboard />}/>
</>
)}
</Routes>
Expand Down
224 changes: 224 additions & 0 deletions src/Edit_paper/Editpaper.jsx
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;
2 changes: 1 addition & 1 deletion src/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Login() {

const handleLogin = (e) => {
e.preventDefault();
setIsLoading(true); // Start loading
setIsLoading(true);

axios
.post("http://localhost:5000/teacher/login", { email, password })
Expand Down
26 changes: 17 additions & 9 deletions src/Navbar/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

.navbar-links,
.navbar-logout {
width: 100px;
width: 160px;
height: 40px;
display: flex;
align-items: center;
Expand All @@ -50,21 +50,24 @@

.navbar-links.active {
background-color: #4caf50;
border-radius: 10px;
border: 2px solid white;
padding: 0px 0px 0px 5px;
color: #000000;
}

.navbar-logout {
width: 120px;
display: flex;
align-items: center;
justify-content: center;
gap: 5px;
margin-top: 10px;
background-color: #282828;
background-color: #1a1a1a;
transition: 0.3s all;
}

.navbar-logout:hover {
border-radius: 10px;
background-color: red;
border: 2px solid #1a1a1a;
transition: all 1s;
background-color: #181818;
color: red;
}

.navbar-menu {
Expand Down Expand Up @@ -109,7 +112,12 @@
.navbar-displayed {
display: none;
}


.navbar-sidebar-ul{
margin: 0px;
padding: 0px 20px;
}
.navbar-logout-menu,
.navbar-links {
background-color: #313030;
Expand All @@ -118,7 +126,7 @@
border: none;
border-radius: 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.253);
margin-left: -15px;

}

.navbar-logout-menu {
Expand Down
Loading

0 comments on commit 36f5d09

Please sign in to comment.