mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 05:58:56 +08:00
feat(admin): add ban user to admin panel (#10780)
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
||||
createChangePasswordUrlMutation,
|
||||
createUserMutation,
|
||||
deleteUserMutation,
|
||||
disableUserMutation,
|
||||
enableUserMutation,
|
||||
getUsersCountQuery,
|
||||
listUsersQuery,
|
||||
updateAccountFeaturesMutation,
|
||||
@@ -162,6 +164,55 @@ export const useDeleteUser = () => {
|
||||
return deleteById;
|
||||
};
|
||||
|
||||
export const useEnableUser = () => {
|
||||
const { trigger: enableUserById } = useMutation({
|
||||
mutation: enableUserMutation,
|
||||
});
|
||||
|
||||
const revalidate = useMutateQueryResource();
|
||||
|
||||
const enableById = useAsyncCallback(
|
||||
async (id: string, callback?: () => void) => {
|
||||
await enableUserById({ id })
|
||||
.then(async ({ enableUser }) => {
|
||||
await revalidate(listUsersQuery);
|
||||
toast(`User ${enableUser.email} enabled successfully`);
|
||||
callback?.();
|
||||
})
|
||||
.catch(e => {
|
||||
toast.error('Failed to enable user: ' + e.message);
|
||||
});
|
||||
},
|
||||
[enableUserById, revalidate]
|
||||
);
|
||||
|
||||
return enableById;
|
||||
};
|
||||
export const useDisableUser = () => {
|
||||
const { trigger: disableUserById } = useMutation({
|
||||
mutation: disableUserMutation,
|
||||
});
|
||||
|
||||
const revalidate = useMutateQueryResource();
|
||||
|
||||
const disableById = useAsyncCallback(
|
||||
async (id: string, callback?: () => void) => {
|
||||
await disableUserById({ id })
|
||||
.then(async ({ banUser }) => {
|
||||
await revalidate(listUsersQuery);
|
||||
toast(`User ${banUser.email} disabled successfully`);
|
||||
callback?.();
|
||||
})
|
||||
.catch(e => {
|
||||
toast.error('Failed to disable user: ' + e.message);
|
||||
});
|
||||
},
|
||||
[disableUserById, revalidate]
|
||||
);
|
||||
|
||||
return disableById;
|
||||
};
|
||||
|
||||
export const useUserCount = () => {
|
||||
const {
|
||||
data: { usersCount },
|
||||
|
||||
Reference in New Issue
Block a user