From 7876fcc90bf2400d23df2a2422196a3f4c5a9575 Mon Sep 17 00:00:00 2001 From: Innocent-akim Date: Fri, 8 Nov 2024 23:19:32 +0200 Subject: [PATCH] feat: add grouped display for timesheet data by date --- .../[memberId]/components/TimesheetFilter.tsx | 4 ++-- .../[locale]/timesheet/[memberId]/page.tsx | 7 +++--- apps/web/app/hooks/features/useTimesheet.ts | 22 ++++++++++++++++++- .../calendar/table-time-sheet.tsx | 1 - 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilter.tsx b/apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilter.tsx index 0a1f8ed0d..b669fa3b7 100644 --- a/apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilter.tsx +++ b/apps/web/app/[locale]/timesheet/[memberId]/components/TimesheetFilter.tsx @@ -9,9 +9,9 @@ interface ITimesheetFilter { openModal: () => void, closeModal: () => void, t: TranslationHooks, - initDate?: TimesheetFilterDateProps + initDate?: Pick } - + export function TimesheetFilter({ closeModal, isOpen, openModal, t, initDate }: ITimesheetFilter,) { return ( <> diff --git a/apps/web/app/[locale]/timesheet/[memberId]/page.tsx b/apps/web/app/[locale]/timesheet/[memberId]/page.tsx index 06a6441ff..f002a4942 100644 --- a/apps/web/app/[locale]/timesheet/[memberId]/page.tsx +++ b/apps/web/app/[locale]/timesheet/[memberId]/page.tsx @@ -8,7 +8,7 @@ import { withAuthentication } from 'lib/app/authenticator'; import { Breadcrumb, Container } from 'lib/components'; import { MainLayout } from 'lib/layout'; -import { useAuthenticateUser, useDailyPlan, useLocalStorageState, useModal, useOrganizationTeams } from '@app/hooks'; +import { useAuthenticateUser, useLocalStorageState, useModal, useOrganizationTeams } from '@app/hooks'; import { clsxm } from '@app/utils'; import { fullWidthState } from '@app/stores/fullWidth'; import { useAtomValue } from 'jotai'; @@ -42,11 +42,12 @@ const TimeSheet = React.memo(function TimeSheetPage({ params }: { params: { memb to: endOfDay(new Date()), }); - const { sortedPlans } = useDailyPlan(); const { timesheet } = useTimesheet({ startDate: dateRange.from ?? "", endDate: dateRange.to ?? "" }); + + const { isOpen: isManualTimeModalOpen, openModal: openManualTimeModal, @@ -162,7 +163,7 @@ const TimeSheet = React.memo(function TimeSheetPage({ params }: { params: { memb />
{timesheetNavigator === 'ListView' ? - + : }
diff --git a/apps/web/app/hooks/features/useTimesheet.ts b/apps/web/app/hooks/features/useTimesheet.ts index 91a8b473a..c67616373 100644 --- a/apps/web/app/hooks/features/useTimesheet.ts +++ b/apps/web/app/hooks/features/useTimesheet.ts @@ -5,12 +5,15 @@ import { useQuery } from '../useQuery'; import { useCallback, useEffect } from 'react'; import { getTaskTimesheetLogsApi } from '@/app/services/client/api/timer/timer-log'; import moment from 'moment'; +import { ITimeSheet } from '@/app/interfaces'; interface TimesheetParams { startDate: Date | string; endDate: Date | string; } + + export function useTimesheet({ startDate, endDate, @@ -42,9 +45,26 @@ export function useTimesheet({ useEffect(() => { getTaskTimesheet({ startDate, endDate }); }, [getTaskTimesheet, startDate, endDate]); + + + const groupByDate = (items: ITimeSheet[]) => { + const groupedByDate = items.reduce((acc: Record, item) => { + const date = new Date(item.createdAt).toISOString().split('T')[0]; + if (!acc[date]) { + acc[date] = []; + } + acc[date].push(item); + return acc; + }, {}); + return Object.keys(groupedByDate).map((date) => ({ + date, + tasks: groupedByDate[date] + })) as []; + } + return { loadingTimesheet, - timesheet, + timesheet: groupByDate(timesheet), getTaskTimesheet, }; } diff --git a/apps/web/lib/features/integrations/calendar/table-time-sheet.tsx b/apps/web/lib/features/integrations/calendar/table-time-sheet.tsx index a6cb33f44..25ed36ef3 100644 --- a/apps/web/lib/features/integrations/calendar/table-time-sheet.tsx +++ b/apps/web/lib/features/integrations/calendar/table-time-sheet.tsx @@ -225,7 +225,6 @@ export function DataTableTimeSheet({ data }: { data?: IDailyPlan[] }) { console.error(`Unsupported action: ${action}`); } }; - console.log("================>", data) return (