/* eslint-disable @typescript-eslint/no-unused-vars */ import { Formik, FormikHelpers } from 'formik'; import { DeadCenter } from 'pages/gallery'; import React, { useRef, useState } from 'react'; import { Form } from 'react-bootstrap'; import OtpInput from 'react-otp-input'; import constants from 'utils/strings/constants'; import SubmitButton from './SubmitButton'; interface formValues { otp: string; } interface Props { onSubmit: any; back: any; buttonText: string; } export default function VerifyTwoFactor(props: Props) { const [waiting, setWaiting] = useState(false); const otpInputRef = useRef(null); const submitForm = async ( { otp }: formValues, { setFieldError, resetForm }: FormikHelpers ) => { try { setWaiting(true); await props.onSubmit(otp); } catch (e) { resetForm(); for (let i = 0; i < 6; i++) { otpInputRef.current?.focusPrevInput(); } setFieldError('otp', `${constants.UNKNOWN_ERROR} ${e.message}`); } setWaiting(false); }; const onChange = ( otp: string, callback: Function, triggerSubmit: Function ) => { callback(otp); if (otp.length === 6) { triggerSubmit(otp); } }; return ( <>

enter the 6-digit code from your authenticator app.

initialValues={{ otp: '' }} validateOnChange={false} validateOnBlur={false} onSubmit={submitForm}> {({ values, errors, handleChange, handleSubmit, submitForm, }) => (
{ onChange( otp, handleChange('otp'), submitForm ); }} numInputs={6} separator={'-'} isInputNum className={'otp-input'} /> {errors.otp && (
{constants.INCORRECT_CODE}
)}
)} ); }