Skip to content

Commit

Permalink
Stop rendering code actions before codes are available
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwoodnz committed Aug 28, 2024
1 parent 9a5049f commit 985f7a5
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions settings/src/components/backup-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ function Setup( { setGenerating, onSuccess } ) {
<>
<CodeList codes={ backupCodes } />

<ButtonGroup>
<CopyToClipboardButton codes={ backupCodes } />
<PrintButton />
<DownloadButton codes={ backupCodes } />
</ButtonGroup>

<CheckboxControl
label="I have printed or saved these codes"
checked={ hasPrinted }
Expand All @@ -162,33 +156,41 @@ function Setup( { setGenerating, onSuccess } ) {
}

/**
* Display a list of backup codes
* Display a list of backup codes and actions
*
* @param props
* @param props.codes
*/
function CodeList( { codes } ) {
return (
<div className="wporg-2fa__backup-codes-list">
{ ! codes.length && (
<p>
Generating backup codes...
<Spinner />
</p>
) }
const hasCodes = !! codes.length;

{ codes.length > 0 && (
<ol>
{ codes.map( ( code ) => {
return (
<li key={ code } className="wporg-2fa__token">
{ code.slice( 0, 4 ) + ' ' + code.slice( 4 ) }
</li>
);
} ) }
</ol>
return (
<>
<div className="wporg-2fa__backup-codes-list">
{ hasCodes ? (
<ol>
{ codes.map( ( code ) => {
return (
<li key={ code } className="wporg-2fa__token">
{ code.slice( 0, 4 ) + ' ' + code.slice( 4 ) }
</li>
);
} ) }
</ol>
) : (
<p>
<Spinner /> Generating backup codes...
</p>
) }
</div>
{ hasCodes && (
<ButtonGroup>
<CopyToClipboardButton codes={ codes } />
<PrintButton />
<DownloadButton codes={ codes } />
</ButtonGroup>
) }
</div>
</>
);
}

Expand Down

0 comments on commit 985f7a5

Please sign in to comment.