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:
@@ -12,7 +12,6 @@ import {
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerOverlay,
|
||||
useToast,
|
||||
InputGroup,
|
||||
InputLeftElement,
|
||||
FormErrorMessage,
|
||||
@@ -21,8 +20,8 @@ import { useTranslation } from 'react-i18next';
|
||||
import { PhoneIcon } from '@chakra-ui/icons';
|
||||
|
||||
import { api } from '../../__data__/service/api';
|
||||
import showToast from '../../helpers/showToast';
|
||||
import { DrawerInputs } from '../../models/arm/form';
|
||||
import useShowToast from '../../hooks/useShowToast';
|
||||
|
||||
interface MasterDrawerProps {
|
||||
isOpen: boolean;
|
||||
@@ -50,12 +49,7 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
|
||||
const isEmptyFields = trimMaster.name === '' || trimMaster.phone === '';
|
||||
|
||||
if (isEmptyFields) {
|
||||
showToast({
|
||||
toast,
|
||||
title: t('toast.error.base'),
|
||||
description: t('toast.error.empty-fields'),
|
||||
status: 'error',
|
||||
});
|
||||
showToast(t('toast.error.base'), 'error', t('toast.error.empty-fields'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,15 +57,11 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
|
||||
};
|
||||
|
||||
const [addMaster, { error, isSuccess }] = api.useAddMasterMutation();
|
||||
const toast = useToast();
|
||||
const showToast = useShowToast();
|
||||
|
||||
useEffect(() => {
|
||||
if (isSuccess) {
|
||||
showToast({
|
||||
toast,
|
||||
title: t('toast.create-master'),
|
||||
status: 'success',
|
||||
});
|
||||
showToast(t('toast.create-master'), 'success');
|
||||
reset();
|
||||
onClose();
|
||||
}
|
||||
@@ -79,12 +69,11 @@ const MasterDrawer = ({ isOpen, onClose }: MasterDrawerProps) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
showToast({
|
||||
toast,
|
||||
title: t('toast.error.create-master'),
|
||||
description: t('toast.error.create-master-details'),
|
||||
status: 'error',
|
||||
});
|
||||
showToast(
|
||||
t('toast.error.create-master'),
|
||||
'error',
|
||||
t('toast.error.create-master-details'),
|
||||
);
|
||||
console.error(error);
|
||||
}
|
||||
}, [error]);
|
||||
|
||||
Reference in New Issue
Block a user