Skip to content

Commit

Permalink
Update contentu
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed May 23, 2024
1 parent d691fa7 commit 5e3ced0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/components/CompetitionPage/CompetitionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ type CompetitionPageProps = {
}

export const CompetitionPage: FC<CompetitionPageProps> = ({
competition: {id, name, who_can_participate, description, upcoming_or_current_event, history_events},
competition: {
id,
competition_type,
name,
who_can_participate,
description,
upcoming_or_current_event,
history_events,
},
}) => {
const {setBannerMessages} = BannerContainer.useContainer()

Expand All @@ -43,14 +51,29 @@ export const CompetitionPage: FC<CompetitionPageProps> = ({
? formatDateTimeInterval(upcoming_or_current_event.start, upcoming_or_current_event.end)
: null

function getRegistartionInfo(registrationLink: RegistrationLink) {
function getRegistrationInfo(registrationLink: RegistrationLink | null) {
if (!registrationLink) return ``
if (DateTime.fromISO(registrationLink.start) > DateTime.now())
return `Registrácia bude otvorená od ${formatDateTime(registrationLink.start)}`
else if (DateTime.fromISO(registrationLink.end) > DateTime.now())
return `Registrácia je otvorená do ${formatDateTime(registrationLink.end)}`
return `Registrácia bola ukončená`
}

function getEventInfo(upcomingEvent: Event | null) {
if (competition_type?.short_name === 'súťaž')
return `${upcomingEvent?.year}. ročník súťaže ${name} sa bude konať ${upcomingEventDate} ${
upcomingEvent?.location || ''
}. `
else if (competition_type?.short_name === 'tábor')
return `${name} v roku ${upcomingEvent?.school_year?.split('/')[1]} sa bude konať ${upcomingEventDate} ${
upcomingEvent?.location || ''
}.`
else if (competition_type?.short_name === 'seminár')
return `Aktuálne prebieha ${upcomingEvent?.year}. ročník seminára ${name}`
return ''
}

const isRegistrationActive = upcoming_or_current_event?.registration_link
? DateTime.fromISO(upcoming_or_current_event.registration_link.start) < DateTime.now() &&
DateTime.fromISO(upcoming_or_current_event.registration_link.end) > DateTime.now()
Expand All @@ -59,8 +82,8 @@ export const CompetitionPage: FC<CompetitionPageProps> = ({
return (
<Stack gap={5}>
<Typography variant="body1">
{who_can_participate && `Súťaž je určená pre ${who_can_participate}.`}
{description && ` ${description}`}
{description && `${description}`}
{who_can_participate && ` Súťaž je určená pre ${who_can_participate}.`}
</Typography>

<Stack
Expand All @@ -75,13 +98,12 @@ export const CompetitionPage: FC<CompetitionPageProps> = ({
</Stack>

<Stack gap={2}>
<Typography variant="h2">Nadchádzajúci ročník</Typography>
{upcoming_or_current_event ? (
<Stack gap={1}>
<Typography variant="body1">
<b>
{upcoming_or_current_event?.year}. ročník súťaže {name} sa bude konať {upcomingEventDate} v Košiciach.{' '}
{getRegistartionInfo(upcoming_or_current_event.registration_link)}
{getEventInfo(upcoming_or_current_event)}
{getRegistrationInfo(upcoming_or_current_event.registration_link)}
</b>
</Typography>
<Stack sx={{alignItems: 'end'}}>
Expand All @@ -99,7 +121,7 @@ export const CompetitionPage: FC<CompetitionPageProps> = ({
</Stack>
) : (
<Typography variant="body1" sx={{marginTop: 1}}>
Pripravujeme
Ďalší ročník aktuálne pripravujeme
</Typography>
)}
</Stack>
Expand Down
2 changes: 2 additions & 0 deletions src/types/api/competition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Event {
is_registered: boolean
publication_set: Publication[]
registration_link: RegistrationLink
location: string | null
year: number | null
school_year: string | null
season_code: number
Expand All @@ -43,6 +44,7 @@ export interface Event {
export interface CompetitionType {
id: number
name: string
short_name: string
}

export interface Competition {
Expand Down

0 comments on commit 5e3ced0

Please sign in to comment.