import { FullCertificationRequestDTO , getCertificationRequestControllerGetAllQueryKey , useCertificationRequestControllerApprove , useCertificationRequestControllerRevoke , } from '@energyweb/issuer-irec-api-react-query-client' ; import { NotificationTypeEnum , showNotification , } from '@energyweb/origin-ui-core' ; import { useTranslation } from 'react-i18next' ; import { useQueryClient } from 'react-query' ; export const useApiHandlersForPendingRequests = ( ) => { const { t } = useTranslation ( ) ; const queryClient = useQueryClient ( ) ; const certificationRequestsKey = getCertificationRequestControllerGetAllQueryKey ( ) ; const { mutate : approve , isLoading : isApproveMutating } = useCertificationRequestControllerApprove ( { mutation : { onSuccess : ( ) => { showNotification ( t ( 'certificate.pending.notifications.approveSuccess' ) , NotificationTypeEnum . Success ) ; queryClient . invalidateQueries ( certificationRequestsKey ) ; } , onError : ( error ) => { showNotification ( `${ t ( 'certificate.pending.notifications.approveError' ) }:
        ${ error ?. response ?. data ?. message || '' }
        ` , NotificationTypeEnum . Error ) ; } , } , } ) ; const { mutate : revoke , isLoading : isRejectMutating } = useCertificationRequestControllerRevoke ( { mutation : { onSuccess : ( ) => { showNotification ( t ( 'certificate.pending.notifications.revokeSuccess' ) , NotificationTypeEnum . Success ) ; queryClient . invalidateQueries ( certificationRequestsKey ) ; } , onError : ( error ) => { showNotification ( `${ t ( 'organization.invitations.notifications.revokeError' ) }:
        ${ error ?. response ?. data ?. message || '' }
        ` , NotificationTypeEnum . Error ) ; } , } , } ) ; const approveHandler = ( id ) => { approve ( { id } ) ; } ; const rejectHandler = ( id ) => { revoke ( { id } ) ; } ; return { approveHandler , isApproveMutating , rejectHandler , isRejectMutating } ; } ;