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

type Props = {
  element: FileType;
6
  answers: AnswersType;
7
8
9
10
11
12
  handleAnswer: () => void;
  addFiles: (oneFile: { questionId: string; file: File }) => void;
};

export const AFileForm = ({
  element,
13
  answers,
14
15
16
17
18
19
20
  handleAnswer,
  addFiles,
}: Props) => {
  const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    if (event.currentTarget.files) {
      const uploadFile = event.currentTarget.files[0];
      addFiles({ questionId: element._id, file: uploadFile });
21
22
23
24
25
26
      // response.answers.map((a) => {
      //   if (a.questionId === element._id) {
      //     a.answer = uploadFile.name;
      //   }
      // });
      answers[element._id] = uploadFile.name;
27
28
29
30
31
32
33
34
35
36
      handleAnswer();
    }
  };
  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}
Jiwon Yoon's avatar
Jiwon Yoon committed
37
        required={element.isRequired}
38
39
40
41
      ></input>
    </div>
  );
};