https://dev.kronoz.win/r/marzneshin.git
1import {
2 useToast,
3} from '@chakra-ui/react';
4import { FC, useState } from 'react';
5import { useTranslation } from 'react-i18next';
6import { useUsers } from 'stores';
7import { DeleteModal } from 'components/delete-modal';
8
9type DeleteUserModalProps = {
10 deleteCallback?: () => void;
11};
12
13export const DeleteUserModal: FC<DeleteUserModalProps> = () => {
14 const [loading, setLoading] = useState(false);
15 const { deletingUser, onDeletingUser, deleteUser } = useUsers();
16 const { t } = useTranslation();
17 const toast = useToast();
18 const onClose = () => {
19 onDeletingUser(null);
20 };
21 const onDelete = () => {
22 if (deletingUser) {
23 setLoading(true);
24 deleteUser(deletingUser)
25 .then(() => {
26 toast({
27 title: t('deleteUser.deleteSuccess', { username: deletingUser.username }),
28 status: 'success',
29 isClosable: true,
30 position: 'top',
31 duration: 3000,
32 });
33 })
34 .then(onClose)
35 .finally(setLoading.bind(null, false));
36 }
37 };
38 return (
39 <DeleteModal
40 onDelete={onDelete}
41 loading={loading}
42 isOpen={!!deletingUser}
43 onClose={onClose}
44 deletingObjectName={deletingUser?.username}
45 deleteObjectPromptT={'deleteUser.prompt'}
46 deleteObjectTitleT={'deleteUser.title'}
47 />
48 );
49};