Commit 7275ba42 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

result에 맞게 다시 수정

parent 10f7f53d
......@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
type Props = {
question: IQuestionData;
answers: any;
};
export const RCheckbox = ({ question, answers }: Props) => {
const result = answers.flat().reduce((acc: any, cur: any) => {
export const RCheckbox = ({ question }: Props) => {
const result = question.answers.flat().reduce((acc: any, cur: any) => {
acc[cur] = (acc[cur] || 0) + 1;
return acc;
}, {});
......
......@@ -3,13 +3,12 @@ import { IQuestionData } from "../types";
type Props = {
question: IQuestionData;
answers: any;
};
export const RDate = ({ question, answers }: Props) => {
export const RDate = ({ question }: Props) => {
return (
<div className="m-5">
{answers.map((answer: any) => (
{question.answers.map((answer: any) => (
<div key={answer} className="font-bold">
{answer}
</div>
......
......@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
type Props = {
question: IQuestionData;
answers: any;
};
export const RDropdown = ({ question, answers }: Props) => {
const result = answers.reduce((acc: any, cur: any) => {
export const RDropdown = ({ question }: Props) => {
const result = question.answers.reduce((acc: any, cur: any) => {
acc[cur] = (acc[cur] || 0) + 1;
return acc;
}, {});
......
......@@ -3,13 +3,12 @@ import { IQuestionData } from "../types";
type Props = {
question: IQuestionData;
answers: any;
};
export const REssay = ({ question, answers }: Props) => {
export const REssay = ({ question }: Props) => {
return (
<div className="m-5">
{answers.map((answer: any, index: number) => (
{question.answers.map((answer: any, index: number) => (
<div key={index} className="font-bold">
{answer}
</div>
......
......@@ -3,14 +3,13 @@ import { baseImageUrl } from "../apis";
type Props = {
question: any;
answers: any;
};
export const RFile = ({ question, answers }: Props) => {
export const RFile = ({ question }: Props) => {
console.log("question", question);
return (
<div className="m-5 flex justify-start items-center">
{answers.map((answer: any, index: number) => (
{question.answers.map((answer: any, index: number) => (
<Fragment key={index}>
<img
className="h-14"
......
......@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
type Props = {
question: IQuestionData;
answers: any;
};
export const RRadio = ({ question, answers }: Props) => {
const result = answers.reduce((acc: any, cur: any) => {
export const RRadio = ({ question }: Props) => {
const result = question.answers.reduce((acc: any, cur: any) => {
acc[cur] = (acc[cur] || 0) + 1;
return acc;
}, {});
......
......@@ -3,11 +3,10 @@ import { IQuestionData } from "../types";
type Props = {
question: IQuestionData;
answers: any;
};
export const RRating = ({ question, answers }: Props) => {
const result = answers.reduce((acc: any, cur: any) => {
export const RRating = ({ question }: Props) => {
const result = question.answers.reduce((acc: any, cur: any) => {
acc[cur] = (acc[cur] || 0) + 1;
return acc;
}, {});
......
......@@ -109,25 +109,22 @@ export const getAnswerElementByType = (
}
};
export const getResultElementByType = (
question: IQuestionData,
answers: any
) => {
export const getResultElementByType = (question: IQuestionData) => {
switch (question.type) {
case "singletext":
return <REssay question={question} answers={answers} />;
return <REssay question={question} />;
case "radio":
return <RRadio question={question} answers={answers} />;
return <RRadio question={question} />;
case "checkbox":
return <RCheckbox question={question} answers={answers} />;
return <RCheckbox question={question} />;
case "dropdown":
return <RDropdown question={question} answers={answers} />;
return <RDropdown question={question} />;
case "file":
return <RFile question={question} answers={answers} />;
return <RFile question={question} />;
case "rating":
return <RRating question={question} answers={answers} />;
return <RRating question={question} />;
case "date":
return <RDate question={question} answers={answers} />;
return <RDate question={question} />;
default:
return <></>;
}
......
......@@ -4,10 +4,9 @@ import { getResultElementByType } from "../helpers/question.helper";
type AccordionProps = {
question: IQuestionData;
answers: any;
};
export const Accordion = ({ question, answers }: AccordionProps) => {
export const Accordion = ({ question }: AccordionProps) => {
const [isOpened, setOpened] = useState<boolean>(false);
const [height, setHeight] = useState<string>("0px");
const contentElement = useRef<HTMLDivElement>(null);
......@@ -33,7 +32,7 @@ export const Accordion = ({ question, answers }: AccordionProps) => {
style={{ height: height }}
className="bg-gray-100 overflow-hidden transition-all duration-300"
>
{answers && getResultElementByType(question, answers)}
{question.answers && getResultElementByType(question)}
</div>
</div>
</div>
......
......@@ -51,11 +51,7 @@ export const ResultSurvey = () => {
<div className="container w-11/12 place-self-center">
{survey.questions.map((question) => (
<Accordion
key={question._id}
question={question.questionInfo}
answers={question.answers}
/>
<Accordion key={question._id} question={question} />
))}
</div>
</div>
......
......@@ -34,6 +34,9 @@ export const getAnswers = async (surveyId: string) => {
$unwind: "$questionInfo",
},
{ $set: { "questionInfo.answers": "$answers" } },
{ $unset: "answers" },
// 질문 순서대로 정렬
{ $sort: { "questionInfo.order": 1 } },
......@@ -42,7 +45,7 @@ export const getAnswers = async (surveyId: string) => {
$group: {
_id: "$surveyId",
questions: {
$push: { questionInfo: "$questionInfo", answers: "$answers" },
$push: "$questionInfo",
},
},
},
......
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