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