import React from 'react'; import { useTranslation } from 'react-i18next'; import { react2angular } from 'react2angular'; import { IApplication } from '../../models/application'; import { Loader } from '../base/loader'; import { Event } from '../../models/event'; import FormatLib from '../../lib/format'; declare const Application: IApplication; interface EventCardProps { event: Event, cardType: 'sm' | 'md' | 'lg' } export const EventCard: React.FC = ({ event, cardType = 'md' }) => { const { t } = useTranslation('public'); /** * Format description to remove HTML tags and set a maximum character count */ const formatText = (text: string, count: number) => { text = text.replace(/(<\/p>|<\/h4>|<\/h5>|<\/h6>|<\/pre>|<\/blockquote>)/g, '\n'); text = text.replace(//g, '\n'); text = text.replace(/<\/?\w+[^>]*>/g, ''); if (text.length > count) { text = text.slice(0, count) + '…'; } text = text.replace(/\n+/g, '
'); return text; }; /** * Return the formatted localized date of the event */ const formatDate = (): string => { // FIXME: typeof event.all_day = sting ? return event.all_day === 'true' ? t('app.public.home.from_date_to_date', { START: FormatLib.date(event.start_date), END: FormatLib.date(event.end_date) }) : t('app.public.home.on_the_date', { DATE: FormatLib.date(event.start_date) }); }; /** * Return the formatted localized hours of the event */ const formatTime = (): string => { // FIXME: typeof event.all_day = sting ? return event.all_day === 'true' ? t('app.public.home.all_day') : t('app.public.home.from_time_to_time', { START: FormatLib.time(event.start_date), END: FormatLib.time(event.end_date) }); }; /** * TODO: Link to event by id ? */ const showEvent = (id: number) => { console.log(window.location.href + '/' + id); }; return (
showEvent(event.id)}> {event.event_image ?
: cardType !== 'sm' &&
}

{event?.title}

{event.category.name}
{cardType !== 'sm' &&

}
{cardType !== 'md' &&

{formatDate()}

}
{cardType === 'sm' && event.event_themes.map(theme => { return (
{theme.name}
); }) } {(cardType === 'sm' && event.age_range) &&
{event.age_range?.name}
} {cardType === 'md' &&
{formatDate()}
}
{cardType !== 'sm' && }
{formatTime()}
{cardType !== 'sm' && } {event.nb_free_places > 0 &&
{t('app.public.home.still_available') + event.nb_free_places}
} {event.nb_total_places > 0 && event.nb_free_places <= 0 &&
{t('app.public.home.event_full')}
} {!event.nb_total_places &&
{t('app.public.home.without_reservation')}
}
{cardType !== 'sm' && } {event.amount === 0 &&
{t('app.public.home.free_admission')}
} {/* TODO: Display currency ? */} {event.amount > 0 &&
{t('app.public.home.full_price') + event.amount}
}
); }; const EventCardWrapper: React.FC = ({ event, cardType }) => { return ( ); }; Application.Components.component('eventCard', react2angular(EventCardWrapper, ['event', 'cardType']));