Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add grouped display for timesheet data by date #3266

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ?? ""
});
Innocent-Akim marked this conversation as resolved.
Show resolved Hide resolved


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} />
Innocent-Akim marked this conversation as resolved.
Show resolved Hide resolved
: <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 [];
}
Innocent-Akim marked this conversation as resolved.
Show resolved Hide resolved

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
Loading