fear: change requests to RTK query
All checks were successful
it-academy/dry-wash-pl/pipeline/pr-main This commit looks good

This commit is contained in:
2025-02-02 11:59:27 +03:00
parent ad1f948641
commit a00aaff29d
12 changed files with 145 additions and 238 deletions

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import {
Menu,
MenuButton,
@@ -10,7 +10,7 @@ import {
import { EditIcon } from '@chakra-ui/icons';
import { useTranslation } from 'react-i18next';
import { armService } from '../../api/arm';
import { useDeleteMasterMutation } from '../../__data__/service/api';
interface MasterActionsMenu {
id: string;
@@ -21,12 +21,17 @@ const MasterActionsMenu = ({ id }: MasterActionsMenu) => {
keyPrefix: 'dry-wash.arm.master.table.actionsMenu',
});
const { deleteMaster } = armService();
const [deleteMaster, { isSuccess, isError, error, isLoading }] =
useDeleteMasterMutation();
const toast = useToast();
const handleClickDelete = async () => {
try {
await deleteMaster({ id });
await deleteMaster({ id });
};
useEffect(() => {
if (isSuccess) {
toast({
title: 'Мастер удалён.',
description: `Мастер с ID "${id}" успешно удалён.`,
@@ -35,7 +40,11 @@ const MasterActionsMenu = ({ id }: MasterActionsMenu) => {
isClosable: true,
position: 'top-right',
});
} catch (error) {
}
}, [isSuccess]);
useEffect(() => {
if (isError) {
toast({
title: 'Ошибка удаления мастера.',
description: 'Не удалось удалить мастера. Попробуйте ещё раз.',
@@ -46,13 +55,15 @@ const MasterActionsMenu = ({ id }: MasterActionsMenu) => {
});
console.error(error);
}
};
}, [isError]);
return (
<Menu>
<MenuButton icon={<EditIcon />} as={IconButton} variant='outline' />
<MenuList>
<MenuItem onClick={handleClickDelete}>{t('delete')}</MenuItem>
<MenuItem onClick={handleClickDelete} isDisabled={isLoading}>
{t('delete')}
</MenuItem>
</MenuList>
</Menu>
);