🎨 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:
parent
5216b519e0
commit
a81a99f1c4
1 changed files with 3 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue