AEssayForm.tsx 948 Bytes
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import React, { useState } from "react";
2
import { EssayType, AnswersType } from "../types";
Lee SeoYeon's avatar
Lee SeoYeon committed
3

4
5
type Props = {
  element: EssayType;
6
  answers: AnswersType;
Jiwon Yoon's avatar
Jiwon Yoon committed
7
  handleAnswer: () => void;
8
9
};

10
11
12
13
14
export const AEssayForm = ({
  element,
  handleAnswer,
  answers: answers,
}: Props) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
15
16
17
18
  const [answer, setAnswer] = useState("");

  const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const { value } = event.currentTarget;
19
20
21
22
23
24
    // response.answers.map((a) => {
    //   if (a.questionId === element._id) {
    //     a.answer = value;
    //   }
    // });
    answers[element._id] = value;
Jiwon Yoon's avatar
Jiwon Yoon committed
25
26
27
    setAnswer(value);
    handleAnswer();
  };
Lee SeoYeon's avatar
Lee SeoYeon committed
28
  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
29
30
31
32
33
34
35
    <div className="flex mt-3 w-full justify-center">
      <input
        type="text"
        className="border w-11/12 h-36 my-3"
        id={element._id}
        onChange={handleChange}
        value={answer}
Jiwon Yoon's avatar
Jiwon Yoon committed
36
        required={element.isRequired}
Jiwon Yoon's avatar
Jiwon Yoon committed
37
      ></input>
Lee SeoYeon's avatar
Lee SeoYeon committed
38
39
40
    </div>
  );
};