AEssayForm.tsx 951 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;
Yoon, Daeki's avatar
Yoon, Daeki committed
6
  answers: AnswersType | undefined;
Jiwon Yoon's avatar
Jiwon Yoon committed
7
  handleAnswer: () => void;
8
9
};

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

  const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const { value } = event.currentTarget;
15
16
17
18
19
    // response.answers.map((a) => {
    //   if (a.questionId === element._id) {
    //     a.answer = value;
    //   }
    // });
Yoon, Daeki's avatar
Yoon, Daeki committed
20
    answers && (answers.answer = value);
Jiwon Yoon's avatar
Jiwon Yoon committed
21
22
23
    setAnswer(value);
    handleAnswer();
  };
Lee SeoYeon's avatar
Lee SeoYeon committed
24
  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
25
26
27
28
29
30
31
    <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
32
        required={element.isRequired}
Jiwon Yoon's avatar
Jiwon Yoon committed
33
      ></input>
Lee SeoYeon's avatar
Lee SeoYeon committed
34
35
36
    </div>
  );
};