refactor: rewrite useRole with RQ

This commit is contained in:
Rıdvan Akca
2024-03-15 12:38:11 +03:00
parent 40934a2c77
commit 3f9f17f584
8 changed files with 35 additions and 227 deletions

View File

@@ -1,19 +1,19 @@
import * as React from 'react';
import { useLazyQuery } from '@apollo/client';
import { GET_ROLE } from 'graphql/queries/get-role.ee';
export default function useRole(roleId) {
const [getRole, { data, loading }] = useLazyQuery(GET_ROLE);
React.useEffect(() => {
if (roleId) {
getRole({
variables: {
id: roleId,
},
import { useQuery } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useRole({ roleId }) {
const query = useQuery({
queryKey: ['role', roleId],
queryFn: async ({ signal }) => {
const { data } = await api.get(`/v1/admin/roles/${roleId}`, {
signal,
});
}
}, [roleId]);
return {
role: data?.getRole,
loading,
};
return data;
},
enabled: !!roleId,
});
return query;
}