From ba073ad8faab4adb0dafa486212d2f9cfe83120c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vikt=C3=B3ria=20Brezinov=C3=A1?= Date: Sat, 27 May 2023 14:04:03 +0200 Subject: [PATCH] create PublicationUploader --- .../PublicationUploader.tsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/components/PublicationUploader/PublicationUploader.tsx diff --git a/src/components/PublicationUploader/PublicationUploader.tsx b/src/components/PublicationUploader/PublicationUploader.tsx new file mode 100644 index 00000000..e231cacf --- /dev/null +++ b/src/components/PublicationUploader/PublicationUploader.tsx @@ -0,0 +1,39 @@ +import {Upload} from '@mui/icons-material' +import axios from 'axios' +import {FC, useCallback} from 'react' +import {DropzoneOptions, useDropzone} from 'react-dropzone' + +interface PublicationUploaderProps { + uploadLink: string + publication_type: string + event: string + order: string + refetch: () => void +} + +export const PublicationUploader: FC = ({uploadLink, publication_type, event, order, refetch}) => { + const onDrop = useCallback>( + async (acceptedFiles) => { + const formData = new FormData() + formData.append('file', acceptedFiles[0]) + formData.append('publication_type', publication_type) + formData.append('event', event) + formData.append('order', order) + await axios.post(uploadLink, formData) + await refetch() + + }, + [refetch, uploadLink], + ) + + const {getRootProps, getInputProps} = useDropzone({onDrop}) + + return ( + <> +
+ + +
+ + ) +}