feat: add event rows to Show Page Calendar tab (#4319)

* feat: add event rows to Show Page Calendar tab

Closes #4287

* refactor: use time as events group key instead of ISO string for easier sorting

* feat: implement data model changes

* refactor: improve sorting
This commit is contained in:
Thaïs
2024-03-07 07:13:22 -03:00
committed by GitHub
parent 9190bd8d7f
commit dd961209de
11 changed files with 692 additions and 4 deletions

View File

@ -0,0 +1,41 @@
import { startOfDay } from 'date-fns';
import { CalendarDayCardContent } from '@/activities/calendar/components/CalendarDayCardContent';
import { CalendarEvent } from '@/activities/calendar/types/CalendarEvent';
import { Card } from '@/ui/layout/card/components/Card';
import { groupArrayItemsBy } from '~/utils/array/groupArrayItemsBy';
import { sortDesc } from '~/utils/sort';
type CalendarMonthCardProps = {
calendarEvents: CalendarEvent[];
};
export const CalendarMonthCard = ({
calendarEvents,
}: CalendarMonthCardProps) => {
const calendarEventsByDayTime = groupArrayItemsBy(
calendarEvents,
({ startsAt }) => startOfDay(startsAt).getTime(),
);
const sortedDayTimes = Object.keys(calendarEventsByDayTime)
.map(Number)
.sort(sortDesc);
return (
<Card fullWidth>
{sortedDayTimes.map((dayTime, index) => {
const dayCalendarEvents = calendarEventsByDayTime[dayTime];
return (
!!dayCalendarEvents?.length && (
<CalendarDayCardContent
key={dayTime}
calendarEvents={dayCalendarEvents}
divider={index < sortedDayTimes.length - 1}
/>
)
);
})}
</Card>
);
};