AFileForm.tsx 1.1 KB
Newer Older
1
import React, { useState } from "react";
2
import { FileType, AnswersType, AnswerProps } from "../types";
3

4
interface Props extends AnswerProps {
5
  element: FileType;
Jiwon Yoon's avatar
Jiwon Yoon committed
6
  answerQuestion: any | undefined;
7
  addFiles: (oneFile: { questionId: string; file: File }) => void;
8
}
9

Jiwon Yoon's avatar
Jiwon Yoon committed
10
11
export const AFileForm = ({ element, answerQuestion, addFiles }: Props) => {
  const [answer, setAnswer] = useState("");
12
13
14
15
  const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    if (event.currentTarget.files) {
      const uploadFile = event.currentTarget.files[0];
      addFiles({ questionId: element._id, file: uploadFile });
Jiwon Yoon's avatar
Jiwon Yoon committed
16
17
18
19
20
21
22
23
      answerQuestion.answer = uploadFile.name;
      if (answerQuestion.answer) {
        answerQuestion.requiredCheck = true;
      } else {
        answerQuestion.requiredCheck = false;
      }
      setAnswer(uploadFile.name);
      console.log(answerQuestion);
24
25
26
27
28
29
30
31
32
33
34
35
36
    }
  };
  return (
    <div id="content" className="flex mt-4 w-full justify-center">
      <input
        type="file"
        name="file"
        className=" w-11/12 h-16"
        onChange={handleChange}
      ></input>
    </div>
  );
};