CreateSurveyFormPage.tsx 3.77 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import React, { useState } from "react";
2
import { Question } from "./Question";
Jiwon Yoon's avatar
Jiwon Yoon committed
3
import { QuestionProvider } from "./question.context";
4

Jiwon Yoon's avatar
Jiwon Yoon committed
5
export interface BasicQuestionType {
6
  type: string;
Jiwon Yoon's avatar
Jiwon Yoon committed
7
  _id: string;
8
9
  title: string;
  isRequired: boolean;
Jiwon Yoon's avatar
Jiwon Yoon committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  comment: string;
  content: any;
  [key: string]: string | number | boolean | any;
}
export interface EssayType extends BasicQuestionType {}
export interface RadioType extends BasicQuestionType {
  content: {
    hasOther: boolean;
    choices: string[];
    otherText: string;
  };
}
export interface CheckboxType extends BasicQuestionType {
  content: {
    choices: string[];
    maxCount: number;
  };
}
export interface DropdownType extends BasicQuestionType {
  content: {
    choices: string[];
    hasNone: boolean;
  };
}
export interface FileType extends BasicQuestionType {
  content: {
    filename: string;
    value: string;
  };
}
export interface RatingType extends BasicQuestionType {
  content: {
Jiwon Yoon's avatar
QRating    
Jiwon Yoon committed
42
43
44
45
    rateValues: {
      value: number;
      text: string;
    }[];
Jiwon Yoon's avatar
Jiwon Yoon committed
46
47
48
    minRateDescription: string;
    maxRateDescription: string;
  };
49
50
}

Jiwon Yoon's avatar
Jiwon Yoon committed
51
52
const EssayQ: EssayType = {
  type: "essay",
Jiwon Yoon's avatar
Jiwon Yoon committed
53
  _id: "000000000000",
Jiwon Yoon's avatar
Jiwon Yoon committed
54
  title: "Question Title",
55
  isRequired: false,
Jiwon Yoon's avatar
Jiwon Yoon committed
56
57
58
59
60
  comment: "질문에 대한 설명을 입력해주세요",
  content: null,
};
const RadioQ: RadioType = {
  type: "radio",
Jiwon Yoon's avatar
Jiwon Yoon committed
61
  _id: "000000000001",
Jiwon Yoon's avatar
Jiwon Yoon committed
62
  title: "Question Title",
Jiwon Yoon's avatar
Jiwon Yoon committed
63
64
65
66
67
68
69
70
71
72
  isRequired: false,
  comment: "질문에 대한 설명을 입력해주세요",
  content: {
    hasOther: false,
    otherText: "",
    choices: ["radio1", "radio2", "radio3"],
  },
};
const CheckboxQ: CheckboxType = {
  type: "checkbox",
Jiwon Yoon's avatar
Jiwon Yoon committed
73
  _id: "000000000002",
Jiwon Yoon's avatar
Jiwon Yoon committed
74
  title: "Question Title",
Jiwon Yoon's avatar
Jiwon Yoon committed
75
76
77
78
79
80
81
82
83
  isRequired: false,
  comment: "질문에 대한 설명을 입력해주세요",
  content: {
    choices: ["check1", "check2", "check3"],
    maxCount: 2,
  },
};
const DropdownQ: DropdownType = {
  type: "dropdown",
Jiwon Yoon's avatar
Jiwon Yoon committed
84
  _id: "000000000003",
Jiwon Yoon's avatar
Jiwon Yoon committed
85
  title: "Question Title",
Jiwon Yoon's avatar
Jiwon Yoon committed
86
87
88
89
90
91
92
93
94
  isRequired: false,
  comment: "질문에 대한 설명을 입력해주세요",
  content: {
    choices: ["drop1", "drop2", "drop3"],
    hasNone: false,
  },
};
const FileQ: FileType = {
  type: "file",
Jiwon Yoon's avatar
Jiwon Yoon committed
95
  _id: "000000000004",
Jiwon Yoon's avatar
Jiwon Yoon committed
96
  title: "Question Title",
Jiwon Yoon's avatar
Jiwon Yoon committed
97
98
99
100
101
102
103
104
105
  isRequired: false,
  comment: "질문에 대한 설명을 입력해주세요",
  content: {
    filename: "",
    value: "",
  },
};
const RatingQ: RatingType = {
  type: "rating",
Jiwon Yoon's avatar
Jiwon Yoon committed
106
  _id: "000000000005",
Jiwon Yoon's avatar
Jiwon Yoon committed
107
  title: "Question Title",
Jiwon Yoon's avatar
Jiwon Yoon committed
108
109
110
  isRequired: false,
  comment: "질문에 대한 설명을 입력해주세요",
  content: {
Jiwon Yoon's avatar
QRating    
Jiwon Yoon committed
111
112
113
114
115
    rateValues: [
      { value: 1, text: "1" },
      { value: 2, text: "2" },
      { value: 3, text: "3" },
    ],
Jiwon Yoon's avatar
Jiwon Yoon committed
116
117
118
    minRateDescription: "가장 낮음",
    maxRateDescription: "가장 높음",
  },
119
120
};

Jiwon Yoon's avatar
Jiwon Yoon committed
121
export const CreateSurveyForm = () => {
Jiwon Yoon's avatar
Jiwon Yoon committed
122
  const [survey, setSurvey] = useState();
Jiwon Yoon's avatar
Jiwon Yoon committed
123
124
125
  const [error, setError] = useState("");
  const [disabled, setDisabled] = useState(false);
  const [success, setSuccess] = useState(false);
Jiwon Yoon's avatar
Jiwon Yoon committed
126
127

  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
128
    <>
Jiwon Yoon's avatar
Jiwon Yoon committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
      <QuestionProvider>
        <div className="flex flex-col place-items-center">
          <div className="flex flex-col container place-items-center mt-4">
            <input
              type="text"
              className="font-bold text-4xl text-center m-2 border-b-2"
              placeholder="설문지 제목"
            ></input>
            <textarea
              className="font-bold text-1xl text-center m-2 resize-none"
              placeholder="설문조사에 대한 설명을 입력해주세요"
              rows={2}
              cols={60}
            ></textarea>
          </div>
          <Question />
          <div>
Lee SeoYeon's avatar
Lee SeoYeon committed
146
            <button className="border rounded bg-themeColor my-5 py-2 px-3 font-bold text-white">
Jiwon Yoon's avatar
Jiwon Yoon committed
147
148
149
              설문조사 생성
            </button>
          </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
150
        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
151
      </QuestionProvider>
Jiwon Yoon's avatar
Jiwon Yoon committed
152
    </>
Jiwon Yoon's avatar
Jiwon Yoon committed
153
154
  );
};