import { formatDate } from '@transferwise/formatting'; import { PureComponent } from 'react'; import { MonthFormat } from '../../common'; import type { DisabledRules } from '../Calendar.types'; import messages from '../Calendar.messages'; import DateHeader from '../DateHeader'; import DayCalendarTable from './Table'; import { injectIntl, type WrappedComponentProps } from '../../common/injectIntl'; interface DayCalendarProps extends WrappedComponentProps { selectedDate: Date | null; focusedDate?: Date | null; min: Date | null; max: Date | null; viewMonth: number; viewYear: number; monthFormat: `${MonthFormat}`; disabledRules?: DisabledRules; disabledReasonId?: string; announceReasonOnFocus?: boolean; onSelect: (date: Date) => void; onDayFocus?: (date: Date) => void; onLabelClick: () => void; onViewDateUpdate: (date: { month: number; year: number }) => void; } class DayCalendar extends PureComponent { selectPreviousMonth = () => { const { viewMonth, viewYear } = this.props; this.props.onViewDateUpdate({ month: viewMonth <= 0 ? 11 : viewMonth - 1, year: viewMonth <= 0 ? viewYear - 1 : viewYear, }); }; selectNextMonth = () => { const { viewMonth, viewYear } = this.props; this.props.onViewDateUpdate({ month: viewMonth >= 11 ? 0 : viewMonth + 1, year: viewMonth >= 11 ? viewYear + 1 : viewYear, }); }; render() { const { selectedDate, focusedDate, min, max, viewMonth, viewYear, intl: { locale, formatMessage }, monthFormat, disabledRules, disabledReasonId, announceReasonOnFocus, onLabelClick, onSelect, onDayFocus, } = this.props; const prevMonth = viewMonth <= 0 ? 11 : viewMonth - 1; const prevYear = viewMonth <= 0 ? viewYear - 1 : viewYear; const nextMonth = viewMonth >= 11 ? 0 : viewMonth + 1; const nextYear = viewMonth >= 11 ? viewYear + 1 : viewYear; const isPreviousDisabled = !!( min && new Date(prevYear, prevMonth) < new Date(min.getFullYear(), min.getMonth()) ); const isNextDisabled = !!( max && new Date(nextYear, nextMonth) > new Date(max.getFullYear(), max.getMonth()) ); return ( <> ); } } export default injectIntl(DayCalendar);