2021-06-21 15:22:21 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
import { Formik, FormikHelpers } from 'formik';
|
|
|
|
import router from 'next/router';
|
|
|
|
import { DeadCenter } from 'pages/gallery';
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { Form, FormControl } 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 {
|
2021-06-22 05:37:47 +00:00
|
|
|
onSubmit: any
|
2021-06-21 15:22:21 +00:00
|
|
|
back: any
|
|
|
|
buttonText: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function VerifyTwoFactor(props: Props) {
|
|
|
|
const [waiting, setWaiting] = useState(false);
|
|
|
|
|
|
|
|
const submitForm = async (
|
|
|
|
{ otp }: formValues,
|
2021-06-22 06:58:26 +00:00
|
|
|
{ setFieldError, resetForm }: FormikHelpers<formValues>,
|
2021-06-21 15:22:21 +00:00
|
|
|
) => {
|
|
|
|
try {
|
|
|
|
setWaiting(true);
|
2021-06-22 05:37:47 +00:00
|
|
|
await props.onSubmit(otp);
|
2021-06-21 15:22:21 +00:00
|
|
|
} catch (e) {
|
2021-06-22 06:58:26 +00:00
|
|
|
resetForm();
|
2021-06-21 15:22:21 +00:00
|
|
|
setFieldError('otp', `${constants.UNKNOWN_ERROR} ${e.message}`);
|
|
|
|
}
|
|
|
|
setWaiting(false);
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<p style={{ marginBottom: '30px' }}>enter the 6-digit code from your authenticator app.</p>
|
|
|
|
<Formik<formValues>
|
|
|
|
initialValues={{ otp: '' }}
|
|
|
|
validateOnChange={false}
|
|
|
|
validateOnBlur={false}
|
|
|
|
onSubmit={submitForm}
|
|
|
|
>
|
|
|
|
{({
|
|
|
|
values,
|
|
|
|
errors,
|
|
|
|
handleChange,
|
|
|
|
handleSubmit,
|
|
|
|
}) => (
|
|
|
|
<Form noValidate onSubmit={handleSubmit} style={{ width: '100%' }}>
|
2021-06-25 20:34:56 +00:00
|
|
|
<Form.Group style={{ marginBottom: '32px' }} controlId="formBasicEmail">
|
2021-06-21 15:22:21 +00:00
|
|
|
<DeadCenter>
|
|
|
|
<OtpInput value={values.otp}
|
|
|
|
onChange={handleChange('otp')}
|
|
|
|
numInputs={6}
|
|
|
|
separator={'-'}
|
|
|
|
isInputNum
|
|
|
|
className={'otp-input'}
|
|
|
|
/>
|
|
|
|
{errors.otp &&
|
2021-06-25 20:34:56 +00:00
|
|
|
<div style={{ display: 'block', marginTop: '16px' }} className="invalid-feedback">{constants.INCORRECT_CODE}</div>
|
2021-06-21 15:22:21 +00:00
|
|
|
}
|
|
|
|
</DeadCenter>
|
|
|
|
</Form.Group>
|
|
|
|
<SubmitButton
|
|
|
|
buttonText={props.buttonText}
|
|
|
|
loading={waiting}
|
|
|
|
disabled={values.otp.length < 6}
|
|
|
|
/>
|
|
|
|
</Form>
|
|
|
|
)}
|
|
|
|
</Formik>
|
|
|
|
|
|
|
|
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|