import React from 'react'; import dayjs from 'dayjs'; import { useTranslation } from 'react-i18next'; import { monthDays } from '../../helpers'; import { useSelectedDateContext } from '../../hooks/selected-date-context'; import DaysOfWeekCard from '../../calendar/monthly/days-of-week.component'; import MonthlyWorkloadCard from './monthlyWorkCard'; import styles from './monthly-workload.scss'; interface MonthlyCalendarViewProps { calendarWorkload: Array<{ count: number; date: string }>; dateToDisplay?: string; onDateClick?: (pickedDate: Date) => void; } const MonthlyCalendarView: React.FC = ({ calendarWorkload, dateToDisplay = '', onDateClick, }) => { const monthFormat = 'MMMM, YYYY'; const { t } = useTranslation(); const { selectedDate } = useSelectedDateContext(); const daysInWeek = ['SUN', 'MON', 'TUE', 'WED', 'THUR', 'FRI', 'SAT']; const monthViewDate = dateToDisplay === '' ? selectedDate : dateToDisplay; const daysInWeeks = daysInWeek.map((day) => t(day)); const handleClick = (date: Date) => { if (onDateClick) { onDateClick(date); } }; return (
<>
{dayjs(monthViewDate).format(monthFormat)}
{daysInWeeks?.map((day, i) => ( ))}
{monthDays(dayjs(monthViewDate)).map((dateTime, i) => (
handleClick(dayjs(dateTime).toDate())} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { handleClick(dayjs(dateTime).toDate()); } }} key={i} className={`${styles.monthlyWorkloadCard} ${ dayjs(dateTime).format('YYYY-MM-DD') === dayjs(monthViewDate).format('YYYY-MM-DD') ? styles.selectedDate : '' }`} > calendar.date === dayjs(dateTime).format('YYYY-MM-DD')) ?.count ?? 0 } />
))}
); }; export default MonthlyCalendarView;