diff --git a/apps/web/app/hooks/features/useTimelogFilterOptions.ts b/apps/web/app/hooks/features/useTimelogFilterOptions.ts index 6f0603867..04992ee89 100644 --- a/apps/web/app/hooks/features/useTimelogFilterOptions.ts +++ b/apps/web/app/hooks/features/useTimelogFilterOptions.ts @@ -1,4 +1,3 @@ -import { ITimeSheet } from '@/app/interfaces'; import { timesheetDeleteState, timesheetFilterEmployeeState, timesheetFilterProjectState, timesheetFilterStatusState, timesheetFilterTaskState } from '@/app/stores'; import { useAtom } from 'jotai'; @@ -13,7 +12,7 @@ export function useTimelogFilterOptions() { const project = projectState; const task = taskState - const handleSelectRowTimesheet = (items: ITimeSheet) => { + const handleSelectRowTimesheet = (items: string) => { setSelectTimesheet((prev) => prev.includes(items) ? prev.filter((filter) => filter !== items) : [...prev, items]) } @@ -27,6 +26,7 @@ export function useTimelogFilterOptions() { setTaskState, setStatusState, handleSelectRowTimesheet, - selectTimesheet + selectTimesheet, + setSelectTimesheet }; } diff --git a/apps/web/app/hooks/features/useTimesheet.ts b/apps/web/app/hooks/features/useTimesheet.ts index 73e079bb3..959f2ccdd 100644 --- a/apps/web/app/hooks/features/useTimesheet.ts +++ b/apps/web/app/hooks/features/useTimesheet.ts @@ -20,7 +20,7 @@ export interface GroupedTimesheet { interface DeleteTimesheetParams { organizationId: string; tenantId: string; - logIds: ITimeSheet[]; + logIds: string[]; } const groupByDate = (items: ITimeSheet[]): GroupedTimesheet[] => { @@ -85,16 +85,16 @@ export function useTimesheet({ - const handleDeleteTimesheet = (params: DeleteTimesheetParams) => { + const handleDeleteTimesheet = async (params: DeleteTimesheetParams) => { try { - return queryDeleteTimesheet(params); + return await queryDeleteTimesheet(params); } catch (error) { console.error('Error deleting timesheet:', error); throw error; } }; - const deleteTaskTimesheet = useCallback(() => { + const deleteTaskTimesheet = useCallback(async () => { if (!user) { throw new Error('User not authenticated'); } @@ -102,7 +102,7 @@ export function useTimesheet({ throw new Error('No timesheet IDs provided for deletion'); } try { - handleDeleteTimesheet({ + await handleDeleteTimesheet({ organizationId: user.employee.organizationId, tenantId: user.tenantId ?? "", logIds @@ -112,7 +112,7 @@ export function useTimesheet({ throw error; } }, - [user, queryDeleteTimesheet] + [user, queryDeleteTimesheet, logIds, handleDeleteTimesheet] // deepscan-disable-line ); useEffect(() => { diff --git a/apps/web/app/services/client/api/timer/timer-log.ts b/apps/web/app/services/client/api/timer/timer-log.ts index 8bab83002..3715f8cc3 100644 --- a/apps/web/app/services/client/api/timer/timer-log.ts +++ b/apps/web/app/services/client/api/timer/timer-log.ts @@ -75,7 +75,7 @@ export async function deleteTaskTimesheetLogsApi({ }: { organizationId: string, tenantId: string, - logIds: ITimeSheet[] + logIds: string[] }) { // Validate required parameters if (!organizationId || !tenantId || !logIds?.length) { @@ -91,11 +91,11 @@ export async function deleteTaskTimesheetLogsApi({ organizationId, tenantId }); - logIds.forEach((items, index) => { - if (!items) { + logIds.forEach((id, index) => { + if (!id) { throw new Error(`Invalid logId at index ${index}`); } - params.append(`logIds[${index}]`, items.id); + params.append(`logIds[${index}]`, id); }); const endPoint = `/timesheet/time-log?${params.toString()}`; diff --git a/apps/web/app/stores/time-logs.ts b/apps/web/app/stores/time-logs.ts index 7f49fd38b..e73d66c64 100644 --- a/apps/web/app/stores/time-logs.ts +++ b/apps/web/app/stores/time-logs.ts @@ -16,4 +16,4 @@ export const timesheetFilterProjectState = atom([]); export const timesheetFilterTaskState = atom([]); export const timesheetFilterStatusState = atom([]); -export const timesheetDeleteState = atom([]) +export const timesheetDeleteState = atom([]) diff --git a/apps/web/lib/components/alert-dialog-confirmation.tsx b/apps/web/lib/components/alert-dialog-confirmation.tsx index 8cc5c8068..19a9c06a8 100644 --- a/apps/web/lib/components/alert-dialog-confirmation.tsx +++ b/apps/web/lib/components/alert-dialog-confirmation.tsx @@ -46,11 +46,14 @@ export function AlertDialogConfirmation({ {cancelText} - {loading && ( + className="px-4 py-2 text-sm font-medium text-red-600 border border-red-600 rounded-md bg-light--theme-light dark:!bg-dark--theme-light" + aria-label={loading ? "Confirming action..." : confirmText} + disabled={loading} onClick={onConfirm} + > + {!loading && ( )} - {confirmText} + {loading ? "Processing..." : confirmText} 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 12dfbcf6a..bd937ee60 100644 --- a/apps/web/lib/features/integrations/calendar/table-time-sheet.tsx +++ b/apps/web/lib/features/integrations/calendar/table-time-sheet.tsx @@ -179,11 +179,21 @@ export function DataTableTimeSheet({ data }: { data?: GroupedTimesheet[] }) { closeModal } = useModal(); const { deleteTaskTimesheet, loadingDeleteTimesheet } = useTimesheet({}) - const { handleSelectRowTimesheet, selectTimesheet } = useTimelogFilterOptions() + const { handleSelectRowTimesheet, selectTimesheet, setSelectTimesheet } = useTimelogFilterOptions() const [isDialogOpen, setIsDialogOpen] = React.useState(false); const handleConfirm = () => { - deleteTaskTimesheet(); - setIsDialogOpen(false); + try { + deleteTaskTimesheet() + .then(() => { + setSelectTimesheet([]) + setIsDialogOpen(false); + }) + .catch((error) => { + console.error('Delete timesheet error:', error); + }); + } catch (error) { + console.error('Delete timesheet error:', error); + } }; const handleCancel = () => { setIsDialogOpen(false); @@ -228,7 +238,7 @@ export function DataTableTimeSheet({ data }: { data?: GroupedTimesheet[] }) { openModal() break; case 'Deleted': - // TODO: Implement pending logic + setIsDialogOpen(true) break; default: console.error(`Unsupported action: ${action}`); @@ -239,7 +249,7 @@ export function DataTableTimeSheet({ data }: { data?: GroupedTimesheet[] }) {
handleSelectRowTimesheet(task)} - checked={selectTimesheet.includes(task)} + onClick={() => handleSelectRowTimesheet(task.id)} + checked={selectTimesheet.includes(task.id)} />
{/*