Question.tsx 2.18 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import React, { useState } from "react";
Jiwon Yoon's avatar
Jiwon Yoon committed
2
3
import { BasicQuestionType } from "./CreateSurveyFormPage";
import { QEssay } from "./QEssay";
Jiwon Yoon's avatar
Jiwon Yoon committed
4
5
import { QCheckbox } from "./QCheckbox";
import { QRadio } from "./QRadio";
Jiwon Yoon's avatar
Jiwon Yoon committed
6
7
import { QDropdown } from "./QDropdown";
import { QFile } from "./QFile";
Jiwon Yoon's avatar
QRating    
Jiwon Yoon committed
8
import { QRating } from "./QRating";
9

Jiwon Yoon's avatar
Jiwon Yoon committed
10
11
12
13
type Props = {
  questionList: BasicQuestionType[];
  QuestionListChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
  addQuestion: () => void;
Jiwon Yoon's avatar
Jiwon Yoon committed
14
  changeCurrentId: (event: React.MouseEvent<HTMLButtonElement>) => void;
Jiwon Yoon's avatar
Jiwon Yoon committed
15
};
16

Jiwon Yoon's avatar
Jiwon Yoon committed
17
18
19
20
export const Question = ({
  questionList,
  QuestionListChange,
  addQuestion,
Jiwon Yoon's avatar
Jiwon Yoon committed
21
  changeCurrentId,
Jiwon Yoon's avatar
Jiwon Yoon committed
22
}: Props) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
23
24
25
26
27
  return (
    <>
      {console.log(questionList)}
      {questionList.map((element) => {
        switch (element.type) {
Jiwon Yoon's avatar
Jiwon Yoon committed
28
          case "essay":
Jiwon Yoon's avatar
Jiwon Yoon committed
29
            return (
Jiwon Yoon's avatar
Jiwon Yoon committed
30
              <QEssay
Jiwon Yoon's avatar
Jiwon Yoon committed
31
32
                element={element}
                QuestionListChange={QuestionListChange}
Jiwon Yoon's avatar
Jiwon Yoon committed
33
                changeCurrentId={changeCurrentId}
Jiwon Yoon's avatar
Jiwon Yoon committed
34
35
36
37
38
39
40
41
42
43
              />
            );
          case "radio":
            return (
              <QRadio
                element={element}
                QuestionListChange={QuestionListChange}
              />
            );
          case "checkbox":
Jiwon Yoon's avatar
Jiwon Yoon committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
            return (
              <QCheckbox
                element={element}
                QuestionListChange={QuestionListChange}
              />
            );
          case "dropdown":
            return (
              <QDropdown
                element={element}
                QuestionListChange={QuestionListChange}
              />
            );
          case "file":
            return (
              <QFile
                element={element}
                QuestionListChange={QuestionListChange}
              />
            );
Jiwon Yoon's avatar
QRating    
Jiwon Yoon committed
64
65
66
67
68
69
70
          case "rating":
            return (
              <QRating
                element={element}
                QuestionListChange={QuestionListChange}
              />
            );
Jiwon Yoon's avatar
Jiwon Yoon committed
71
72
73
74
          default:
            break;
        }
      })}
Jiwon Yoon's avatar
Jiwon Yoon committed
75
76
77
      <div className="flex w-4/5 content-center justify-center border-2 border-black h-8 mt-3">
        <button onClick={addQuestion}>질문 추가</button>
      </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
78
79
80
    </>
  );
};