AQuestion.tsx 2.47 KB
Newer Older
1
2
import React from "react";
import { BasicQuestionType, AnswersType } 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

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

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