import { getOrderControllerGetMyOrdersQueryKey , OrderDTO , useOrderControllerCancelOrder , } from '@energyweb/exchange-irec-react-query-client' ; import { NotificationTypeEnum , showNotification , } from '@energyweb/origin-ui-core' ; import { useTranslation } from 'react-i18next' ; import { useQueryClient } from 'react-query' ; export const useApiCancelOrderHandler = ( orderSide ) => { const { mutate , isLoading : isMutating } = useOrderControllerCancelOrder ( ) ; const { t } = useTranslation ( ) ; const queryClient = useQueryClient ( ) ; const ordersQueryKey = getOrderControllerGetMyOrdersQueryKey ( ) ; const removeHandler = ( id , closeModal ) => { mutate ( { id } , { onSuccess : ( ) => { showNotification ( t ( 'exchange.myOrders.notifications.orderRemoveSuccess' , { orderSide , } ) , NotificationTypeEnum . Success ) ; queryClient . invalidateQueries ( ordersQueryKey ) ; closeModal ( ) ; } , onError : ( error ) => { showNotification ( `${ t ( 'exchange.myOrders.notifications.orderRemoveError' ) }:
            ${ error ?. response ?. data ?. message || '' }
            ` , NotificationTypeEnum . Error ) ; closeModal ( ) ; } , } ) ; } ; return { removeHandler , isMutating } ; } ;