import { Role } from '@energyweb/origin-backend-core' ; import { getOrganizationControllerGetUsersQueryKey , useOrganizationControllerChangeMemberRole , UserDTO , } from '@energyweb/origin-backend-react-query-client' ; import { NotificationTypeEnum , showNotification , } from '@energyweb/origin-ui-core' ; import { useTranslation } from 'react-i18next' ; import { useQueryClient } from 'react-query' ; import { useUser } from '../fetching' ; export const useOrganizationMemberRoleUpdate = ( ) => { const { t } = useTranslation ( ) ; const { mutate , isLoading : isMutating } = useOrganizationControllerChangeMemberRole ( ) ; const { user : userUpdating } = useUser ( ) ; const queryClient = useQueryClient ( ) ; const membersKey = getOrganizationControllerGetUsersQueryKey ( userUpdating ?. organization ?. id ) ; const updateRoleHandler = ( userToUpdateId , newRole ) => { mutate ( { id : userUpdating ?. organization ?. id , userId : userToUpdateId , data : { role : newRole , } , } , { onSuccess : ( ) => { showNotification ( t ( 'organization.members.notifications.roleChangeSuccess' ) , NotificationTypeEnum . Success ) ; queryClient . invalidateQueries ( membersKey ) ; } , onError : ( error ) => { showNotification ( `${ t ( 'organization.members.notifications.roleChangeError' ) }:
            ${ error ?. response ?. data ?. message || '' }
            ` , NotificationTypeEnum . Error ) ; } , } ) ; } ; return { updateRoleHandler , isMutating } ; } ;