From 4370bf18c7a9c6a4a202c0ccd8354751826f38c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vikt=C3=B3ria=20Brezinov=C3=A1?= Date: Sat, 27 May 2023 14:50:01 +0200 Subject: [PATCH] add Accept to Uploader --- .../PublicationUploader/PublicationUploader.tsx | 16 ++++++++++++---- .../SemesterAdministration.tsx | 9 +++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/PublicationUploader/PublicationUploader.tsx b/src/components/PublicationUploader/PublicationUploader.tsx index e231cacf..d4fbab92 100644 --- a/src/components/PublicationUploader/PublicationUploader.tsx +++ b/src/components/PublicationUploader/PublicationUploader.tsx @@ -1,19 +1,23 @@ import {Upload} from '@mui/icons-material' import axios from 'axios' import {FC, useCallback} from 'react' -import {DropzoneOptions, useDropzone} from 'react-dropzone' +import {Accept, DropzoneOptions, useDropzone} from 'react-dropzone' interface PublicationUploaderProps { uploadLink: string + acceptedFormats?: Accept publication_type: string event: string order: string refetch: () => void } -export const PublicationUploader: FC = ({uploadLink, publication_type, event, order, refetch}) => { +export const PublicationUploader: FC = ({uploadLink, acceptedFormats, publication_type, event, order, refetch}) => { const onDrop = useCallback>( - async (acceptedFiles) => { + async (acceptedFiles, fileRejections) => { + if (fileRejections.length > 0) { + return + } const formData = new FormData() formData.append('file', acceptedFiles[0]) formData.append('publication_type', publication_type) @@ -26,7 +30,11 @@ export const PublicationUploader: FC = ({uploadLink, p [refetch, uploadLink], ) - const {getRootProps, getInputProps} = useDropzone({onDrop}) + const {getRootProps, getInputProps} = useDropzone({ + onDrop, + multiple: false, + accept: acceptedFormats ?? {}, + }) return ( <> diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 8c630eb5..da89b343 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -130,6 +130,9 @@ export const SemesterAdministration: FC = () => { 1. časopis: { 2. časopis: { 3. časopis: