-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOKY-146 Upload a new file to document (#109)
* DOKY-146 Upload a new file to document Improve API request header generation Enhancements in the process of generating headers in API requests occurred, with functionalities now split into two separate functions: one that manages authorization headers, and another which handles content-type headers. Increased code clarity and maintainability are expected benefits. Update local development base URL and refine API request methods The base URL for local development has been changed from port 8119 to 8080. Improvements have been made to the API request methods to handle different content-type more efficiently. The `prepareBody` function was removed, and data is now directly stringified, streamlining the code and offering increased flexibility in managing various content-types. Incorporate `documentId` within `SingleFileUploader` Updates were made to the `SingleFileUploader` component, namely with the addition of a `documentId` parameter. This change enhances the file uploading feature in the application, as tracking of the uploaded document is now possible. The form using this component has also been adjusted to provide the `documentId`. * Fix formatting issues and clean up unused console logs Corrected inconsistent quotation marks and improved indentation in various files. Removed unused console logs and added TODO comments to enhance future development. * Add file upload support in `EditDocumentForm` Refactor `SingleFileUploader` to `FileUploader` with upload functionality. Integrated new upload handler in `EditDocumentForm` to handle document uploads, including toast notifications upon success or failure. Simplified async call in `postFormData` to return fetch promise. * Remove `documentId` prop from `FileUploader` The `documentId` prop in the `FileUploader` component was redundant and has been removed.
- Loading branch information
1 parent
69cb8c1
commit c9d8ffe
Showing
7 changed files
with
81 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ server/out | |
/server/src/main/resources/static/ | ||
/server/property 'buildDir'/ | ||
/filestorage/ | ||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const BASE_URL = 'http://localhost:8119'; | ||
export const BASE_URL = 'http://localhost:8080'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
server/doky-front/src/components/formComponents/FileUploader.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, {useId, useState} from 'react'; | ||
|
||
const FileUploader = ({onUpload}) => { | ||
|
||
const [file, setFile] = useState(null); | ||
const id = useId(); | ||
const inputId = `file-input-${id}`; | ||
|
||
const handleFileChange = (e) => { | ||
if (e.target.files && e.target.files[0]) { | ||
setFile(e.target.files[0]); | ||
} | ||
}; | ||
|
||
const handleUpload = () => { | ||
const formData = new FormData(); | ||
formData.append('file', file); | ||
onUpload(formData); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="mt-4"> | ||
<label htmlFor={inputId} className="form-label">Select file to upload:</label> | ||
<input className="form-control" type="file" id={inputId} onChange={handleFileChange}/> | ||
</div> | ||
{file && | ||
<button type="button" className="btn btn-outline-primary me-2 mt-2" onClick={handleUpload}> | ||
<i className="bi bi-cloud-upload me-1"></i><span>Upload</span> | ||
</button> | ||
} | ||
</> | ||
); | ||
}; | ||
|
||
export default FileUploader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters