-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(export): users list dynamic based on mindate (#573)
- Loading branch information
1 parent
afd683f
commit 6caf75d
Showing
5 changed files
with
85 additions
and
4 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,36 @@ | ||
import React from "react"; | ||
import { ADMIN_USERS_SINCE_DATE } from "common/utils/apiQueries"; | ||
import { useApi } from "common/utils/api"; | ||
import { useAdminStore } from "../../admin/store/store"; | ||
import { isoFormatLocalDate } from "common/utils/time"; | ||
import { useSnackbarAlerts } from "../Snackbar"; | ||
import { formatApiError } from "common/utils/errors"; | ||
|
||
export const useGetUsersSinceDate = () => { | ||
const api = useApi(); | ||
const alerts = useSnackbarAlerts(); | ||
const adminStore = useAdminStore(); | ||
const earliestDate = React.useRef(null); | ||
const memo = React.useRef(null); | ||
|
||
const getUsersSinceDate = async fromDate => { | ||
if (!earliestDate.current || fromDate < earliestDate.current) { | ||
try { | ||
const payload = await api.graphQlQuery(ADMIN_USERS_SINCE_DATE, { | ||
id: adminStore.userId, | ||
activityAfter: isoFormatLocalDate(fromDate), | ||
companyIds: [adminStore.companyId] | ||
}); | ||
const users = payload?.data?.user?.adminedCompanies[0]?.users; | ||
earliestDate.current = fromDate; | ||
memo.current = users; | ||
return users; | ||
} catch (err) { | ||
alerts.error(formatApiError(err), "get_users_since_date", 6000); | ||
} | ||
} | ||
return memo.current; | ||
}; | ||
|
||
return { getUsersSinceDate }; | ||
}; |