refactor: rewrite useAuthClients with RQ
This commit is contained in:
17
packages/web/src/hooks/useAdminAppAuthClients.js
Normal file
17
packages/web/src/hooks/useAdminAppAuthClients.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAdminAppAuthClient(appKey) {
|
||||
const query = useQuery({
|
||||
queryKey: ['admin', 'apps', appKey, 'auth-clients'],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get(`/v1/admin/apps/${appKey}/auth-clients`, {
|
||||
signal,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
enabled: !!appKey,
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
import { useLazyQuery } from '@apollo/client';
|
||||
import * as React from 'react';
|
||||
import { GET_APP_AUTH_CLIENTS } from 'graphql/queries/get-app-auth-clients.ee';
|
||||
export default function useAppAuthClient({ appKey, active }) {
|
||||
const [getAppAuthClients, { data, loading }] = useLazyQuery(
|
||||
GET_APP_AUTH_CLIENTS,
|
||||
{
|
||||
context: { autoSnackbar: false },
|
||||
},
|
||||
);
|
||||
const appAuthClients = data?.getAppAuthClients;
|
||||
React.useEffect(
|
||||
function fetchUponAppKey() {
|
||||
if (!appKey) return;
|
||||
getAppAuthClients({
|
||||
variables: { appKey, ...(typeof active === 'boolean' && { active }) },
|
||||
});
|
||||
},
|
||||
[appKey],
|
||||
);
|
||||
return {
|
||||
appAuthClients,
|
||||
loading,
|
||||
};
|
||||
}
|
17
packages/web/src/hooks/useAppAuthClients.js
Normal file
17
packages/web/src/hooks/useAppAuthClients.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAppAuthClients(appKey) {
|
||||
const query = useQuery({
|
||||
queryKey: ['apps', appKey, 'auth-clients'],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get(`/v1/apps/${appKey}/auth-clients`, {
|
||||
signal,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
enabled: !!appKey,
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
Reference in New Issue
Block a user