import React, { useState, useEffect } from 'react'; import { useIntl, defineMessages, FormattedMessage } from 'react-intl'; import { useHistory } from 'react-router-dom'; import { fetchBackupCodes } from 'soapbox/actions/mfa'; import snackbar from 'soapbox/actions/snackbar'; import { useAppDispatch } from 'soapbox/hooks'; import { Button, FormActions, Spinner, Stack, Text } from '../../../components/ui'; const messages = defineMessages({ mfaCancelButton: { id: 'column.mfa_cancel', defaultMessage: 'Cancel' }, mfaSetupButton: { id: 'column.mfa_setup', defaultMessage: 'Proceed to Setup' }, codesFail: { id: 'security.codes.fail', defaultMessage: 'Failed to fetch backup codes' }, }); interface IEnableOtpForm { displayOtpForm: boolean, handleSetupProceedClick: (event: React.MouseEvent) => void, } const EnableOtpForm: React.FC = ({ displayOtpForm, handleSetupProceedClick }) => { const dispatch = useAppDispatch(); const intl = useIntl(); const history = useHistory(); const [backupCodes, setBackupCodes] = useState>([]); useEffect(() => { dispatch(fetchBackupCodes()).then(({ codes: backupCodes }: { codes: Array }) => { setBackupCodes(backupCodes); }) .catch(() => { dispatch(snackbar.error(intl.formatMessage(messages.codesFail))); }); }, []); return (
{backupCodes.length > 0 ? (
{backupCodes.map((code, i) => ( {code} ))}
) : ( )}
{!displayOtpForm && (