import React, { FC, useCallback, useEffect, useRef } from 'react'; import { Box, Button, TextInput, Icon, ButtonGroup, Modal } from '@rocket.chat/fuselage'; import { useTranslation } from '../../contexts/TranslationContext'; import { useForm } from '../../hooks/useForm'; type VerifyCodeModalProps = { onVerify: (code: string) => void; onCancel: () => void; }; const VerifyCodeModal: FC = ({ onVerify, onCancel, ...props }) => { const t = useTranslation(); const ref = useRef(); useEffect(() => { if (typeof ref?.current?.focus === 'function') { ref.current.focus(); } }, [ref]); const { values, handlers } = useForm({ code: '' }); const { code } = values as { code: string }; const { handleCode } = handlers; const handleVerify = useCallback((e) => { if (e.type === 'click' || (e.type === 'keydown' && e.keyCode === 13)) { onVerify(code); } }, [code, onVerify]); return {t('Two-factor_authentication')} {t('Open_your_authentication_app_and_enter_the_code')} ; }; export default VerifyCodeModal;