feat: add hook useShowToast.ts
All checks were successful
it-academy/dry-wash-pl/pipeline/pr-main This commit looks good
All checks were successful
it-academy/dry-wash-pl/pipeline/pr-main This commit looks good
This commit is contained in:
@@ -5,12 +5,12 @@ import {
|
||||
MenuList,
|
||||
MenuItem,
|
||||
IconButton,
|
||||
useToast,
|
||||
} from '@chakra-ui/react';
|
||||
import { EditIcon } from '@chakra-ui/icons';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useDeleteMasterMutation } from '../../__data__/service/api';
|
||||
import useShowToast from '../../hooks/useShowToast';
|
||||
|
||||
interface MasterActionsMenu {
|
||||
id: string;
|
||||
@@ -24,7 +24,7 @@ const MasterActionsMenu = ({ id }: MasterActionsMenu) => {
|
||||
const [deleteMaster, { isSuccess, isError, error, isLoading }] =
|
||||
useDeleteMasterMutation();
|
||||
|
||||
const toast = useToast();
|
||||
const showToast = useShowToast();
|
||||
|
||||
const handleClickDelete = async () => {
|
||||
await deleteMaster({ id });
|
||||
@@ -32,27 +32,13 @@ const MasterActionsMenu = ({ id }: MasterActionsMenu) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (isSuccess) {
|
||||
toast({
|
||||
title: 'Мастер удалён.',
|
||||
description: `Мастер с ID "${id}" успешно удалён.`,
|
||||
status: 'success',
|
||||
duration: 5000,
|
||||
isClosable: true,
|
||||
position: 'top-right',
|
||||
});
|
||||
showToast(t('toast.success'), 'success');
|
||||
}
|
||||
}, [isSuccess]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isError) {
|
||||
toast({
|
||||
title: 'Ошибка удаления мастера.',
|
||||
description: 'Не удалось удалить мастера. Попробуйте ещё раз.',
|
||||
status: 'error',
|
||||
duration: 5000,
|
||||
isClosable: true,
|
||||
position: 'top-right',
|
||||
});
|
||||
showToast(t('toast.error.title'), 'error', t('toast.error.description'));
|
||||
console.error(error);
|
||||
}
|
||||
}, [isError]);
|
||||
|
||||
Reference in New Issue
Block a user