Skip to content

Commit

Permalink
Linting and alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
dd32 committed Jul 4, 2024
1 parent 902f846 commit 414dbe4
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions settings/src/components/svn-password.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* WordPress dependencies
*/
import { Button, TextControl, Notice, Spinner } from '@wordpress/components';
import { useCallback, useContext, useState } from '@wordpress/element';
import { Button, Notice, Spinner } from '@wordpress/components';
import { useCallback, useContext } from '@wordpress/element';
import { Icon, check, copySmall } from '@wordpress/icons';

/**
Expand All @@ -17,43 +17,42 @@ export default function SVNPassword() {
const {
user: {
userRecord: {
record: { svn_password },
record: { svn_password: svnPassword },
edit,
save
},
isSaving,
},
setGlobalNotice
} = useContext( GlobalContext );

const handleGenerate = useCallback( async () => {
try {
await edit( { svn_password: 'regenerate' } );
await save();
} catch ( error ) {
let message = error.message;

console.log( error );
setGlobalNotice( error.message );
}
}, [] );
}, [ edit, save ] );

const handleCopy = useCallback( () => {
navigator.clipboard.writeText( svn_password );
alert( "Copied to clipboard" );
}, [ ] );
try {
navigator.clipboard.writeText( svnPassword );
setGlobalNotice( 'Copied to clipboard' );
} catch ( error ) {
setGlobalNotice( "Couldn't write to clipboard" );
}
}, [ svnPassword ] );

return (
<>
<p>
Your SVN password can be used to commit to WordPress.org SVN repositories, such as for a plugin or theme.
</p>
<p>
If you forget your SVN password, you can generate a new one here. Never share your SVN password with anyone.
</p>
<p>Your SVN password can be used to commit to WordPress.org SVN repositories, such as for a plugin or theme.</p>
<p>If you forget your SVN password, you can generate a new one here. Never share your SVN password with anyone.</p>

{ ( svn_password && 'string' == typeof svn_password ) && (
{ svnPassword && 'string' === typeof svnPassword && (
<Notice status="success" isDismissible={ true }>
<Icon icon={ check } />
New Password generated: <code>{ svn_password }</code>
New Password generated: <code>{ svnPassword }</code>
<Icon icon={ copySmall } onClick={ handleCopy } className="wporg-2fa__svn-copy-password" label="Copy to clipboard" />
</Notice>
) }
Expand All @@ -70,7 +69,7 @@ export default function SVNPassword() {
Requesting..
</>
) : (
svn_password ? 'Regenerate password' : 'Request password'
svnPassword ? 'Regenerate password' : 'Request password'
) }
</Button>
</p>
Expand Down

0 comments on commit 414dbe4

Please sign in to comment.