AQuestion.tsx 2.07 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
8
import { ACheckboxForm } from "./ACheckbox";
import { ADropdownForm } from "./ADropdown";
import { AEssayForm } from "./AEssayForm";
import { ARadioForm } from "./ARadioForm";

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

  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
65
66
67
    <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>
68
      </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
69
      <div className="w-11/12 text-slate-500">{question.comment}</div>
70
71
72
73
      {getContent(question)}
    </div>
  );
};