Skip to content

Commit

Permalink
feat: toggle timesheet IDs based on checkbox state
Browse files Browse the repository at this point in the history
  • Loading branch information
Innocent-Akim committed Dec 13, 2024
1 parent 1bbb370 commit 380288e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 12 additions & 7 deletions apps/web/app/hooks/features/useTimelogFilterOptions.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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));
}
});
}


Expand All @@ -61,6 +65,7 @@ export function useTimelogFilterOptions() {
return {
statusState,
employee,
setSelectedItems,
project,
task,
setEmployeeState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function DataTableTimeSheet({ data, user }: { data?: GroupedTimesheet[],
console.error(`Unsupported action: ${action}`);
}
};

console.log("============+++++++++========>", selectTimesheetId);

return (
<div className="w-full dark:bg-dark--theme">
Expand Down Expand Up @@ -303,14 +303,14 @@ export function DataTableTimeSheet({ data, user }: { data?: GroupedTimesheet[],
</Badge>
</div>
<div className={clsxm('flex items-center gap-2 p-x-1 capitalize')}>
{isManage && getTimesheetButtons(status as StatusType, t, true, handleButtonClick)}
{isManage && getTimesheetButtons(status as StatusType, t, selectTimesheetId.length === 0, handleButtonClick)}
</div>
</div>
</AccordionTrigger>
<AccordionContent className="flex flex-col w-full">
<HeaderRow
handleSelectRowByStatusAndDate={
() => handleSelectRowByStatusAndDate(status, plan.date)}
() => handleSelectRowByStatusAndDate(rows, selectTimesheetId.length === 0)}
data={rows}
status={status}
onSort={handleSort}
Expand All @@ -328,7 +328,7 @@ export function DataTableTimeSheet({ data, user }: { data?: GroupedTimesheet[],
)}
>
<Checkbox
className="w-5 h-5"
className="w-5 h-5 select-auto"
onCheckedChange={() => handleSelectRowTimesheet(task.id)}
checked={selectTimesheetId.includes(task.id)}
/>
Expand Down

0 comments on commit 380288e

Please sign in to comment.