import { useSetModal, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; import type { ComponentProps } from 'react'; import ConfirmOwnerChangeWarningModal from '../../../../components/ConfirmOwnerChangeModal'; export const useConfirmOwnerChanges = (): (( action: (confirm?: boolean) => Promise, modalProps: Pick, 'contentTitle' | 'confirmText'>, onChange: () => void, ) => Promise) => { const setModal = useSetModal(); const dispatchToastMessage = useToastMessageDispatch(); return async (action, modalProps, onChange): Promise => { try { return await action(); } catch (error: any) { if (error.errorType === 'user-last-owner') { const { shouldChangeOwner, shouldBeRemoved } = error.details; const handleConfirm = async (): Promise => { await action(true); setModal(); onChange(); }; return setModal( setModal()} />, ); } dispatchToastMessage({ type: 'error', message: error }); } }; };