-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathscreen-link.js
More file actions
50 lines (42 loc) · 1.3 KB
/
screen-link.js
File metadata and controls
50 lines (42 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* WordPress dependencies
*/
import { useCallback, useContext } from '@wordpress/element';
/**
* Internal dependencies
*/
import { GlobalContext } from '../script';
export default function ScreenLink( { screen, anchorText, buttonStyle = false, ariaLabel } ) {
const { navigateToScreen, setBackupCodesVerified } = useContext( GlobalContext );
const classes = [];
const screenUrl = new URL( document.location.href );
screenUrl.searchParams.set( 'screen', screen );
if ( 'primary' === buttonStyle ) {
classes.push( 'components-button' );
classes.push( 'is-primary' );
} else if ( 'secondary' === buttonStyle ) {
classes.push( 'components-button' );
classes.push( 'is-secondary' );
}
const onClick = useCallback(
( event ) => {
event.preventDefault();
// When generating Backup Codes, they're automatically saved to the database, so clicking `Back` is
// implicitly verifying them, or at least needs to be treated that way. This should be removed once
// `two-factor/#507` is fixed, though.
setBackupCodesVerified( true );
navigateToScreen( screen );
},
[ navigateToScreen, screen, setBackupCodesVerified ]
);
return (
<a
href={ screenUrl.href }
onClick={ onClick }
className={ classes.join( ' ' ) }
aria-label={ ariaLabel }
>
{ anchorText }
</a>
);
}