-
Notifications
You must be signed in to change notification settings - Fork 2k
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 the authorization Step for the Application Passwords #96891
Merged
+466
−5
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f9ae282
Add the authorization Step for the Application Passwords
valterlorran a045d7b
Add the notice when the authorization is request and add the texts
valterlorran 5aacf80
Apply the style to the component
valterlorran 904a860
Added the submit logic for the new step
valterlorran fb0316c
Add the tests
valterlorran 228b6f3
Add the action to skip the error on storing the credentials
valterlorran e7c3fd6
Add the redirect to the fallback step
valterlorran 0349e4f
Fix the authorizationUrl parameter name
valterlorran 4a0deb8
Try fix the errors
valterlorran 93a7874
Fix tests
valterlorran f213398
Add the back button logic
valterlorran 0aa14a1
Fix the from param
valterlorran bff33e2
Fix design issues
valterlorran 0ce0f81
Fix button test
valterlorran e55dca2
We should encode the success_url to allow the source site to redirect…
valterlorran 8b8ca48
Fix the authorizationUrl parameter
valterlorran 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
58 changes: 58 additions & 0 deletions
58
...repository/site-migration-application-password-authorization/components/authorization.tsx
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,58 @@ | ||
import { NextButton } from '@automattic/onboarding'; | ||
import { check, Icon } from '@wordpress/icons'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
|
||
const AuthorizationBenefits = ( { benefits }: { benefits: string[] } ) => { | ||
return ( | ||
<div className="site-migration-application-password-authorization__benefits"> | ||
{ benefits.map( ( benefit, index ) => ( | ||
<div | ||
className="site-migration-application-password-authorization__benefits-item" | ||
key={ index } | ||
> | ||
<div className="site-migration-application-password-authorization__benefits-item-icon"> | ||
<Icon icon={ check } size={ 20 } /> | ||
</div> | ||
<span>{ benefit }</span> | ||
</div> | ||
) ) } | ||
</div> | ||
); | ||
}; | ||
|
||
interface AuthorizationProps { | ||
onShareCredentialsClick: () => void; | ||
onAuthorizationClick: () => void; | ||
} | ||
|
||
const Authorization = ( { onShareCredentialsClick, onAuthorizationClick }: AuthorizationProps ) => { | ||
const translate = useTranslate(); | ||
return ( | ||
<div className="site-migration-application-password-authorization__authorization"> | ||
<div> | ||
<NextButton onClick={ onAuthorizationClick }>{ translate( 'Authorize' ) }</NextButton> | ||
</div> | ||
<div> | ||
<button | ||
className="button navigation-link step-container__navigation-link has-underline is-borderless" | ||
type="button" | ||
onClick={ onShareCredentialsClick } | ||
> | ||
{ translate( 'Share credentials instead' ) } | ||
</button> | ||
</div> | ||
<div className="site-migration-application-password-authorization__benefits-container"> | ||
<h3>{ translate( "Here's what else you're getting" ) }</h3> | ||
<AuthorizationBenefits | ||
benefits={ [ | ||
translate( 'Uninterrupted service throughout the entire migration experience.' ), | ||
translate( 'Unmatched reliability with 99.999% uptime and unmetered traffic.' ), | ||
translate( 'Round-the-clock security monitoring and DDoS protection.' ), | ||
] } | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Authorization; |
35 changes: 35 additions & 0 deletions
35
...site-migration-application-password-authorization/hooks/use-store-application-password.ts
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,35 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import wpcomRequest from 'wpcom-proxy-request'; | ||
import { ApiError } from '../../site-migration-credentials/types'; | ||
|
||
interface StoreApplicationPasswordResponse { | ||
success: boolean; | ||
} | ||
|
||
interface StoreApplicationPasswordPayload { | ||
password: string; | ||
username: string; | ||
source: string; | ||
} | ||
|
||
const useStoreApplicationPassword = ( siteSlug: string ) => { | ||
return useMutation< StoreApplicationPasswordResponse, ApiError, StoreApplicationPasswordPayload >( | ||
{ | ||
mutationFn: ( { password, username, source } ) => { | ||
return wpcomRequest( { | ||
path: `sites/${ siteSlug }/automated-migration/application-passwords`, | ||
apiNamespace: 'wpcom/v2/', | ||
apiVersion: '2', | ||
method: 'POST', | ||
body: { | ||
password, | ||
username, | ||
from_url: source, | ||
}, | ||
} ); | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
export default useStoreApplicationPassword; |
144 changes: 144 additions & 0 deletions
144
...ow/internals/steps-repository/site-migration-application-password-authorization/index.tsx
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,144 @@ | ||
import { StepContainer } from '@automattic/onboarding'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { useEffect } from 'react'; | ||
import DocumentHead from 'calypso/components/data/document-head'; | ||
import FormattedHeader from 'calypso/components/formatted-header'; | ||
import { LoadingEllipsis } from 'calypso/components/loading-ellipsis'; | ||
import Notice from 'calypso/components/notice'; | ||
import { useQuery } from 'calypso/landing/stepper/hooks/use-query'; | ||
import { useSiteSlugParam } from 'calypso/landing/stepper/hooks/use-site-slug-param'; | ||
import { recordTracksEvent } from 'calypso/lib/analytics/tracks'; | ||
import Authorization from './components/authorization'; | ||
import useStoreApplicationPassword from './hooks/use-store-application-password'; | ||
import type { Step } from '../../types'; | ||
import './style.scss'; | ||
|
||
const SiteMigrationApplicationPasswordsAuthorization: Step = function ( { navigation } ) { | ||
const translate = useTranslate(); | ||
const siteSlug = useSiteSlugParam(); | ||
|
||
const source = useQuery().get( 'site_url' ) ?? ''; | ||
const authorizationUrl = useQuery().get( 'authorizationUrl' ) ?? undefined; | ||
const isAuthorizationRejected = useQuery().get( 'success' ) === 'false'; | ||
const applicationPassword = useQuery().get( 'password' ); | ||
const username = useQuery().get( 'user_login' ); | ||
const isAuthorizationSuccessful = !! ( applicationPassword && username ); | ||
const { | ||
mutate: storeApplicationPasswordMutation, | ||
isSuccess: isStoreApplicationPasswordSuccess, | ||
isError: isStoreApplicationPasswordError, | ||
isPending: isStoreApplicationPasswordPending, | ||
} = useStoreApplicationPassword( siteSlug as string ); | ||
const hasStoreApplicationPasswordResponse = | ||
isStoreApplicationPasswordSuccess || isStoreApplicationPasswordError; | ||
const isLoading = | ||
isAuthorizationSuccessful && | ||
( ! hasStoreApplicationPasswordResponse || isStoreApplicationPasswordPending ); | ||
|
||
useEffect( () => { | ||
if ( ! isAuthorizationSuccessful || ! siteSlug ) { | ||
return; | ||
} | ||
|
||
storeApplicationPasswordMutation( { | ||
password: applicationPassword, | ||
username, | ||
source, | ||
} ); | ||
}, [ isAuthorizationSuccessful, siteSlug, useStoreApplicationPassword ] ); | ||
|
||
useEffect( () => { | ||
if ( isStoreApplicationPasswordSuccess ) { | ||
navigation?.submit?.( { action: 'migration-started' } ); | ||
} | ||
}, [ isStoreApplicationPasswordSuccess, navigation ] ); | ||
|
||
const navigateToFallbackCredentials = () => { | ||
navigation?.submit?.( { action: 'fallback-credentials', authorizationUrl } ); | ||
}; | ||
|
||
const startAuthorization = () => { | ||
navigation?.submit?.( { action: 'authorization', authorizationUrl } ); | ||
}; | ||
|
||
const contactMe = () => { | ||
navigation?.submit?.( { action: 'contact-me' } ); | ||
}; | ||
|
||
let notice = undefined; | ||
if ( isStoreApplicationPasswordError ) { | ||
notice = ( | ||
<Notice status="is-error" showDismiss={ false }> | ||
{ translate( "We couldn't complete the authorization." ) } | ||
<button | ||
className="button navigation-link step-container__navigation-link has-underline is-borderless site-migration-application-password-authorization__contact-me-button" | ||
type="button" | ||
onClick={ contactMe } | ||
> | ||
{ translate( 'Please contact me.' ) } | ||
</button> | ||
</Notice> | ||
); | ||
} else if ( isAuthorizationRejected ) { | ||
notice = ( | ||
<Notice status="is-warning" showDismiss={ false }> | ||
{ translate( | ||
"We can't start your migration without your authorization. Please authorize WordPress.com in your WP Admin or share your credentials." | ||
) } | ||
</Notice> | ||
); | ||
} | ||
|
||
const sourceDomain = new URL( source ).host; | ||
|
||
// translators: %(sourceDomain)s is the source domain that is being migrated. | ||
const subHeaderText = translate( | ||
"We're ready to migrate %(sourceDomain)s to WordPress.com. To make sure everything goes smoothly, we need you to authorize us for access in your WordPress admin.", | ||
{ | ||
args: { | ||
sourceDomain, | ||
}, | ||
} | ||
); | ||
|
||
const formattedHeader = ! isLoading ? ( | ||
<FormattedHeader | ||
id="site-migration-credentials-header" | ||
headerText={ translate( 'Get ready for blazing fast speeds' ) } | ||
subHeaderAlign="center" | ||
subHeaderText={ subHeaderText } | ||
align="center" | ||
/> | ||
) : undefined; | ||
|
||
return ( | ||
<> | ||
<DocumentHead title={ translate( 'Get ready for blazing fast speeds' ) } /> | ||
<StepContainer | ||
stepName="site-migration-application-password-authorization" | ||
flowName="site-migration" | ||
goBack={ navigation?.goBack } | ||
goNext={ navigation?.submit } | ||
hideSkip | ||
isFullLayout | ||
notice={ notice } | ||
formattedHeader={ formattedHeader } | ||
stepContent={ | ||
! isLoading ? ( | ||
<Authorization | ||
onAuthorizationClick={ startAuthorization } | ||
onShareCredentialsClick={ navigateToFallbackCredentials } | ||
/> | ||
) : ( | ||
<div data-testid="loading-ellipsis"> | ||
<LoadingEllipsis /> | ||
</div> | ||
) | ||
} | ||
recordTracksEvent={ recordTracksEvent } | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default SiteMigrationApplicationPasswordsAuthorization; |
55 changes: 55 additions & 0 deletions
55
...w/internals/steps-repository/site-migration-application-password-authorization/style.scss
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,55 @@ | ||
@import "@wordpress/base-styles/breakpoints"; | ||
@import "@wordpress/base-styles/mixins"; | ||
|
||
.site-migration-application-password-authorization { | ||
.site-migration-application-password-authorization__authorization { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
align-items: center; | ||
} | ||
.site-migration-application-password-authorization__benefits-container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
align-items: center; | ||
h3 { | ||
font-size: $font-title-small; | ||
} | ||
} | ||
.site-migration-application-password-authorization__benefits { | ||
padding: 2em; | ||
background-color: var(--color-border-shadow); | ||
border-radius: 4px; | ||
width: 100%; | ||
@include break-small { | ||
width: 350px; | ||
} | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
} | ||
.site-migration-application-password-authorization__benefits-item { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 0.5em; | ||
font-size: $font-body-small; | ||
.site-migration-application-password-authorization__benefits-item-icon { | ||
width: 42px; | ||
height: 42px; | ||
background-color: var(--studio-wordpress-blue-10); | ||
border-radius: 4px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-shrink: 0; | ||
svg { | ||
fill: var(--studio-wordpress-blue-50); | ||
} | ||
} | ||
} | ||
.site-migration-application-password-authorization__contact-me-button { | ||
color: var(--color-text-inverted) !important; | ||
margin-left: 0.25em; | ||
} | ||
} |
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.
where this strings added to the string freeze PR we where using for having translations ready earliear?