Skip to content

Commit

Permalink
Merge pull request #3266 from ever-co/feat/grouped-timesheet-display
Browse files Browse the repository at this point in the history
Feat: Add grouped display for timesheet data by date
  • Loading branch information
evereq authored Nov 9, 2024
2 parents d5a4eeb + 7876fcc commit 06d67fd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ interface ITimesheetFilter {
openModal: () => void,
closeModal: () => void,
t: TranslationHooks,
initDate?: TimesheetFilterDateProps
initDate?: Pick<TimesheetFilterDateProps, 'initialRange' | 'onChange' | 'maxDate' | 'minDate'>
}

export function TimesheetFilter({ closeModal, isOpen, openModal, t, initDate }: ITimesheetFilter,) {
return (
<>
Expand Down
7 changes: 4 additions & 3 deletions apps/web/app/[locale]/timesheet/[memberId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -162,7 +163,7 @@ const TimeSheet = React.memo(function TimeSheetPage({ params }: { params: { memb
/>
<div className='h-[calc(100vh-_291px)] mt-3 overflow-y-auto border border-gray-200 rounded-lg dark:border-gray-800'>
{timesheetNavigator === 'ListView' ?
<TimesheetView data={sortedPlans} />
<TimesheetView data={timesheet} />
: <CalendarView />
}
</div>
Expand Down
22 changes: 21 additions & 1 deletion apps/web/app/hooks/features/useTimesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -42,9 +45,26 @@ export function useTimesheet({
useEffect(() => {
getTaskTimesheet({ startDate, endDate });
}, [getTaskTimesheet, startDate, endDate]);


const groupByDate = (items: ITimeSheet[]) => {
const groupedByDate = items.reduce((acc: Record<string, ITimeSheet[]>, 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,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ export function DataTableTimeSheet({ data }: { data?: IDailyPlan[] }) {
console.error(`Unsupported action: ${action}`);
}
};
console.log("================>", data)

return (
<div className="w-full dark:bg-dark--theme">
Expand Down

0 comments on commit 06d67fd

Please sign in to comment.