AFile.tsx 1.13 KB
Newer Older
1
import React, { useState } from "react";
2
import { IAnswerProps } from "../types";
3

4
5
interface Props extends IAnswerProps {
  // addFiles: (oneFile: { questionId: string; file: File }) => void;
6
}
7

8
export const AFile = ({ element, answer: answerQuestion }: Props) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
9
  const [answer, setAnswer] = useState("");
10
11
  const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    if (event.currentTarget.files) {
12
13
14
15
16
17
      const uploadFiles = event.currentTarget.files;
      // const uploadFile = event.currentTarget.files[0];
      // addFiles({ questionId: element._id, file: uploadFile });
      // answerQuestion.content = uploadFile.name;
      answerQuestion.content = uploadFiles;
      if (answerQuestion.content) {
Jiwon Yoon's avatar
Jiwon Yoon committed
18
19
20
21
        answerQuestion.requiredCheck = true;
      } else {
        answerQuestion.requiredCheck = false;
      }
22
      setAnswer(uploadFiles[0].name);
Jiwon Yoon's avatar
Jiwon Yoon committed
23
      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>
  );
};