Merge pull request #1717 from automatisch/AUT-829

refactor: rewrite useCurrentUser with RQ
This commit is contained in:
Ali BARIN
2024-03-15 14:02:09 +01:00
committed by GitHub
11 changed files with 52 additions and 121 deletions

View File

@@ -1,6 +1,18 @@
import { useQuery } from '@apollo/client';
import { GET_CURRENT_USER } from 'graphql/queries/get-current-user';
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useCurrentUser() {
const { data } = useQuery(GET_CURRENT_USER);
return data?.getCurrentUser;
const query = useQuery({
queryKey: ['currentUser'],
queryFn: async ({ signal }) => {
const { data } = await api.get(`/v1/users/me`, {
signal,
});
return data;
},
});
return query;
}

View File

@@ -1,6 +1,8 @@
import userAbility from 'helpers/userAbility';
import useCurrentUser from 'hooks/useCurrentUser';
export default function useCurrentUserAbility() {
const currentUser = useCurrentUser();
return userAbility(currentUser);
const { data: currentUser } = useCurrentUser();
return userAbility(currentUser?.data);
}