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' } /** * This component is a box showing the picture of the given event, and a short description of it. */ export const EventCard: React.FC = ({ event, cardType }) => { 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 => { const startDate = new Date(event.start_date); const endDate = new Date(event.end_date); const singleDayEvent = startDate.getFullYear() === endDate.getFullYear() && startDate.getMonth() === endDate.getMonth() && startDate.getDate() === endDate.getDate(); return singleDayEvent ? t('app.public.event_card.on_the_date', { DATE: FormatLib.date(event.start_date) }) : t('app.public.event_card.from_date_to_date', { START: FormatLib.date(event.start_date), END: FormatLib.date(event.end_date) }); }; /** * Return the formatted localized hours of the event */ const formatTime = (): string => { return event.all_day ? t('app.public.event_card.all_day') : t('app.public.event_card.from_time_to_time', { START: FormatLib.time(event.start_date), END: FormatLib.time(event.end_date) }); }; return (
{event.event_image ?
: cardType !== 'sm' &&
}
{event.category.name}

{event?.title}

{cardType !== 'sm' &&

}
{cardType !== 'md' &&

{formatDate()} {formatTime()}

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