ADateForm.tsx 851 Bytes
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import React, { useState } from "react";
2
import { DateType, AnswersType } from "../types";
Jiwon Yoon's avatar
Jiwon Yoon committed
3
4
type Props = {
  element: DateType;
Yoon, Daeki's avatar
Yoon, Daeki committed
5
  answers: AnswersType | undefined;
Jiwon Yoon's avatar
Jiwon Yoon committed
6
7
  handleAnswer: () => void;
};
8
export const ADateForm = ({ element, answers, handleAnswer }: Props) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
9
10
11
  const [answer, setAnswer] = useState("");
  const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const { value } = event.currentTarget;
12
13
14
15
16
    // response.answers.map((a) => {
    //   if (a.questionId === element._id) {
    //     a.answer = value;
    //   }
    // });
Yoon, Daeki's avatar
Yoon, Daeki committed
17
    answers && (answers.answer = value);
Jiwon Yoon's avatar
Jiwon Yoon committed
18
19
20
    setAnswer(value);
    handleAnswer();
  };
Lee SeoYeon's avatar
Lee SeoYeon committed
21
  return (
Lee SeoYeon's avatar
Lee SeoYeon committed
22
    <div className="justify-start w-11/12 m-3 py-4">
Jiwon Yoon's avatar
Jiwon Yoon committed
23
24
25
26
27
      <input
        type="date"
        onChange={handleChange}
        required={element.isRequired}
      ></input>
Lee SeoYeon's avatar
Lee SeoYeon committed
28
29
30
    </div>
  );
};