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]: Toggle Timesheet IDs based on checkbox state #3424

Merged
merged 2 commits into from
Dec 13, 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
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 @@ -229,7 +229,6 @@ export function DataTableTimeSheet({ data, user }: { data?: GroupedTimesheet[],
}
};


return (
<div className="w-full dark:bg-dark--theme">
<AlertConfirmationModal
Expand Down Expand Up @@ -303,14 +302,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 +327,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
Loading