Skip to content

Commit

Permalink
Merge branch 'fix-question-edit-bug' into test-updated-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Jai2501 committed Nov 16, 2023
2 parents e6e5af7 + 831215c commit a19655c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions Frontend/src/Components/QuestionList/QuestionEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@ export const QuestionEdit = ({ q, index, updateQ, setEdit }) => {
}
};

const handleSubmit = (toggleEdit, editQ) => async e => {
e.preventDefault();
const handleSubmit = async (toggleEdit, editQ) => {
// e.preventDefault();
if(isEmpty(title) || isEmpty(difficulty) || isEmpty(topic) || isEmpty(description)) {
setIsMissingField(true);
setIsMissingField(true);
} else {
setIsMissingField(false);
const response = await editQ(q._id, title, description, difficulty, topic, language);
if(response.status === 200) {
toggleEdit(false);
} else {
let res = await response.json();
setErrorVar(res.errors)
}

setIsMissingField(false);

const response = await editQ(q._id, title, description, difficulty, topic, language);

if(response.status === 200) {
toggleEdit(false);
} else {
let res = await response.json();
setErrorVar(res.errors)
}
}
}

Expand Down Expand Up @@ -94,6 +97,7 @@ export const QuestionEdit = ({ q, index, updateQ, setEdit }) => {
<div className="btn-container">
<button type = "cancel" className="cancel-btn" onClick = {(e)=> {setEdit(false)}}>Cancel</button>
<button className="submit-btn" onClick = {(e) => {
e.preventDefault();
handleSubmit(setEdit, updateQ);
}}>Submit
</button>
Expand Down
4 changes: 2 additions & 2 deletions Frontend/src/Components/QuestionList/QuestionList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export const Questions = () => {

if (response.status === 200) {
setFilterApplied(false);
fetchQuestions();
return [];
await fetchQuestions();
return response;
} else {
return ['Unable to edit question'];
}
Expand Down

0 comments on commit a19655c

Please sign in to comment.