Commit b66cfbf5 authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

editing 상태 수정

parent dce3cbcd
...@@ -59,7 +59,7 @@ export const Question = ({ ...@@ -59,7 +59,7 @@ export const Question = ({
selectedType === "dropdown" || selectedType === "dropdown" ||
selectedType === "checkbox" selectedType === "checkbox"
) { ) {
element.content = { content = {
choices: [{ text: "", value: 0 }], choices: [{ text: "", value: 0 }],
}; };
} else if (selectedType === "essay") { } else if (selectedType === "essay") {
......
...@@ -94,17 +94,20 @@ export const CreateSurvey = () => { ...@@ -94,17 +94,20 @@ export const CreateSurvey = () => {
async function addQuestion() { async function addQuestion() {
try { try {
if (surveyId) { if (surveyId) {
const questions: BasicQuestionType[] = await questionApi.createQuestion( // const questions: BasicQuestionType[] = await questionApi.createQuestion(
// surveyId
// );
// console.log(questions);
const question: BasicQuestionType = await questionApi.createQuestion(
surveyId surveyId
); );
console.log(questions); console.log(question);
const addedEditing = questions.map((question) => {
return { qid: question._id, isEditing: false }; isEditing &&
}); setIsEditing([...isEditing, { qid: question._id, isEditing: true }]);
console.log("added editing", addedEditing);
setIsEditing([...addedEditing]);
setSurvey({ ...survey, questions: questions }); // setSurvey({ ...survey, questions: questions });
setSurvey({ ...survey, questions: [...questions, question] });
setSuccess(true); setSuccess(true);
setError(""); setError("");
} else { } else {
......
...@@ -96,18 +96,24 @@ export const EditSurvey = () => { ...@@ -96,18 +96,24 @@ export const EditSurvey = () => {
async function addQuestion() { async function addQuestion() {
try { try {
if (surveyId) { if (surveyId) {
const questions: BasicQuestionType[] = await questionApi.createQuestion( // const questions: BasicQuestionType[] = await questionApi.createQuestion(
// surveyId
// );
// console.log(questions);
const question: BasicQuestionType = await questionApi.createQuestion(
surveyId surveyId
); );
console.log(questions); console.log(question);
const addedEditing = questions.map((question) => { // const addedEditing = questions.map((question) => {
return { qid: question._id, isEditing: false }; // return { qid: question._id, isEditing: false };
}); // });
console.log("added editing", addedEditing); // console.log("added editing", addedEditing);
setIsEditing([...addedEditing]); isEditing &&
setIsEditing([...isEditing, { qid: question._id, isEditing: true }]);
setSurvey({ ...survey, questions: questions }); // setSurvey({ ...survey, questions: questions });
setSurvey({ ...survey, questions: [...questions, question] });
setSuccess(true); setSuccess(true);
setError(""); setError("");
} else { } else {
......
...@@ -24,7 +24,8 @@ export const createQuestion = asyncWrap( ...@@ -24,7 +24,8 @@ export const createQuestion = asyncWrap(
surveyId surveyId
); );
console.log(updatedSurvey); console.log(updatedSurvey);
return res.json(updatedSurvey?.questions); // return res.json(updatedSurvey?.questions);
return res.json(newQuestion);
} }
} catch (error: any) { } catch (error: any) {
return res return res
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment