-
Notifications
You must be signed in to change notification settings - Fork 4
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 #757 from yeatmanlab/ref/318/query-composables-cre…
…ate-administration Migrate Create Administration page to composable TanStack queries
- Loading branch information
Showing
40 changed files
with
932 additions
and
598 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
40 changes: 40 additions & 0 deletions
40
src/composables/mutations/useUpsertAdministrationMutation.js
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,40 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/vue-query'; | ||
import { useAuthStore } from '@/store/auth'; | ||
import { ADMINISTRATION_UPSERT_MUTATION_KEY } from '@/constants/mutationKeys'; | ||
import { | ||
ADMINISTRATIONS_QUERY_KEY, | ||
ADMINISTRATIONS_LIST_QUERY_KEY, | ||
ADMINISTRATION_ASSIGNMENTS_QUERY_KEY, | ||
} from '@/constants/queryKeys'; | ||
|
||
/** | ||
* Upsert Administration mutation. | ||
* | ||
* TanStack mutation to update or insert an administration and automatically invalidate the corresponding queries. | ||
* | ||
* @returns {Object} The mutation object returned by `useMutation`. | ||
*/ | ||
const useUpsertAdministrationMutation = () => { | ||
const authStore = useAuthStore(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ADMINISTRATION_UPSERT_MUTATION_KEY, | ||
mutationFn: async (data) => { | ||
await authStore.roarfirekit.createAdministration(data); | ||
}, | ||
onSuccess: () => { | ||
// Invalidate the queries to refetch the administration data. | ||
// @NOTE: Usually we would apply a more granular invalidation strategy including updating the specific | ||
// adminitration record in the cache. However, unfortunately, given the nature of the data model and the data that | ||
// is updated in the application, we would have to manually map the updated data, which could cause issues when | ||
// the data model changes. Therefore, we invalidate the entire query to ensure the data is up-to-date. | ||
queryClient.invalidateQueries({ queryKey: [ADMINISTRATIONS_QUERY_KEY] }); | ||
queryClient.invalidateQueries({ queryKey: [ADMINISTRATIONS_LIST_QUERY_KEY] }); | ||
queryClient.invalidateQueries({ queryKey: [ADMINISTRATION_ASSIGNMENTS_QUERY_KEY] }); | ||
console.warn('Administration upserted successfully.'); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useUpsertAdministrationMutation; |
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.