diff --git a/settings/src/components/backup-codes.js b/settings/src/components/backup-codes.js index 1f560c1d..f6b6ddc8 100644 --- a/settings/src/components/backup-codes.js +++ b/settings/src/components/backup-codes.js @@ -24,10 +24,9 @@ import DownloadButton from './download-button'; */ export default function BackupCodes( { onSuccess = () => {} } ) { const { - user: { backupCodesEnabled, hasPrimaryProvider, backupCodesRemaining }, - backupCodesVerified, + user: { hasPrimaryProvider }, } = useContext( GlobalContext ); - const [ regenerating, setRegenerating ] = useState( false ); + const [ generating, setGenerating ] = useState( false ); // Prevent users from accessing directly through the URL. if ( ! hasPrimaryProvider ) { @@ -41,26 +40,21 @@ export default function BackupCodes( { onSuccess = () => {} } ) { ); } - if ( - ! backupCodesEnabled || - backupCodesRemaining === 0 || - regenerating || - ! backupCodesVerified - ) { - return ; - } - - return ; + return generating ? ( + + ) : ( + + ); } /** * Setup the Backup Codes provider. * * @param props - * @param props.setRegenerating + * @param props.setGenerating * @param props.onSuccess */ -function Setup( { setRegenerating, onSuccess } ) { +function Setup( { setGenerating, onSuccess } ) { const { setGlobalNotice, user: { userRecord }, @@ -110,18 +104,14 @@ function Setup( { setRegenerating, onSuccess } ) { // The codes have already been saved to usermeta, see `generateCodes()` above. setBackupCodesVerified( true ); setGlobalNotice( 'Backup codes have been enabled.' ); - setRegenerating( false ); + setGenerating( false ); onSuccess(); } ); return ( <>
-

- Backup codes let you access your account if your primary two-factor - authentication method is unavailable, like if your phone is lost or stolen. Each - code can only be used once. -

+

Please print the codes and keep them in a safe place.

@@ -142,12 +132,6 @@ function Setup( { setRegenerating, onSuccess } ) { <> - - - - - - - { ! codes.length && ( -

- Generating backup codes... - -

- ) } + const hasCodes = !! codes.length; - { codes.length > 0 && ( -
    - { codes.map( ( code ) => { - return ( -
  1. - { code.slice( 0, 4 ) + ' ' + code.slice( 4 ) } -
  2. - ); - } ) } -
+ return ( + <> +
+ { hasCodes ? ( +
    + { codes.map( ( code ) => { + return ( +
  1. + { code.slice( 0, 4 ) + ' ' + code.slice( 4 ) } +
  2. + ); + } ) } +
+ ) : ( +

+ Generating backup codes... +

+ ) } +
+ { hasCodes && ( + + + + + ) } -
+ ); } +const IntroText = () => ( +

+ Backup codes let you access your account if your primary two-factor authentication method is + unavailable, like if your phone is lost or stolen. Each code can only be used once. +

+); + /** * Render the screen where users can manage Backup Codes. * * @param props - * @param props.setRegenerating + * @param props.setGenerating */ -function Manage( { setRegenerating } ) { +function Manage( { setGenerating } ) { const { - user: { backupCodesRemaining }, + user: { backupCodesEnabled, backupCodesRemaining }, } = useContext( GlobalContext ); return ( <>
-

- Backup codes let you access your account if your primary two-factor - authentication method is unavailable, like if your phone is lost or stolen. Each - code can only be used once. -

+ - { backupCodesRemaining > 5 && ( + { backupCodesEnabled && backupCodesRemaining > 5 && (

You have { backupCodesRemaining } backup codes remaining.

) } - { backupCodesRemaining <= 5 && ( + { backupCodesEnabled && backupCodesRemaining <= 5 && (
@@ -241,8 +236,10 @@ function Manage( { setRegenerating } ) { ) }
- ); diff --git a/settings/src/components/settings.js b/settings/src/components/settings.js index 5deb2bb9..41bff482 100644 --- a/settings/src/components/settings.js +++ b/settings/src/components/settings.js @@ -21,7 +21,11 @@ import { GlobalContext } from '../script'; * Render the correct component based on the URL. */ export default function Settings() { - const { backupCodesEnabled, navigateToScreen, screen } = useContext( GlobalContext ); + const { + user: { backupCodesEnabled }, + navigateToScreen, + screen, + } = useContext( GlobalContext ); // The index is the URL slug and the value is the React component. const components = {