Skip to content

Commit

Permalink
455 using publication types (#468)
Browse files Browse the repository at this point in the history
* Introduced PublicationTypes

* UpcomingOrCurrentEvent identifying invitation based on publication_type not index of the publication

* reduce lines a little bit

---------

Co-authored-by: matushl <[email protected]>
  • Loading branch information
michalmasrna1 and Matushl authored Nov 23, 2024
1 parent 2a41527 commit 2d8f928
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/components/CompetitionPage/UpcomingOrCurrentEventInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Stack, Typography} from '@mui/material'
import {DateTime} from 'luxon'
import {FC} from 'react'

import {Event} from '@/types/api/competition'
import {Event, PublicationTypes} from '@/types/api/competition'
import {DateFormat, formatDateTimeInterval} from '@/utils/formatDate'

import {Link} from '../Clickable/Link'
Expand All @@ -14,6 +14,10 @@ export const UpcomingOrCurrentEventInfo: FC<{event: Event; name: string; shortNa
}) => {
const {year, school_year, location, registration_link, publication_set, start, end} = event

const invitationFile = publication_set.find(
(publication) => publication.publication_type === PublicationTypes.INVITATION.id,
)

const upcomingEventDate = event ? formatDateTimeInterval(start, end) : null

const regStart = registration_link && DateTime.fromISO(registration_link.start)
Expand Down Expand Up @@ -42,8 +46,8 @@ export const UpcomingOrCurrentEventInfo: FC<{event: Event; name: string; shortNa
{registrationInfo}
</Typography>
<Stack direction="row" sx={{justifyContent: 'end', gap: {xs: 1, sm: 2}}}>
{publication_set.length > 0 && (
<Link variant="button2" href={`/api/${publication_set[0].file}`}>
{invitationFile && (
<Link variant="button2" href={`/api/${invitationFile.name}`}>
Pozvánka
</Link>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/PublicationUploader/PublicationUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Stack, Typography} from '@mui/material'
import {useQueryClient} from '@tanstack/react-query'
import {FC} from 'react'

import {PublicationTypes} from '@/types/api/competition'
import {SemesterWithProblems} from '@/types/api/generated/competition'

import {Link} from '../Clickable/Link'
Expand All @@ -19,7 +20,7 @@ export const PublicationUploader: FC<PublicationUploaderProps> = ({semesterId, o
const refetch = () => queryClient.invalidateQueries({queryKey: ['competition', 'semester', semesterId]})

const appendFormData = (formData: FormData) => {
formData.append('publication_type', 'Časopisy')
formData.append('publication_type', PublicationTypes.LEAFLET.name)
formData.append('event', semesterId.toString())
formData.append('order', order.toString())
}
Expand Down
24 changes: 24 additions & 0 deletions src/types/api/competition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ export interface Publication {
order: number | null
}

// webstrom-backend/competition/fixtures/publication_type.json
export const PublicationTypes = {
PROBLEMS: {
id: 0,
name: 'Zadania',
},
RESULTS: {
id: 1,
name: 'Výsledky',
},
SOLUTIONS: {
id: 2,
name: 'Brožúra',
},
INVITATION: {
id: 3,
name: 'Pozvánka',
},
LEAFLET: {
id: 4,
name: 'Časopisy',
},
}

export interface RegistrationLink {
id: number
url: string
Expand Down

0 comments on commit 2d8f928

Please sign in to comment.