mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 10:18:16 +00:00
feat(ui): added api hooks and state hooks for dashboard
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
|
||||
const userKeys = {
|
||||
getUser: ['user'] as const,
|
||||
userAction: ['user-action'] as const,
|
||||
getOrgUsers: (orgId: string) => [{ orgId }, 'user']
|
||||
};
|
||||
|
||||
@@ -31,6 +32,21 @@ const fetchUserDetails = async () => {
|
||||
|
||||
export const useGetUser = () => useQuery(userKeys.getUser, fetchUserDetails);
|
||||
|
||||
const fetchUserAction = async (action: string) => {
|
||||
const { data } = await apiRequest.get<{ userAction: string }>('/api/v1/user-action', {
|
||||
params: {
|
||||
action
|
||||
}
|
||||
});
|
||||
return data.userAction;
|
||||
};
|
||||
|
||||
export const useGetUserAction = (action: string) =>
|
||||
useQuery({
|
||||
queryKey: userKeys.userAction,
|
||||
queryFn: () => fetchUserAction(action)
|
||||
});
|
||||
|
||||
export const fetchOrgUsers = async (orgId: string) => {
|
||||
const { data } = await apiRequest.get<{ users: OrgUser[] }>(
|
||||
`/api/v1/organization/${orgId}/users`
|
||||
@@ -128,6 +144,16 @@ export const useUpdateOrgUserRole = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useRegisterUserAction = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<{}, {}, string>({
|
||||
mutationFn: (action) => apiRequest.post('/api/v1/user-action', { action }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(userKeys.userAction);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useLogoutUser = () =>
|
||||
useMutation({
|
||||
mutationFn: () => apiRequest.post('/api/v1/auth/logout'),
|
||||
|
||||
Reference in New Issue
Block a user