AQuestion.tsx 2.31 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";
4
5
6
7
import { ACheckboxForm } from "./ACheckbox";
import { ADropdownForm } from "./ADropdown";
import { AEssayForm } from "./AEssayForm";
import { ARadioForm } from "./ARadioForm";
8
import { AFileForm } from "./AFileForm";
9

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

  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
79
80
81
    <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>
82
      </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
83
      <div className="w-11/12 text-slate-500">{question.comment}</div>
84
85
86
87
      {getContent(question)}
    </div>
  );
};