-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1503 from ever-co/develop
Release
- Loading branch information
Showing
37 changed files
with
341 additions
and
285 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
import { useQuery } from "react-query" | ||
import { getTimerStatusRequest, syncTimeSlotRequest } from "../../requests/timer" | ||
import { ITimerTimeslotParams } from "../../../interfaces/ITimer" | ||
import { ITimerTimeslotParams, TimerSource } from "../../../interfaces/ITimer" | ||
|
||
type IGetTimerStatusParams = ITimerTimeslotParams & { authToken: string } | ||
|
||
const fetchTimerStatus = async (params: IGetTimerStatusParams) => { | ||
const fetchTimerStatus = async ( | ||
params: IGetTimerStatusParams, | ||
isTimerRunning: boolean, | ||
lastlogTimerSource: TimerSource | null, | ||
) => { | ||
const { tenantId, organizationId, logType, authToken, employeeId } = params | ||
|
||
const { data } = await getTimerStatusRequest( | ||
{ source: "MOBILE", tenantId, organizationId }, | ||
authToken, | ||
) | ||
if (isTimerRunning) { | ||
await syncTimeSlotRequest( | ||
{ | ||
tenantId, | ||
organizationId, | ||
source: lastlogTimerSource || TimerSource.MOBILE, | ||
employeeId, | ||
duration: 5, | ||
logType, | ||
}, | ||
authToken, | ||
) | ||
} | ||
|
||
await syncTimeSlotRequest( | ||
{ | ||
tenantId, | ||
organizationId, | ||
source: "MOBILE", | ||
employeeId, | ||
duration: 5, | ||
logType, | ||
}, | ||
authToken, | ||
) | ||
const { data } = await getTimerStatusRequest({ tenantId, organizationId }, authToken) | ||
|
||
return data | ||
} | ||
|
||
const useFetchTimerStatus = (IGetTimerStatusParams, isTimerRunning: boolean) => | ||
useQuery(["status-timer", IGetTimerStatusParams], () => fetchTimerStatus(IGetTimerStatusParams), { | ||
enabled: isTimerRunning, | ||
refetchInterval: 5000, | ||
notifyOnChangeProps: ["data"], // Re-render only when data changes | ||
notifyOnChangePropsExclusions: ["isFetching"], | ||
}) | ||
const useFetchTimerStatus = ( | ||
IGetTimerStatusParams, | ||
isTimerRunning: boolean, | ||
lastlogTimerSource: TimerSource, | ||
) => | ||
useQuery( | ||
["status-timer", IGetTimerStatusParams], | ||
() => fetchTimerStatus(IGetTimerStatusParams, isTimerRunning, lastlogTimerSource), | ||
{ | ||
refetchInterval: 5000, | ||
notifyOnChangeProps: ["data"], // Re-render only when data changes | ||
notifyOnChangePropsExclusions: ["isFetching"], | ||
}, | ||
) | ||
export default useFetchTimerStatus |
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
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
Oops, something went wrong.