mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat: add toast when delete user
This commit is contained in:
parent
437d0d8105
commit
2e93cbafa7
@ -23,9 +23,11 @@ import PaginateUI from '../../../common/PaginateUI/PaginateUI';
|
|||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { IUser } from '../../../../interfaces/user';
|
import { IUser } from '../../../../interfaces/user';
|
||||||
import IRole from '../../../../interfaces/role';
|
import IRole from '../../../../interfaces/role';
|
||||||
|
import useToast from '../../../../hooks/useToast';
|
||||||
|
|
||||||
const UsersList = () => {
|
const UsersList = () => {
|
||||||
const { users, roles, refetch, loading } = useUsers();
|
const { users, roles, refetch, loading } = useUsers();
|
||||||
|
const { setToastData, setToastApiError } = useToast();
|
||||||
const {
|
const {
|
||||||
removeUser,
|
removeUser,
|
||||||
changePassword,
|
changePassword,
|
||||||
@ -53,12 +55,14 @@ const UsersList = () => {
|
|||||||
setDelUser(undefined);
|
setDelUser(undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
const openDelDialog = (user: IUser) => (e: React.SyntheticEvent<Element, Event>) => {
|
const openDelDialog =
|
||||||
|
(user: IUser) => (e: React.SyntheticEvent<Element, Event>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setDelDialog(true);
|
setDelDialog(true);
|
||||||
setDelUser(user);
|
setDelUser(user);
|
||||||
};
|
};
|
||||||
const openPwDialog = (user: IUser) => (e: React.SyntheticEvent<Element, Event>) => {
|
const openPwDialog =
|
||||||
|
(user: IUser) => (e: React.SyntheticEvent<Element, Event>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setPwDialog({ open: true, user });
|
setPwDialog({ open: true, user });
|
||||||
};
|
};
|
||||||
@ -67,13 +71,18 @@ const UsersList = () => {
|
|||||||
setPwDialog({ open: false });
|
setPwDialog({ open: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDeleteUser = () => {
|
const onDeleteUser = async () => {
|
||||||
removeUser(delUser)
|
try {
|
||||||
.then(() => {
|
await removeUser(delUser);
|
||||||
|
setToastData({
|
||||||
|
title: `${delUser?.name} has been deleted`,
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
refetch();
|
refetch();
|
||||||
closeDelDialog();
|
closeDelDialog();
|
||||||
})
|
} catch (e: any) {
|
||||||
.catch(handleCatch);
|
setToastApiError(e.toString());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCatch = () =>
|
const handleCatch = () =>
|
||||||
|
Loading…
Reference in New Issue
Block a user