AQuestion.tsx 2.42 KB
Newer Older
1
import React from "react";
2
import { BasicQuestionType, AnswersType, AnswerProps } from "../types";
Lee SeoYeon's avatar
Lee SeoYeon committed
3
4
5
import { ACheckboxForm } from "./ACheckboxForm";
import { ADateForm } from "./ADateForm";
import { ADropdownForm } from "./ADropdownForm";
6
import { AEssayForm } from "./AEssayForm";
7
import { AFileForm } from "./AFileForm";
8
import { ARadioForm } from "./ARadioForm";
Lee SeoYeon's avatar
Lee SeoYeon committed
9
import { ARatingForm } from "./ARatingForm";
10

11
interface Props extends AnswerProps {
12
  addFiles: (oneFile: { questionId: string; file: File }) => void;
13
14
}

15
export const AQuestion = ({
16
  element,
17
  handleAnswer,
18
  answers,
19
20
  addFiles,
}: Props) => {
21
22
23
  function getContent(question: BasicQuestionType) {
    switch (question.type) {
      case "essay":
Jiwon Yoon's avatar
Jiwon Yoon committed
24
25
26
        return (
          <AEssayForm
            element={question}
27
            answers={answers}
Jiwon Yoon's avatar
Jiwon Yoon committed
28
29
30
            handleAnswer={handleAnswer}
          />
        );
31
      case "radio":
Jiwon Yoon's avatar
Jiwon Yoon committed
32
33
34
        return (
          <ARadioForm
            element={question}
35
            answers={answers}
Jiwon Yoon's avatar
Jiwon Yoon committed
36
37
38
            handleAnswer={handleAnswer}
          />
        );
39
      case "checkbox":
Jiwon Yoon's avatar
Jiwon Yoon committed
40
41
42
        return (
          <ACheckboxForm
            element={question}
43
            answers={answers}
Jiwon Yoon's avatar
Jiwon Yoon committed
44
45
46
            handleAnswer={handleAnswer}
          />
        );
47
      case "dropdown":
Jiwon Yoon's avatar
Jiwon Yoon committed
48
49
50
        return (
          <ADropdownForm
            element={question}
51
            answers={answers}
Jiwon Yoon's avatar
Jiwon Yoon committed
52
53
54
            handleAnswer={handleAnswer}
          />
        );
55
56
57
58
      case "file":
        return (
          <AFileForm
            element={question}
59
            answers={answers}
60
61
62
63
            handleAnswer={handleAnswer}
            addFiles={addFiles}
          />
        );
Lee SeoYeon's avatar
Lee SeoYeon committed
64
      case "rating":
Jiwon Yoon's avatar
Jiwon Yoon committed
65
66
67
        return (
          <ARatingForm
            element={question}
68
            answers={answers}
Jiwon Yoon's avatar
Jiwon Yoon committed
69
70
71
            handleAnswer={handleAnswer}
          />
        );
Lee SeoYeon's avatar
Lee SeoYeon committed
72
      case "date":
Jiwon Yoon's avatar
Jiwon Yoon committed
73
74
75
        return (
          <ADateForm
            element={question}
76
            answers={answers}
Jiwon Yoon's avatar
Jiwon Yoon committed
77
78
79
            handleAnswer={handleAnswer}
          />
        );
80
81
82
83
84
85
      default:
        return <></>;
    }
  }

  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
86
87
    <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">
88
        <div className="text-xl font-bold">{element.title}</div>
89
      </div>
90
91
      <div className="w-11/12 text-slate-500">{element.comment}</div>
      {getContent(element)}
92
93
94
    </div>
  );
};