AQuestion.tsx 2.55 KB
Newer Older
1
2
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
Jiwon Yoon's avatar
Jiwon Yoon committed
3
import { BasicQuestionType, AnswerType, SurveyType } from "../types";
Lee SeoYeon's avatar
Lee SeoYeon committed
4
5
6
import { ACheckboxForm } from "./ACheckboxForm";
import { ADateForm } from "./ADateForm";
import { ADropdownForm } from "./ADropdownForm";
7
import { AEssayForm } from "./AEssayForm";
8
import { AFileForm } from "./AFileForm";
9
import { ARadioForm } from "./ARadioForm";
Lee SeoYeon's avatar
Lee SeoYeon committed
10
import { ARatingForm } from "./ARatingForm";
11

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

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