-
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.
Upload of publications in administration (#156)
* create PublicationUploader * add uploading publications for current semester * add Accept to Uploader * refactor uploading publications * add order to Publication * refactor/cleanup + style the section --------- Co-authored-by: rtrembecky <[email protected]>
- Loading branch information
1 parent
0a089ca
commit 51a4b34
Showing
5 changed files
with
57 additions
and
2 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
43 changes: 43 additions & 0 deletions
43
src/components/PublicationUploader/PublicationUploader.tsx
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,43 @@ | ||
import {Stack} from '@mui/material' | ||
import {useQueryClient} from '@tanstack/react-query' | ||
import {FC} from 'react' | ||
|
||
import {SemesterWithProblems} from '@/types/api/generated/competition' | ||
|
||
import {Link} from '../Clickable/Clickable' | ||
import {FileUploader} from '../FileUploader/FileUploader' | ||
|
||
interface PublicationUploaderProps { | ||
semesterId: string | ||
order: number | ||
semesterData: SemesterWithProblems | undefined | ||
} | ||
|
||
export const PublicationUploader: FC<PublicationUploaderProps> = ({semesterId, order, semesterData}) => { | ||
const queryClient = useQueryClient() | ||
|
||
const refetch = () => queryClient.invalidateQueries({queryKey: ['competition', 'semester', semesterId]}) | ||
|
||
const appendFormData = (formData: FormData) => { | ||
formData.append('publication_type', 'Časopisy') | ||
formData.append('event', semesterId) | ||
formData.append('order', order.toString()) | ||
} | ||
|
||
const publication = semesterData?.publication_set.find((publication) => publication.order === order) | ||
|
||
return ( | ||
<Stack direction="row" gap={2} alignItems="center"> | ||
<h4>{order}. Časopis:</h4> | ||
{publication && ( | ||
<Link href={`/api/competition/publication/${publication.id}/download`}>{publication.name}.pdf</Link> | ||
)} | ||
<FileUploader | ||
uploadLink={'/api/competition/publication/upload/'} | ||
acceptedFormats={{'application/pdf': ['.pdf']}} | ||
adjustFormData={appendFormData} | ||
refetch={refetch} | ||
/> | ||
</Stack> | ||
) | ||
} |
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
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