From a81a99f1c451d57350cac0ff797eb35352c6a476 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 21 Jun 2023 10:21:20 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20style(inputFileComponent):=20ref?= =?UTF-8?q?actor=20file=20upload=20to=20use=20a=20separate=20function=20Th?= =?UTF-8?q?e=20file=20upload=20functionality=20has=20been=20refactored=20t?= =?UTF-8?q?o=20use=20a=20separate=20function=20called=20uploadFile,=20whic?= =?UTF-8?q?h=20is=20imported=20from=20the=20API=20controller.=20This=20imp?= =?UTF-8?q?roves=20the=20separation=20of=20concerns=20and=20makes=20the=20?= =?UTF-8?q?code=20more=20modular.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/inputFileComponent/index.tsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/components/inputFileComponent/index.tsx b/src/frontend/src/components/inputFileComponent/index.tsx index 72ed5b80f..efbc53b61 100644 --- a/src/frontend/src/components/inputFileComponent/index.tsx +++ b/src/frontend/src/components/inputFileComponent/index.tsx @@ -4,6 +4,7 @@ import { alertContext } from "../../contexts/alertContext"; import { FileComponentType } from "../../types/components"; import { TabsContext } from "../../contexts/tabsContext"; import { INPUT_STYLE } from "../../constants"; +import { uploadFile } from "../../controllers/API"; export default function InputFileComponent({ value, @@ -53,16 +54,9 @@ export default function InputFileComponent({ // Check if the file type is correct if (file && checkFileType(file.name)) { - // Prepare the file for upload - const formData = new FormData(); - formData.append("file", file); - // Upload the file - fetch(`/upload/${id}`, { - method: "POST", - body: formData, - }) - .then((response) => response.json()) + uploadFile(file, id) + .then((res) => res.data) .then((data) => { console.log("File uploaded successfully"); // Get the file name from the response