import { computed, observable } from 'mobx'; import { observer } from 'mobx-react'; import { ChangeEvent, PureComponent } from 'react'; import { Col, Form, InputGroup, Row } from 'react-bootstrap'; import { formatDate } from 'web-utility'; import { i18n } from '../models/Translation'; const { t } = i18n; export interface DateTimeInputProps { id?: string; label: string; name: string; required?: boolean; startAt?: string; endAt?: string; } @observer export class DateTimeInput extends PureComponent { @observable start = ''; @observable end = ''; @computed get isInvalid() { return +new Date(this.start) > +new Date(this.end); } handleInputChange = ({ currentTarget: { name, value }, }: ChangeEvent) => { if (/StartedAt/.test(name)) { this.start = value; } else { this.end = value; } }; render() { const { id, label, name, required, startAt, endAt } = this.props, { isInvalid } = this; return ( {label} * {t('time_range')} {t('start_time_earlier_end_time')} ); } }