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

설문 응답 폴더 구조 변경

parent 719a7a2b
import React, { useState } from "react"; import React, { useState } from "react";
import { CheckboxType, AnswersType } from "../types"; import { CheckboxType, AnswersType, AnswerProps } from "../types";
type Props = { interface Props extends AnswerProps {
element: CheckboxType; element: CheckboxType;
answers: AnswersType | undefined; }
handleAnswer: () => void;
};
export const ACheckboxForm = ({ element, answers, handleAnswer }: Props) => { export const ACheckboxForm = ({ element, answers, handleAnswer }: Props) => {
const [answer, setAnswer] = useState(""); const [answer, setAnswer] = useState("");
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.currentTarget; const { value } = event.currentTarget;
// response.answers.map((a) => {
// if (a.questionId === element._id) {
// a.answer = value;
// }
// });
answers && (answers.answer = value); answers && (answers.answer = value);
setAnswer(value); setAnswer(value);
handleAnswer(); handleAnswer();
......
import React, { useState } from "react"; import React, { useState } from "react";
import { DateType, AnswersType } from "../types"; import { AnswerProps } from "../types";
type Props = {
element: DateType; export const ADateForm = ({ element, answers, handleAnswer }: AnswerProps) => {
answers: AnswersType | undefined;
handleAnswer: () => void;
};
export const ADateForm = ({ element, answers, handleAnswer }: Props) => {
const [answer, setAnswer] = useState(""); const [answer, setAnswer] = useState("");
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.currentTarget; const { value } = event.currentTarget;
......
import React, { useState } from "react"; import React, { useState } from "react";
import { DropdownType, AnswersType } from "../types"; import { DropdownType, AnswerProps } from "../types";
type Props = { interface Props extends AnswerProps {
element: DropdownType; element: DropdownType;
answers: AnswersType | undefined; }
handleAnswer: () => void;
};
export const ADropdownForm = ({ element, handleAnswer, answers }: Props) => { export const ADropdownForm = ({ element, handleAnswer, answers }: Props) => {
const [answer, setAnswer] = useState(""); const [answer, setAnswer] = useState("");
const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => { const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const { value } = event.currentTarget; const { value } = event.currentTarget;
// response.answers.map((a) => {
// if (a.questionId === element._id) {
// a.answer = value;
// }
// });
answers && (answers.answer = value); answers && (answers.answer = value);
setAnswer(value); setAnswer(value);
handleAnswer(); handleAnswer();
......
import React, { useState } from "react"; import React, { useState } from "react";
import { EssayType, AnswersType } from "../types"; import { AnswerProps } from "../types";
type Props = { export const AEssayForm = ({ element, handleAnswer, answers }: AnswerProps) => {
element: EssayType;
answers: AnswersType | undefined;
handleAnswer: () => void;
};
export const AEssayForm = ({ element, handleAnswer, answers }: Props) => {
const [answer, setAnswer] = useState(""); const [answer, setAnswer] = useState("");
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.currentTarget; const { value } = event.currentTarget;
// response.answers.map((a) => {
// if (a.questionId === element._id) {
// a.answer = value;
// }
// });
answers && (answers.answer = value); answers && (answers.answer = value);
setAnswer(value); setAnswer(value);
handleAnswer(); handleAnswer();
......
import React, { useState } from "react"; import React, { useState } from "react";
import { FileType, AnswersType } from "../types"; import { FileType, AnswersType, AnswerProps } from "../types";
type Props = { interface Props extends AnswerProps {
element: FileType; element: FileType;
answers: AnswersType | undefined;
handleAnswer: () => void;
addFiles: (oneFile: { questionId: string; file: File }) => void; addFiles: (oneFile: { questionId: string; file: File }) => void;
}; }
export const AFileForm = ({ export const AFileForm = ({
element, element,
...@@ -18,11 +16,6 @@ export const AFileForm = ({ ...@@ -18,11 +16,6 @@ export const AFileForm = ({
if (event.currentTarget.files) { if (event.currentTarget.files) {
const uploadFile = event.currentTarget.files[0]; const uploadFile = event.currentTarget.files[0];
addFiles({ questionId: element._id, file: uploadFile }); addFiles({ questionId: element._id, file: uploadFile });
// response.answers.map((a) => {
// if (a.questionId === element._id) {
// a.answer = uploadFile.name;
// }
// });
answers && (answers.answer = uploadFile.name); answers && (answers.answer = uploadFile.name);
handleAnswer(); handleAnswer();
} }
......
import React from "react"; import React from "react";
import { BasicQuestionType, AnswersType } from "../types"; import { BasicQuestionType, AnswersType, AnswerProps } from "../types";
import { ACheckboxForm } from "./ACheckboxForm"; import { ACheckboxForm } from "./ACheckboxForm";
import { ADateForm } from "./ADateForm"; import { ADateForm } from "./ADateForm";
import { ADropdownForm } from "./ADropdownForm"; import { ADropdownForm } from "./ADropdownForm";
...@@ -8,16 +8,14 @@ import { AFileForm } from "./AFileForm"; ...@@ -8,16 +8,14 @@ import { AFileForm } from "./AFileForm";
import { ARadioForm } from "./ARadioForm"; import { ARadioForm } from "./ARadioForm";
import { ARatingForm } from "./ARatingForm"; import { ARatingForm } from "./ARatingForm";
type Props = { interface Props extends AnswerProps {
question: BasicQuestionType;
answer: AnswersType | undefined;
handleAnswer: () => void;
addFiles: (oneFile: { questionId: string; file: File }) => void; addFiles: (oneFile: { questionId: string; file: File }) => void;
}; }
export const AQuestion = ({ export const AQuestion = ({
question, element,
handleAnswer, handleAnswer,
answer, answers,
addFiles, addFiles,
}: Props) => { }: Props) => {
function getContent(question: BasicQuestionType) { function getContent(question: BasicQuestionType) {
...@@ -26,7 +24,7 @@ export const AQuestion = ({ ...@@ -26,7 +24,7 @@ export const AQuestion = ({
return ( return (
<AEssayForm <AEssayForm
element={question} element={question}
answers={answer} answers={answers}
handleAnswer={handleAnswer} handleAnswer={handleAnswer}
/> />
); );
...@@ -34,7 +32,7 @@ export const AQuestion = ({ ...@@ -34,7 +32,7 @@ export const AQuestion = ({
return ( return (
<ARadioForm <ARadioForm
element={question} element={question}
answers={answer} answers={answers}
handleAnswer={handleAnswer} handleAnswer={handleAnswer}
/> />
); );
...@@ -42,7 +40,7 @@ export const AQuestion = ({ ...@@ -42,7 +40,7 @@ export const AQuestion = ({
return ( return (
<ACheckboxForm <ACheckboxForm
element={question} element={question}
answers={answer} answers={answers}
handleAnswer={handleAnswer} handleAnswer={handleAnswer}
/> />
); );
...@@ -50,7 +48,7 @@ export const AQuestion = ({ ...@@ -50,7 +48,7 @@ export const AQuestion = ({
return ( return (
<ADropdownForm <ADropdownForm
element={question} element={question}
answers={answer} answers={answers}
handleAnswer={handleAnswer} handleAnswer={handleAnswer}
/> />
); );
...@@ -58,7 +56,7 @@ export const AQuestion = ({ ...@@ -58,7 +56,7 @@ export const AQuestion = ({
return ( return (
<AFileForm <AFileForm
element={question} element={question}
answers={answer} answers={answers}
handleAnswer={handleAnswer} handleAnswer={handleAnswer}
addFiles={addFiles} addFiles={addFiles}
/> />
...@@ -67,7 +65,7 @@ export const AQuestion = ({ ...@@ -67,7 +65,7 @@ export const AQuestion = ({
return ( return (
<ARatingForm <ARatingForm
element={question} element={question}
answers={answer} answers={answers}
handleAnswer={handleAnswer} handleAnswer={handleAnswer}
/> />
); );
...@@ -75,7 +73,7 @@ export const AQuestion = ({ ...@@ -75,7 +73,7 @@ export const AQuestion = ({
return ( return (
<ADateForm <ADateForm
element={question} element={question}
answers={answer} answers={answers}
handleAnswer={handleAnswer} handleAnswer={handleAnswer}
/> />
); );
...@@ -87,10 +85,10 @@ export const AQuestion = ({ ...@@ -87,10 +85,10 @@ export const AQuestion = ({
return ( return (
<div className="flex flex-col container w-4/5 h-auto border-2 border-themeColor items-center m-3 py-4"> <div className="flex flex-col container w-4/5 h-auto border-2 border-themeColor items-center m-3 py-4">
<div className="flex flexgi-row my-1 w-11/12 place-content-between items-center"> <div className="flex flexgi-row my-1 w-11/12 place-content-between items-center">
<div className="text-xl font-bold">{question.title}</div> <div className="text-xl font-bold">{element.title}</div>
</div> </div>
<div className="w-11/12 text-slate-500">{question.comment}</div> <div className="w-11/12 text-slate-500">{element.comment}</div>
{getContent(question)} {getContent(element)}
</div> </div>
); );
}; };
import React, { useState } from "react"; import React, { useState } from "react";
import { RadioType, AnswersType } from "../types"; import { RadioType, AnswersType, AnswerProps } from "../types";
type Props = { interface Props extends AnswerProps {
element: RadioType; element: RadioType;
answers: AnswersType | undefined; }
handleAnswer: () => void;
};
export const ARadioForm = ({ element, answers, handleAnswer }: Props) => { export const ARadioForm = ({ element, answers, handleAnswer }: Props) => {
const [answer, setAnswer] = useState(""); const [answer, setAnswer] = useState("");
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.currentTarget; const { value } = event.currentTarget;
// response.answers.map((a) => {
// if (a.questionId === element._id) {
// a.answer = value;
// }
// });
answers && (answers.answer = value); answers && (answers.answer = value);
setAnswer(value); setAnswer(value);
handleAnswer(); handleAnswer();
...@@ -24,7 +17,7 @@ export const ARadioForm = ({ element, answers, handleAnswer }: Props) => { ...@@ -24,7 +17,7 @@ export const ARadioForm = ({ element, answers, handleAnswer }: Props) => {
return ( return (
<div className="flex w-full gap-2 justify-around my-3"> <div className="flex w-full gap-2 justify-around my-3">
{element.content.choices.map((choice) => ( {element.content.choices.map((choice) => (
<div> <div key={choice.text}>
<input <input
className="mr-2" className="mr-2"
type="radio" type="radio"
......
import React, { useState } from "react"; import React, { useState } from "react";
import { RatingType, AnswersType } from "../types"; import { RatingType, AnswersType, AnswerProps } from "../types";
type Props = { interface Props extends AnswerProps {
element: RatingType; element: RatingType;
answers: AnswersType | undefined; }
handleAnswer: () => void;
};
export const ARatingForm = ({ element, answers, handleAnswer }: Props) => { export const ARatingForm = ({ element, answers, handleAnswer }: Props) => {
const [selectedchoice, setSelectedchoice] = useState(""); const [selectedchoice, setSelectedchoice] = useState("");
...@@ -14,11 +12,6 @@ export const ARatingForm = ({ element, answers, handleAnswer }: Props) => { ...@@ -14,11 +12,6 @@ export const ARatingForm = ({ element, answers, handleAnswer }: Props) => {
function buttonClick(event: React.MouseEvent<HTMLButtonElement>) { function buttonClick(event: React.MouseEvent<HTMLButtonElement>) {
event.preventDefault(); event.preventDefault();
const { name } = event.currentTarget; const { name } = event.currentTarget;
// response.answers.map((a) => {
// if (a.questionId === element._id) {
// a.answer = name;
// }
// });
answers && (answers.answer = name); answers && (answers.answer = name);
setAnswer(name); setAnswer(name);
setSelectedchoice(event.currentTarget.name); setSelectedchoice(event.currentTarget.name);
......
...@@ -5,7 +5,7 @@ import { catchErrors } from "../helpers"; ...@@ -5,7 +5,7 @@ import { catchErrors } from "../helpers";
import { AnswerType, SurveyType } from "../types"; import { AnswerType, SurveyType } from "../types";
import { AQuestion } from "./AQuestion"; import { AQuestion } from "./AQuestion";
export const SurveyForm = () => { export const AnswerSurveyForm = () => {
let { surveyId } = useParams<{ surveyId: string }>(); let { surveyId } = useParams<{ surveyId: string }>();
const [files, setFiles] = useState<{ questionId: string; file: File }[]>([]); const [files, setFiles] = useState<{ questionId: string; file: File }[]>([]);
const [error, setError] = useState(""); const [error, setError] = useState("");
...@@ -41,11 +41,6 @@ export const SurveyForm = () => { ...@@ -41,11 +41,6 @@ export const SurveyForm = () => {
}); });
console.log(questionIds); console.log(questionIds);
if (answersurvey) { if (answersurvey) {
// setResponse({
// ...answer,
// surveyId: answersurvey._id,
// answers: questionIds,
// });
answer.current.surveyId = answersurvey._id; answer.current.surveyId = answersurvey._id;
answer.current.guestId = answersurvey.guestId; answer.current.guestId = answersurvey.guestId;
answer.current.answers = questionIds; answer.current.answers = questionIds;
...@@ -108,8 +103,9 @@ export const SurveyForm = () => { ...@@ -108,8 +103,9 @@ export const SurveyForm = () => {
{survey.questions.map((question) => { {survey.questions.map((question) => {
return ( return (
<AQuestion <AQuestion
question={question} key={question._id}
answer={answer.current.answers.find( element={question}
answers={answer.current.answers.find(
(ans) => ans.questionId === question._id (ans) => ans.questionId === question._id
)} )}
addFiles={addFiles} addFiles={addFiles}
......
export { AnswerSurveyForm } from "./AnswerSurveyForm";
export { Header } from "./Header"; export { Header } from "./Header";
export { SurveyForm } from "./SurveyForm";
\ No newline at end of file
...@@ -167,6 +167,7 @@ export const Question = ({ ...@@ -167,6 +167,7 @@ export const Question = ({
> >
{Array.from(typeDropDown.entries()).map(([key, value]) => ( {Array.from(typeDropDown.entries()).map(([key, value]) => (
<option <option
key={key}
id={element._id} id={element._id}
value={key} value={key}
selected={key === element.type} selected={key === element.type}
......
...@@ -44,22 +44,21 @@ export interface RadioType extends BasicQuestionType { ...@@ -44,22 +44,21 @@ export interface RadioType extends BasicQuestionType {
}; };
} }
interface IChoices {
value: number;
text: string;
}
export interface CheckboxType extends BasicQuestionType { export interface CheckboxType extends BasicQuestionType {
content: { content: {
choices: { choices: IChoices[];
value: number;
text: string;
}[];
maxCount: number; maxCount: number;
}; };
} }
export interface DropdownType extends BasicQuestionType { export interface DropdownType extends BasicQuestionType {
content: { content: {
choices: { choices: IChoices[];
value: number;
text: string;
}[];
hasNone: boolean; hasNone: boolean;
}; };
} }
...@@ -93,3 +92,9 @@ export interface AnswerType { ...@@ -93,3 +92,9 @@ export interface AnswerType {
guestId: string; guestId: string;
answers: AnswersType[]; answers: AnswersType[];
} }
export interface AnswerProps {
element: BasicQuestionType;
answers: AnswersType | undefined;
handleAnswer: () => void;
}
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