Skip to content

Commit

Permalink
create PublicationUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
vikibrezinova committed Nov 10, 2023
1 parent d4b53be commit ba073ad
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/components/PublicationUploader/PublicationUploader.tsx
Original file line number Diff line number Diff line change
@@ -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<PublicationUploaderProps> = ({uploadLink, publication_type, event, order, refetch}) => {
const onDrop = useCallback<NonNullable<DropzoneOptions['onDrop']>>(
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 (
<>
<div {...getRootProps()}>
<input {...getInputProps()} />
<Upload />
</div>
</>
)
}

0 comments on commit ba073ad

Please sign in to comment.