diff --git a/apps/web/app/hooks/features/useTimelogFilterOptions.ts b/apps/web/app/hooks/features/useTimelogFilterOptions.ts index ba00c9aae..d717d0ebb 100644 --- a/apps/web/app/hooks/features/useTimelogFilterOptions.ts +++ b/apps/web/app/hooks/features/useTimelogFilterOptions.ts @@ -1,4 +1,4 @@ -import { IUser, RoleNameEnum } from '@/app/interfaces'; +import { IUser, RoleNameEnum, TimesheetLog } from '@/app/interfaces'; import { timesheetDeleteState, timesheetGroupByDayState, timesheetFilterEmployeeState, timesheetFilterProjectState, timesheetFilterStatusState, timesheetFilterTaskState, timesheetUpdateStatus } from '@/app/stores'; import { useAtom } from 'jotai'; import React from 'react'; @@ -44,12 +44,16 @@ export function useTimelogFilterOptions() { setSelectTimesheetId((prev) => prev.includes(items) ? prev.filter((filter) => filter !== items) : [...prev, items]) } - const handleSelectRowByStatusAndDate = (status: string, date: string) => { - setSelectedItems((prev) => - prev.some((item) => item.status === status && item.date === date) - ? prev.filter((item) => !(item.status === status && item.date === date)) - : [...prev, { status, date }] - ); + const handleSelectRowByStatusAndDate = (logs: TimesheetLog[], isChecked: boolean) => { + setSelectTimesheetId((prev) => { + const logIds = logs.map((item) => item.id); + + if (isChecked) { + return [...new Set([...prev, ...logIds])]; + } else { + return prev.filter((id) => !logIds.includes(id)); + } + }); } @@ -61,6 +65,7 @@ export function useTimelogFilterOptions() { return { statusState, employee, + setSelectedItems, project, task, setEmployeeState, 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 8d0efecec..7e4332204 100644 --- a/apps/web/lib/features/integrations/calendar/table-time-sheet.tsx +++ b/apps/web/lib/features/integrations/calendar/table-time-sheet.tsx @@ -228,7 +228,7 @@ export function DataTableTimeSheet({ data, user }: { data?: GroupedTimesheet[], console.error(`Unsupported action: ${action}`); } }; - + console.log("============+++++++++========>", selectTimesheetId); return (
@@ -303,14 +303,14 @@ export function DataTableTimeSheet({ data, user }: { data?: GroupedTimesheet[],
- {isManage && getTimesheetButtons(status as StatusType, t, true, handleButtonClick)} + {isManage && getTimesheetButtons(status as StatusType, t, selectTimesheetId.length === 0, handleButtonClick)}
handleSelectRowByStatusAndDate(status, plan.date)} + () => handleSelectRowByStatusAndDate(rows, selectTimesheetId.length === 0)} data={rows} status={status} onSort={handleSort} @@ -328,7 +328,7 @@ export function DataTableTimeSheet({ data, user }: { data?: GroupedTimesheet[], )} > handleSelectRowTimesheet(task.id)} checked={selectTimesheetId.includes(task.id)} />