import React, { useEffect, useState } from 'react' import Icon from 'semantic-ui-react/dist/commonjs/elements/Icon/Icon' import { CommonNotificationProps, EventsStartsSoonNotification as EventsStartsSoonNotificationType } from '../../types' import NotificationItem from '../../NotificationItem' import EventStartsSoon from '../../../Icons/Notifications/EventStartsSoon' let interval: NodeJS.Timeout function Countdown({ startDate }: { startDate: string }) { const [minutes, setMinutes] = useState(undefined) const [seconds, setSeconds] = useState(undefined) useEffect(() => { interval = setInterval(() => { const eventStartDate = new Date(startDate).getTime() const distance = eventStartDate - Date.now() const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)) const seconds = Math.floor((distance % (1000 * 60)) / 1000) setMinutes(minutes) setSeconds(seconds) if (distance < 0) { setMinutes(0) setSeconds(0) clearInterval(interval) } }, 1000) return () => clearInterval(interval) }, [setMinutes, setSeconds]) const minutesString = minutes !== undefined ? minutes.toLocaleString('en-US', { minimumIntegerDigits: 2, useGrouping: false }) : '--' const secondsString = seconds !== undefined ? seconds.toLocaleString('en-US', { minimumIntegerDigits: 2, useGrouping: false }) : '--' return (
{`${minutesString}:${secondsString}`}
) } const i18N = { en: { description: ( metadata: EventsStartsSoonNotificationType['metadata'] ): React.ReactNode => new Date(metadata.startsAt).getTime() > Date.now() ? ( <> The event {metadata.name} is about to start in ) : ( <> The event {metadata.name} starts in an hour ), title: 'Event starts soon' }, es: { description: ( metadata: EventsStartsSoonNotificationType['metadata'] ): React.ReactNode => new Date(metadata.startsAt).getTime() > Date.now() ? ( <> El evento {metadata.name} esta por empezar en ) : ( <> El evento {metadata.name} empieza en una hora ), title: 'Evento empieza pronto' }, zh: { description: ( metadata: EventsStartsSoonNotificationType['metadata'] ): React.ReactNode => new Date(metadata.startsAt).getTime() > Date.now() ? ( <> 事件 {metadata.name} 即将开始 在{' '} ) : ( <> 事件 {metadata.name} 从一个开始 小时 ), title: '事件即将开始' } } /** * @deprecated Should start using the same component migrated to UI2. */ const EventsStartsSoonNotification = ({ notification, locale }: CommonNotificationProps) => ( }} timestamp={notification.timestamp} isNew={!notification.read} locale={locale} >

{i18N[locale].title}

{i18N[locale].description(notification.metadata)}

) export default EventsStartsSoonNotification