🎨 style(inputFileComponent): refactor file upload to use a separate function

The file upload functionality has been refactored to use a separate function called uploadFile, which is imported from the API controller. This improves the separation of concerns and makes the code more modular.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-21 10:21:20 -03:00
commit a81a99f1c4

View file

@ -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