-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat]: Implement Timesheet logs API integration with State managemen…
…t and query handling (#3254) * feat:Implement timesheet logs API integration with state management and query handling * fix: coderabbitai * Update page.tsx --------- Co-authored-by: Ruslan Konviser <[email protected]>
- Loading branch information
1 parent
728f961
commit 0b5b01d
Showing
8 changed files
with
151 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useAuthenticateUser } from './useAuthenticateUser'; | ||
import { useAtom } from 'jotai'; | ||
import { timesheetRapportState } from '@/app/stores/time-logs'; | ||
import { useQuery } from '../useQuery'; | ||
import { useCallback, useEffect } from 'react'; | ||
import { getTaskTimesheetLogsApi } from '@/app/services/client/api/timer/timer-log'; | ||
import moment from 'moment'; | ||
|
||
interface TimesheetParams { | ||
startDate: Date | string; | ||
endDate: Date | string; | ||
} | ||
|
||
export function useTimesheet({ | ||
startDate, | ||
endDate, | ||
}: TimesheetParams) { | ||
const { user } = useAuthenticateUser(); | ||
const [timesheet, setTimesheet] = useAtom(timesheetRapportState); | ||
|
||
const { loading: loadingTimesheet, queryCall: queryTimesheet } = useQuery(getTaskTimesheetLogsApi); | ||
|
||
const getTaskTimesheet = useCallback( | ||
({ startDate, endDate }: TimesheetParams) => { | ||
if (!user) return; | ||
const from = moment(startDate).format('YYYY-MM-DD'); | ||
const to = moment(endDate).format('YYYY-MM-DD') | ||
queryTimesheet({ | ||
startDate: from, | ||
endDate: to, | ||
organizationId: user.employee?.organizationId, | ||
tenantId: user.tenantId ?? '', | ||
timeZone: user.timeZone?.split('(')[0].trim(), | ||
}).then((response) => { | ||
setTimesheet(response.data); | ||
}).catch((error) => { | ||
console.error('Error fetching timesheet:', error); | ||
}); | ||
}, | ||
[user, queryTimesheet, setTimesheet] | ||
); | ||
useEffect(() => { | ||
getTaskTimesheet({ startDate, endDate }); | ||
}, [getTaskTimesheet, startDate, endDate]); | ||
return { | ||
loadingTimesheet, | ||
timesheet, | ||
getTaskTimesheet, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { ITimerLogsDailyReport } from '@app/interfaces/timer/ITimerLogs'; | ||
import { atom } from 'jotai'; | ||
import { ITimeSheet } from '../interfaces'; | ||
|
||
export const timerLogsDailyReportState = atom<ITimerLogsDailyReport[]>([]); | ||
|
||
export const timesheetRapportState = atom<ITimeSheet[]>([]) |