2021-06-17 17:26:35 +02:00
|
|
|
import React from 'react';
|
2021-06-18 12:47:04 +02:00
|
|
|
import moment from 'moment';
|
2021-06-17 17:26:35 +02:00
|
|
|
import { FabModal } from '../base/fab-modal';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { HtmlTranslate } from '../base/html-translate';
|
2021-06-18 12:47:04 +02:00
|
|
|
import { IFablab } from '../../models/fablab';
|
|
|
|
|
|
|
|
declare var Fablab: IFablab;
|
2021-06-17 17:26:35 +02:00
|
|
|
|
|
|
|
interface PendingTrainingModalProps {
|
|
|
|
isOpen: boolean,
|
|
|
|
toggleModal: () => void,
|
|
|
|
nextReservation: Date,
|
|
|
|
}
|
|
|
|
|
2021-06-18 16:05:36 +02:00
|
|
|
/**
|
|
|
|
* Modal dialog shown if the current user has registered for a training but this training isn't validated
|
|
|
|
* when the user tries to book a machine.
|
|
|
|
*/
|
2021-06-17 17:26:35 +02:00
|
|
|
export const PendingTrainingModal: React.FC<PendingTrainingModalProps> = ({ isOpen, toggleModal, nextReservation }) => {
|
|
|
|
const { t } = useTranslation('logged');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the formatted localized date for the given date
|
|
|
|
*/
|
2021-06-18 12:47:04 +02:00
|
|
|
const formatDateTime = (date: Date): string => {
|
|
|
|
const day = Intl.DateTimeFormat().format(moment(date).toDate());
|
|
|
|
const time = Intl.DateTimeFormat(Fablab.intl_locale, { hour: 'numeric', minute: 'numeric' }).format(moment(date).toDate());
|
|
|
|
return t('app.logged.pending_training_modal.DATE_TIME', { DATE: day, TIME:time });
|
2021-06-17 17:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FabModal title={t('app.logged.pending_training_modal.machine_reservation')}
|
|
|
|
isOpen={isOpen}
|
|
|
|
toggleModal={toggleModal}
|
|
|
|
closeButton={true}>
|
|
|
|
<p>{t('app.logged.pending_training_modal.wait_for_validated')}</p>
|
2021-06-18 12:47:04 +02:00
|
|
|
<p><HtmlTranslate trKey="app.logged.pending_training_modal.training_will_occur_DATE_html" options={{ DATE: formatDateTime(nextReservation) }} /></p>
|
2021-06-17 17:26:35 +02:00
|
|
|
</FabModal>
|
|
|
|
)
|
|
|
|
}
|