-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a wizard component for first time configurations. #286
Closed
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f01a233
Try a setup wizard.
StevenDufresne 8a4f4a4
More changes.
StevenDufresne c507d19
More changes
StevenDufresne 2e1b1f4
Fix the linter.
StevenDufresne 3f09cda
Clean up
StevenDufresne 29290b1
Update account-status to be 'home'.
StevenDufresne 5f4f8af
Add back empty line.
StevenDufresne 5726e0c
Update copy.
StevenDufresne c5ebb5b
Add redirect logic.
StevenDufresne fc49452
Fix spacing.
StevenDufresne 094a3ec
Improve css.
StevenDufresne 1d3f9a2
Font show if they have a primary.
StevenDufresne a266649
We can't check via the component because it reloads.
StevenDufresne fbb0e53
Remove eslint disable line.
StevenDufresne 0089358
Remove empty line.
StevenDufresne eecec3d
Clean up formatting.
StevenDufresne 8461a28
Revert "Clean up formatting."
StevenDufresne fbd10e5
clean up formatting.
StevenDufresne 2429c3e
Lowercase setup radial.
StevenDufresne f1440bc
Trap the keyboard focus within the window.
StevenDufresne f4d60c3
Update the padding-top for the wizard.
StevenDufresne d8125e3
Update the component name.
StevenDufresne b373122
Update settings/src/components/first-time/first-time.js
StevenDufresne ab6acb2
Prefer keys as the first option.
StevenDufresne ecbd3d3
Move progress indicator about window.
StevenDufresne 4f60760
Default to 2fa view.
StevenDufresne 730ee19
move the progress component.
StevenDufresne d4483d5
Update selected radial to be webauthn.
StevenDufresne dcde527
Fix react error with map key.
StevenDufresne 221f181
Update radio list styles.
StevenDufresne 52daa65
Update progress bar and titles.
StevenDufresne 82d7913
Move congratulations to its own component.
StevenDufresne 142b57d
Remove unsued button.
StevenDufresne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button } from '@wordpress/components'; | ||
|
||
/** | ||
* Check if the URL is valid. Make sure it stays on wordpress.org. | ||
* | ||
* @param url | ||
* @return {boolean} Whether it's a valid URL. | ||
*/ | ||
const isValidUrl = ( url ) => { | ||
try { | ||
const { hostname } = new URL( url ); | ||
return hostname.endsWith( 'wordpress.org' ); | ||
} catch ( exception ) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default function Congratulations() { | ||
return ( | ||
<> | ||
<p> | ||
To ensure the highest level of security for your account, please remember to keep | ||
your authentication methods up-to-date. We recommend configuring multiple | ||
authentication methods to guarantee you always have access to your account. | ||
</p> | ||
<div className="wporg-2fa__submit-actions"> | ||
<Button | ||
onClick={ () => { | ||
const redirectTo = new URLSearchParams( window.location.search ).get( | ||
'redirect_to' | ||
); | ||
|
||
if ( redirectTo && isValidUrl( redirectTo ) ) { | ||
window.location.href = redirectTo; | ||
} else { | ||
window.location.href = | ||
'//profiles.wordpress.org/me/profile/edit/group/3'; | ||
} | ||
} } | ||
isPrimary | ||
> | ||
Continue | ||
</Button> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect, useContext, useRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ScreenNavigation from '../screen-navigation'; | ||
import TOTP from '../totp'; | ||
import WebAuthn from '../webauthn/webauthn'; | ||
import BackupCodes from '../backup-codes'; | ||
import SetupProgressBar from './setup-progress-bar'; | ||
import Home from './home'; | ||
import Congratulations from './congratulations'; | ||
import WordPressLogo from './wordpress-logo'; | ||
import { GlobalContext } from '../../script'; | ||
|
||
/** | ||
* Render the correct component based on the URL. | ||
*/ | ||
export default function FirstTime() { | ||
const modalRef = useRef( null ); | ||
const { navigateToScreen, screen } = useContext( GlobalContext ); | ||
|
||
// The index is the URL slug and the value is the React component. | ||
const screens = { | ||
home: { | ||
stepIndex: 0, | ||
title: 'Set up two-factor authentication', | ||
component: ( | ||
<Home | ||
onSelect={ ( val ) => { | ||
navigateToScreen( val ); | ||
} } | ||
/> | ||
), | ||
}, | ||
totp: { | ||
stepIndex: 1, | ||
title: 'Set up one-time password', | ||
component: ( | ||
<TOTP | ||
onSuccess={ () => { | ||
navigateToScreen( 'backup-codes' ); | ||
} } | ||
/> | ||
), | ||
}, | ||
webauthn: { | ||
stepIndex: 1, | ||
title: 'Set up security key', | ||
component: ( | ||
<WebAuthn | ||
onKeyAdd={ () => { | ||
navigateToScreen( 'backup-codes' ); | ||
} } | ||
/> | ||
), | ||
}, | ||
'backup-codes': { | ||
stepIndex: 2, | ||
title: 'Print backup codes', | ||
component: ( | ||
<BackupCodes | ||
onSuccess={ () => { | ||
navigateToScreen( 'congratulations' ); | ||
} } | ||
/> | ||
), | ||
}, | ||
congratulations: { | ||
stepIndex: 3, | ||
component: <Congratulations />, | ||
}, | ||
}; | ||
|
||
// Lock the scroll when the modal is open, and trap tab navigation. | ||
useEffect( () => { | ||
const modal = modalRef.current; | ||
const focusableElements = modal.querySelectorAll( | ||
'a, button, input, textarea, select, [tabindex]:not([tabindex="-1"])' | ||
); | ||
const firstFocusableElement = focusableElements[ 0 ]; | ||
const lastFocusableElement = focusableElements[ focusableElements.length - 1 ]; | ||
|
||
const trapFocus = ( event ) => { | ||
const isTabPressed = event.key === 'Tab' || event.keyCode === 9; | ||
if ( ! isTabPressed ) { | ||
return; | ||
} | ||
|
||
if ( event.shiftKey ) { | ||
// eslint-disable-next-line @wordpress/no-global-active-element | ||
if ( document.activeElement === firstFocusableElement ) { | ||
lastFocusableElement.focus(); | ||
event.preventDefault(); | ||
} | ||
return; | ||
} | ||
|
||
// eslint-disable-next-line @wordpress/no-global-active-element | ||
if ( document.activeElement === lastFocusableElement ) { | ||
firstFocusableElement.focus(); | ||
event.preventDefault(); | ||
} | ||
}; | ||
|
||
modal.addEventListener( 'keydown', trapFocus ); | ||
|
||
document.querySelector( 'html' ).style.overflow = 'hidden'; | ||
|
||
// Focus the first focusable element in the modal when it opens | ||
firstFocusableElement.focus(); | ||
|
||
return () => { | ||
modal.removeEventListener( 'keydown', trapFocus ); | ||
document.querySelector( 'html' ).style.overflow = 'initial'; | ||
}; | ||
}, [ screen ] ); | ||
|
||
const currentStepIndex = screens[ screen ].stepIndex; | ||
let currentScreenComponent = null; | ||
|
||
if ( 'congratulations' === screen ) { | ||
currentScreenComponent = ( | ||
<ScreenNavigation screen={ screen } title={ 'Setup complete' } canNavigate={ false }> | ||
{ screens[ screen ].component } | ||
</ScreenNavigation> | ||
); | ||
} else { | ||
currentScreenComponent = ( | ||
<> | ||
<SetupProgressBar currentStepIndex={ currentStepIndex } stepCount={ 3 } /> | ||
<ScreenNavigation | ||
screen={ screen } | ||
title={ screens[ screen ].title } | ||
canNavigate={ currentStepIndex !== 0 } | ||
> | ||
{ screens[ screen ].component } | ||
</ScreenNavigation> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="wporg-2fa__first-time" ref={ modalRef }> | ||
<div className="wporg-2fa__first-time__inner"> | ||
<div className="wporg-2fa__first-time__inner-content"> | ||
<WordPressLogo /> | ||
{ currentScreenComponent } | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
.wporg-2fa__first-time { | ||
position: fixed; | ||
background: #fff; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
z-index: 1000; | ||
|
||
.wporg-2fa__first-time__inner { | ||
box-sizing: border-box; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
width: 100%; | ||
height: 100%; | ||
overflow: scroll; | ||
} | ||
|
||
.wporg-2fa__first-time__inner-content { | ||
padding: 8vh 16px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
|
||
@media (min-width: 600px) { | ||
width: 600px; | ||
} | ||
|
||
> svg { | ||
margin-bottom: 32px; | ||
width: 250px; | ||
} | ||
|
||
// Preven cards from shrinking. | ||
.components-card { | ||
width: 100%; | ||
} | ||
|
||
.components-card__body { | ||
padding: 32px; | ||
padding-top: 16px; | ||
} | ||
} | ||
|
||
.wporg-2fa__first-time-default { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 18px; | ||
padding-top: 8px; | ||
} | ||
|
||
.wporg-2fa__first-time-default-item { | ||
margin: 0; | ||
position: relative; | ||
display: flex; | ||
gap: 10px; | ||
align-items: flex-start; | ||
cursor: pointer; | ||
|
||
span { | ||
font-weight: 600; | ||
z-index: 1; | ||
} | ||
|
||
input { | ||
position: relative; | ||
z-index: 1; | ||
margin-top: 4px; | ||
margin-left: 6px; | ||
} | ||
|
||
> div { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
|
||
p { | ||
color: var(--wp--preset--color--charcoal-4, #656a71); | ||
margin: 0; | ||
z-index: 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.wporg-2fa__congratulations h3 { | ||
margin-bottom: 14px; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do with a check here for the screen existing. Between switching from prod to sandbox I ended up on
?first-time=true&screen=account-status
, resulting in an error. Shouldn't be possible normally of course but it highlighted an edge case.