-
Notifications
You must be signed in to change notification settings - Fork 5
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 #760 from yeatmanlab/ref/318/query-composables-lis…
…t-orgs Migrate List Organisations page to composable TanStack queries
- Loading branch information
Showing
5 changed files
with
77 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { computed, ref } from 'vue'; | ||
import { useQuery } from '@tanstack/vue-query'; | ||
import useUserType from '@/composables/useUserType'; | ||
import useUserClaimsQuery from '@/composables/queries/useUserClaimsQuery'; | ||
import { orgPageFetcher } from '@/helpers/query/orgs'; | ||
import { ORGS_TABLE_QUERY_KEY } from '@/constants/queryKeys'; | ||
/** | ||
* Orgs Table query. | ||
* | ||
* Fetches all orgs assigned to the current user account. This query is intended to be used by the List Orgs page that | ||
* contains a tabbed data table with orgs (districts, schools, etc.) assigned to the user. | ||
* | ||
* @TODO: Explore the possibility of removing this query in favour of more granular queries for each org type. | ||
* | ||
* @param {String} activeOrgType – The active org type (district, school, etc.). | ||
* @param {String} selectedDistrict – The selected district ID. | ||
* @param {String} selectedSchool – The selected school ID. | ||
* @param {String} orderBy – The order by field. | ||
* @param {QueryOptions|undefined} queryOptions – Optional TanStack query options. | ||
* @returns {UseQueryResult} The TanStack query result. | ||
*/ | ||
const useOrgsTableQuery = (activeOrgType, selectedDistrict, selectedSchool, orderBy, queryOptions = undefined) => { | ||
const { data: userClaims } = useUserClaimsQuery({ enabled: queryOptions?.enabled ?? true }); | ||
const { isSuperAdmin } = useUserType(userClaims); | ||
|
||
const adminOrgs = computed(() => userClaims?.value?.claims?.minimalAdminOrgs); | ||
|
||
return useQuery({ | ||
queryKey: [ORGS_TABLE_QUERY_KEY, activeOrgType, selectedDistrict, selectedSchool, orderBy], | ||
queryFn: () => | ||
orgPageFetcher( | ||
activeOrgType, | ||
selectedDistrict, | ||
selectedSchool, | ||
orderBy, | ||
ref(100000), | ||
ref(0), | ||
isSuperAdmin, | ||
adminOrgs, | ||
), | ||
...queryOptions, | ||
}); | ||
}; | ||
|
||
export default useOrgsTableQuery; |
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