CreateSurveyFormPage.tsx 4.14 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
  comment: string;
  content: any;
  [key: string]: string | number | boolean | any;
}
export interface EssayType extends BasicQuestionType {}
export interface RadioType extends BasicQuestionType {
  content: {
    hasOther: boolean;
Lee SeoYeon's avatar
0708    
Lee SeoYeon committed
18
19
20
21
    choices: {
      value: number;
      text: string;
    }[];
Jiwon Yoon's avatar
Jiwon Yoon committed
22
23
24
25
26
    otherText: string;
  };
}
export interface CheckboxType extends BasicQuestionType {
  content: {
Lee SeoYeon's avatar
0708    
Lee SeoYeon committed
27
28
29
30
    choices: {
      value: number;
      text: string;
    }[];
Jiwon Yoon's avatar
Jiwon Yoon committed
31
32
33
34
35
    maxCount: number;
  };
}
export interface DropdownType extends BasicQuestionType {
  content: {
Lee SeoYeon's avatar
0708    
Lee SeoYeon committed
36
37
38
39
    choices: {
      value: number;
      text: string;
    }[];
Jiwon Yoon's avatar
Jiwon Yoon committed
40
41
42
43
44
45
46
47
48
49
50
    hasNone: boolean;
  };
}
export interface FileType extends BasicQuestionType {
  content: {
    filename: string;
    value: string;
  };
}
export interface RatingType extends BasicQuestionType {
  content: {
Lee SeoYeon's avatar
0708    
Lee SeoYeon committed
51
    choices: {
Jiwon Yoon's avatar
QRating    
Jiwon Yoon committed
52
53
54
      value: number;
      text: string;
    }[];
Jiwon Yoon's avatar
Jiwon Yoon committed
55
56
57
    minRateDescription: string;
    maxRateDescription: string;
  };
58
59
}

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

Jiwon Yoon's avatar
Jiwon Yoon committed
142
export const CreateSurveyForm = () => {
Jiwon Yoon's avatar
Jiwon Yoon committed
143
  const [survey, setSurvey] = useState();
Jiwon Yoon's avatar
Jiwon Yoon committed
144
145
146
  const [error, setError] = useState("");
  const [disabled, setDisabled] = useState(false);
  const [success, setSuccess] = useState(false);
Jiwon Yoon's avatar
Jiwon Yoon committed
147
148

  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
149
    <>
Jiwon Yoon's avatar
Jiwon Yoon committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
      <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
167
            <button className="border rounded bg-themeColor my-5 py-2 px-3 font-bold text-white">
Jiwon Yoon's avatar
Jiwon Yoon committed
168
169
170
              설문조사 생성
            </button>
          </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
171
        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
172
      </QuestionProvider>
Jiwon Yoon's avatar
Jiwon Yoon committed
173
    </>
Jiwon Yoon's avatar
Jiwon Yoon committed
174
175
  );
};