Skip to content

Commit

Permalink
Merge pull request #3 from TanishqMehrunkarIIPSDAVV/add-question
Browse files Browse the repository at this point in the history
answer added
  • Loading branch information
Kartikey2011yadav authored Oct 1, 2024
2 parents d7f79f2 + d74f14f commit ebe1832
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/AddQuestion/AddQuestion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import './AddQuestion.css';
import { useEffect, useState } from 'react';
import axios from 'axios';
import AlertModal from '../AlertModel/AlertModel';
import { useNavigate } from 'react-router-dom';

const AddQuestion = () => {
const navigate = useNavigate();
const [isFlex, setIsFlex] = useState(true);
const [tags, setTags] = useState([]);
const [loading, setLoading] = useState(false);
Expand All @@ -22,6 +24,7 @@ const AddQuestion = () => {
const [marks, setMarks] = useState('');
const [option, setOption] = useState('');
const [mcqOptions, setMcqOptions] = useState([]);
const [mcqAnswer, setMcqAnswer] = useState('');
const [expectedTime, setExpectedTime] = useState({});
const [hours, setHours] = useState('');
const [minutes, setMinutes] = useState('');
Expand Down Expand Up @@ -103,9 +106,24 @@ const AddQuestion = () => {
return true;
};

const validateAnswer = () => {
if (option === 'mcq') {
const index = mcqOptions.indexOf(mcqAnswer);
if (index === -1) return false;
return true;
}
return true;
};

const handleSubmit = async (e) => {
e.preventDefault();
if (!validateTime()) return;
if (!validateAnswer()) {
setModalMessage('In MCQ type question, answer should be among the options provided!!!');
setModalIsError(true);
setModalIsOpen(true);
return;
}
setLoading(true);
const teacherId = localStorage.getItem('teacherId');
try {
Expand All @@ -117,6 +135,7 @@ const AddQuestion = () => {
marks,
option,
mcqOptions,
mcqAnswer,
expectedTime,
divTag,
});
Expand Down Expand Up @@ -357,6 +376,19 @@ const AddQuestion = () => {
) : (
<></>
)}
<label>Question Answer:</label>
<center>
<div className="add-question-input-container">
<input
type="text"
placeholder="Enter the Answer:"
onChange={(e) => {
setMcqAnswer(e.target.value);
}}
required
/>
</div>
</center>
<label>Question Tags:</label>
<center>
<div className="add-question-input-container">
Expand Down Expand Up @@ -430,6 +462,7 @@ const AddQuestion = () => {
isOpen={modalIsOpen}
onClose={() => {
setModalIsOpen(false);
navigate('/questions-upload');
}}
isError={modalIsError}
message={modalMessage}
Expand Down
3 changes: 3 additions & 0 deletions src/QuestionsUpload/QuestionsUpload.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ hr {
object-fit: cover;
border-radius: 5px;
}
.question-upload-answer {
padding-bottom: 10px;
}
@media (max-width: 720px) {
.question-upload-add-question {
font-size: 12px;
Expand Down
1 change: 1 addition & 0 deletions src/QuestionsUpload/QuestionsUpload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const QuestionsUpload = () => {
</div>
</div>
)}
<div className="question-upload-answer">Answer: &nbsp;{question.mcqAnswer}</div>
</div>
))}
</div>
Expand Down

0 comments on commit ebe1832

Please sign in to comment.