|
|
import config from '@automattic/calypso-config'; |
|
|
import { |
|
|
isDomainRegistration, |
|
|
isDomainTransfer, |
|
|
isDomainMapping, |
|
|
isPlan, |
|
|
} from '@automattic/calypso-products'; |
|
|
import page from '@automattic/calypso-router'; |
|
|
import { GravatarTextLogo } from '@automattic/components'; |
|
|
import { isBlankCanvasDesign } from '@automattic/design-picker'; |
|
|
import { camelToSnakeCase } from '@automattic/js-utils'; |
|
|
import * as oauthToken from '@automattic/oauth-token'; |
|
|
import { isDomainForGravatarFlow } from '@automattic/onboarding'; |
|
|
import debugModule from 'debug'; |
|
|
import { |
|
|
clone, |
|
|
defer, |
|
|
find, |
|
|
get, |
|
|
includes, |
|
|
isEmpty, |
|
|
isEqual, |
|
|
kebabCase, |
|
|
map, |
|
|
omit, |
|
|
startsWith, |
|
|
} from 'lodash'; |
|
|
import PropTypes from 'prop-types'; |
|
|
import { Component } from 'react'; |
|
|
import { connect } from 'react-redux'; |
|
|
import DocumentHead from 'calypso/components/data/document-head'; |
|
|
import QuerySiteDomains from 'calypso/components/data/query-site-domains'; |
|
|
import LocaleSuggestions from 'calypso/components/locale-suggestions'; |
|
|
import { startedInHostingFlow } from 'calypso/landing/stepper/utils/hosting-flow'; |
|
|
import { addHotJarScript } from 'calypso/lib/analytics/hotjar'; |
|
|
import { |
|
|
recordSignupStart, |
|
|
recordSignupComplete, |
|
|
recordSignupStep, |
|
|
recordSignupInvalidStep, |
|
|
recordSignupProcessingScreen, |
|
|
recordSignupPlanChange, |
|
|
SIGNUP_DOMAIN_ORIGIN, |
|
|
} from 'calypso/lib/analytics/signup'; |
|
|
import { |
|
|
isWooOAuth2Client, |
|
|
isGravatarOAuth2Client, |
|
|
isPartnerPortalOAuth2Client, |
|
|
} from 'calypso/lib/oauth2-clients'; |
|
|
import SignupFlowController from 'calypso/lib/signup/flow-controller'; |
|
|
import FlowProgressIndicator from 'calypso/signup/flow-progress-indicator'; |
|
|
import SignupHeader from 'calypso/signup/signup-header'; |
|
|
import { NON_PRIMARY_DOMAINS_TO_FREE_USERS } from 'calypso/state/current-user/constants'; |
|
|
import { |
|
|
isUserLoggedIn, |
|
|
getCurrentUser, |
|
|
currentUserHasFlag, |
|
|
getCurrentUserSiteCount, |
|
|
isCurrentUserEmailVerified, |
|
|
} from 'calypso/state/current-user/selectors'; |
|
|
import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selectors'; |
|
|
import getCurrentLocaleSlug from 'calypso/state/selectors/get-current-locale-slug'; |
|
|
import getWccomFrom from 'calypso/state/selectors/get-wccom-from'; |
|
|
import isDomainOnlySite from 'calypso/state/selectors/is-domain-only-site'; |
|
|
import { getSignupDependencyStore } from 'calypso/state/signup/dependency-store/selectors'; |
|
|
import { submitSignupStep, removeStep, addStep } from 'calypso/state/signup/progress/actions'; |
|
|
import { getSignupProgress } from 'calypso/state/signup/progress/selectors'; |
|
|
import { getDomainsBySiteId } from 'calypso/state/sites/domains/selectors'; |
|
|
import { |
|
|
getSiteId, |
|
|
isCurrentPlanPaid, |
|
|
getSitePlanSlug, |
|
|
getSitePlanName, |
|
|
} from 'calypso/state/sites/selectors'; |
|
|
import { getSelectedSiteId } from 'calypso/state/ui/selectors'; |
|
|
import flows from './config/flows'; |
|
|
import { getStepComponent } from './config/step-components'; |
|
|
import steps from './config/steps'; |
|
|
import ProcessingScreen from './processing-screen'; |
|
|
import { |
|
|
persistSignupDestination, |
|
|
setDomainsDependencies, |
|
|
clearDomainsDependencies, |
|
|
setSignupCompleteSlug, |
|
|
getSignupCompleteSlug, |
|
|
setSignupCompleteFlowName, |
|
|
} from './storageUtils'; |
|
|
import { |
|
|
canResumeFlow, |
|
|
getCompletedSteps, |
|
|
getDestination, |
|
|
getFirstInvalidStep, |
|
|
getStepUrl, |
|
|
} from './utils'; |
|
|
import WpcomLoginForm from './wpcom-login-form'; |
|
|
|
|
|
import './style.scss'; |
|
|
|
|
|
const debug = debugModule( 'calypso:signup' ); |
|
|
|
|
|
function dependenciesContainCartItem( dependencies ) { |
|
|
|
|
|
|
|
|
return !! ( |
|
|
dependencies && |
|
|
( dependencies.cartItem || dependencies.domainItem || dependencies.cartItems ) |
|
|
); |
|
|
} |
|
|
|
|
|
function showProgressIndicator( flowName ) { |
|
|
const flow = flows.getFlow( flowName ); |
|
|
return ! flow.hideProgressIndicator; |
|
|
} |
|
|
|
|
|
class Signup extends Component { |
|
|
static propTypes = { |
|
|
store: PropTypes.object.isRequired, |
|
|
domainsWithPlansOnly: PropTypes.bool, |
|
|
isLoggedIn: PropTypes.bool, |
|
|
isEmailVerified: PropTypes.bool, |
|
|
submitSignupStep: PropTypes.func.isRequired, |
|
|
signupDependencies: PropTypes.object, |
|
|
siteDomains: PropTypes.array, |
|
|
sitePlanName: PropTypes.string, |
|
|
sitePlanSlug: PropTypes.string, |
|
|
isPaidPlan: PropTypes.bool, |
|
|
flowName: PropTypes.string, |
|
|
stepName: PropTypes.string, |
|
|
pageTitle: PropTypes.string, |
|
|
stepSectionName: PropTypes.string, |
|
|
hostingFlow: PropTypes.bool.isRequired, |
|
|
}; |
|
|
|
|
|
state = { |
|
|
controllerHasReset: false, |
|
|
shouldShowLoadingScreen: false, |
|
|
resumingStep: undefined, |
|
|
previousFlowName: null, |
|
|
}; |
|
|
|
|
|
|
|
|
UNSAFE_componentWillMount() { |
|
|
let providedDependencies = this.getDependenciesInQuery(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( this.props.isManageSiteFlow ) { |
|
|
providedDependencies = { |
|
|
...providedDependencies, |
|
|
siteSlug: getSignupCompleteSlug(), |
|
|
isManageSiteFlow: this.props.isManageSiteFlow, |
|
|
}; |
|
|
} |
|
|
|
|
|
this.signupFlowController = new SignupFlowController( { |
|
|
flowName: this.props.flowName, |
|
|
providedDependencies, |
|
|
reduxStore: this.props.store, |
|
|
onComplete: this.handleSignupFlowControllerCompletion, |
|
|
} ); |
|
|
|
|
|
this.removeFulfilledSteps( this.props ); |
|
|
|
|
|
this.updateShouldShowLoadingScreen(); |
|
|
this.completeFlowAfterLoggingIn(); |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
canResumeFlow( this.props.flowName, this.props.progress, this.props.isLoggedIn ) && |
|
|
! this.isCurrentStepRemovedFromFlow() |
|
|
) { |
|
|
return; |
|
|
} |
|
|
|
|
|
if ( this.getPositionInFlow() !== 0 ) { |
|
|
|
|
|
|
|
|
const destinationStep = flows.getFlow( this.props.flowName, this.props.isLoggedIn ) |
|
|
.steps[ 0 ]; |
|
|
this.setState( { resumingStep: destinationStep } ); |
|
|
const locale = ! this.props.isLoggedIn ? this.props.locale : ''; |
|
|
return page.redirect( |
|
|
getStepUrl( |
|
|
this.props.flowName, |
|
|
destinationStep, |
|
|
undefined, |
|
|
locale, |
|
|
this.getCurrentFlowSupportedQueryParams() |
|
|
) |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
UNSAFE_componentWillReceiveProps( nextProps ) { |
|
|
const { stepName, flowName, progress } = nextProps; |
|
|
|
|
|
if ( this.props.stepName !== stepName ) { |
|
|
this.removeFulfilledSteps( nextProps ); |
|
|
} |
|
|
|
|
|
if ( stepName === this.state.resumingStep ) { |
|
|
this.setState( { resumingStep: undefined } ); |
|
|
} |
|
|
|
|
|
if ( this.props.flowName !== flowName ) { |
|
|
this.signupFlowController.changeFlowName( flowName ); |
|
|
} |
|
|
|
|
|
if ( ! this.state.controllerHasReset && ! isEqual( this.props.progress, progress ) ) { |
|
|
this.updateShouldShowLoadingScreen( progress ); |
|
|
} |
|
|
} |
|
|
|
|
|
componentWillUnmount() { |
|
|
this.signupFlowController.cleanup(); |
|
|
} |
|
|
|
|
|
componentDidMount() { |
|
|
debug( 'Signup component mounted' ); |
|
|
|
|
|
if ( flows.getFlow( this.props.flowName, this.props.isLoggedIn )?.enableHotjar ) { |
|
|
addHotJarScript(); |
|
|
} |
|
|
|
|
|
recordSignupStart( this.props.flowName, this.props.refParameter, this.getRecordProps() ); |
|
|
|
|
|
|
|
|
if ( ! this.state.shouldShowLoadingScreen ) { |
|
|
recordSignupStep( |
|
|
this.props.flowName, |
|
|
this.props.stepName === 'user-social' ? 'user' : this.props.stepName, |
|
|
this.getRecordProps() |
|
|
); |
|
|
} |
|
|
this.preloadNextStep(); |
|
|
} |
|
|
|
|
|
componentDidUpdate( prevProps ) { |
|
|
const { flowName, stepName, sitePlanName, sitePlanSlug, signupDependencies, siteDomains } = |
|
|
this.props; |
|
|
|
|
|
if ( |
|
|
( flowName !== prevProps.flowName || stepName !== prevProps.stepName ) && |
|
|
! this.state.shouldShowLoadingScreen |
|
|
) { |
|
|
|
|
|
recordSignupStep( |
|
|
flowName, |
|
|
stepName === 'user-social' ? 'user' : stepName, |
|
|
this.getRecordProps() |
|
|
); |
|
|
} |
|
|
|
|
|
if ( stepName !== prevProps.stepName ) { |
|
|
this.preloadNextStep(); |
|
|
|
|
|
this.scrollToTop(); |
|
|
} |
|
|
|
|
|
if ( sitePlanSlug && prevProps.sitePlanSlug && sitePlanSlug !== prevProps.sitePlanSlug ) { |
|
|
recordSignupPlanChange( |
|
|
flowName, |
|
|
stepName === 'user-social' ? 'user' : stepName, |
|
|
prevProps.sitePlanName, |
|
|
prevProps.sitePlanSlug, |
|
|
sitePlanName, |
|
|
sitePlanSlug |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
if ( |
|
|
stepName === 'domains' && |
|
|
signupDependencies.domainItem !== prevProps.signupDependencies.domainItem |
|
|
) { |
|
|
clearDomainsDependencies(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( flowName === 'launch-site' && siteDomains !== prevProps.siteDomains ) { |
|
|
this.removeFulfilledSteps( this.props ); |
|
|
} |
|
|
} |
|
|
|
|
|
getRecordPropsFromFlow = () => { |
|
|
const requiredDeps = this.getCurrentFlowSupportedQueryParams(); |
|
|
|
|
|
const flow = flows.getFlow( this.props.flowName, this.props.isLoggedIn ); |
|
|
const optionalDependenciesInQuery = flow?.optionalDependenciesInQuery ?? []; |
|
|
const optionalDeps = this.extractFlowDependenciesFromQuery( optionalDependenciesInQuery ); |
|
|
|
|
|
const deps = { ...requiredDeps, ...optionalDeps }; |
|
|
|
|
|
const snakeCaseDeps = {}; |
|
|
|
|
|
for ( const depsKey in deps ) { |
|
|
snakeCaseDeps[ camelToSnakeCase( depsKey ) ] = deps[ depsKey ]; |
|
|
} |
|
|
|
|
|
return snakeCaseDeps; |
|
|
}; |
|
|
|
|
|
getRecordProps() { |
|
|
const { signupDependencies, hostingFlow, queryObject, wccomFrom, oauth2Client } = this.props; |
|
|
const mainFlow = queryObject?.main_flow; |
|
|
|
|
|
let theme = get( signupDependencies, 'selectedDesign.theme' ); |
|
|
|
|
|
if ( ! theme && signupDependencies.themeParameter ) { |
|
|
theme = signupDependencies.themeParameter; |
|
|
} |
|
|
|
|
|
const deps = this.getRecordPropsFromFlow(); |
|
|
|
|
|
return { |
|
|
...deps, |
|
|
theme, |
|
|
intent: get( signupDependencies, 'intent' ), |
|
|
starting_point: get( signupDependencies, 'startingPoint' ), |
|
|
is_in_hosting_flow: hostingFlow, |
|
|
wccom_from: wccomFrom, |
|
|
oauth2_client_id: oauth2Client?.id, |
|
|
...( mainFlow ? { flow: mainFlow } : {} ), |
|
|
}; |
|
|
} |
|
|
|
|
|
scrollToTop() { |
|
|
setTimeout( () => window.scrollTo( 0, 0 ), 0 ); |
|
|
} |
|
|
|
|
|
completeFlowAfterLoggingIn() { |
|
|
const flowName = this.props.flowName; |
|
|
|
|
|
const eligbleFlows = [ 'domain' ]; |
|
|
if ( ! eligbleFlows.includes( flowName ) || ! this.props.progress ) { |
|
|
return; |
|
|
} |
|
|
const stepName = this.props.stepName; |
|
|
|
|
|
const step = this.props.progress[ stepName ]; |
|
|
if ( step && step.status === 'pending' && this.props.isLoggedIn ) { |
|
|
|
|
|
|
|
|
this.props.removeStep( step ); |
|
|
this.props.addStep( step ); |
|
|
} |
|
|
} |
|
|
|
|
|
handlePostFlowCallbacks = async ( dependencies ) => { |
|
|
const flow = flows.getFlow( this.props.flowName, this.props.isLoggedIn ); |
|
|
|
|
|
if ( flow.postCompleteCallback ) { |
|
|
const siteId = dependencies && dependencies.siteId; |
|
|
await flow.postCompleteCallback( { siteId, flowName: this.props.flowName } ); |
|
|
} |
|
|
}; |
|
|
|
|
|
handleSignupFlowControllerCompletion = async ( dependencies, destination ) => { |
|
|
const filteredDestination = getDestination( |
|
|
destination, |
|
|
dependencies, |
|
|
this.props.flowName, |
|
|
this.props.localeSlug |
|
|
); |
|
|
|
|
|
|
|
|
if ( destination !== filteredDestination ) { |
|
|
persistSignupDestination( destination ); |
|
|
setSignupCompleteSlug( dependencies.siteSlug ); |
|
|
setSignupCompleteFlowName( this.props.flowName ); |
|
|
} |
|
|
|
|
|
|
|
|
if ( this.props.flowName === 'onboarding' ) { |
|
|
const { domainItem, siteUrl, domainCart } = dependencies; |
|
|
const { stepSectionName } = this.props; |
|
|
|
|
|
setDomainsDependencies( { |
|
|
step: { |
|
|
stepName: 'domains', |
|
|
domainItem, |
|
|
siteUrl, |
|
|
isPurchasingItem: true, |
|
|
stepSectionName, |
|
|
domainCart, |
|
|
}, |
|
|
dependencies: { domainItem, siteUrl, domainCart }, |
|
|
} ); |
|
|
} |
|
|
|
|
|
this.handleFlowComplete( dependencies, filteredDestination ); |
|
|
|
|
|
this.handleLogin( dependencies, filteredDestination ); |
|
|
|
|
|
await this.handlePostFlowCallbacks( dependencies ); |
|
|
|
|
|
this.handleDestination( dependencies, filteredDestination, this.props.flowName ); |
|
|
}; |
|
|
|
|
|
updateShouldShowLoadingScreen = ( progress = this.props.progress ) => { |
|
|
if ( |
|
|
isWooOAuth2Client( this.props.oauth2Client ) || |
|
|
this.props.isGravatar || |
|
|
isPartnerPortalOAuth2Client( this.props.oauth2Client ) |
|
|
) { |
|
|
|
|
|
return; |
|
|
} |
|
|
|
|
|
const hasInvalidSteps = !! getFirstInvalidStep( |
|
|
this.props.flowName, |
|
|
progress, |
|
|
this.props.isLoggedIn |
|
|
); |
|
|
const waitingForServer = ! hasInvalidSteps && this.isEveryStepSubmitted( progress ); |
|
|
const startLoadingScreen = waitingForServer && ! this.state.shouldShowLoadingScreen; |
|
|
|
|
|
if ( ! this.isEveryStepSubmitted( progress ) ) { |
|
|
this.goToFirstInvalidStep( progress ); |
|
|
} |
|
|
|
|
|
if ( startLoadingScreen ) { |
|
|
recordSignupProcessingScreen( |
|
|
this.props.flowName, |
|
|
this.props.stepName, |
|
|
this.getRecordProps() |
|
|
); |
|
|
|
|
|
this.setState( { shouldShowLoadingScreen: true } ); |
|
|
} |
|
|
|
|
|
if ( hasInvalidSteps ) { |
|
|
this.setState( { shouldShowLoadingScreen: false } ); |
|
|
} |
|
|
}; |
|
|
|
|
|
processFulfilledSteps = ( stepName, nextProps ) => { |
|
|
const isFulfilledCallback = steps[ stepName ].fulfilledStepCallback; |
|
|
const defaultDependencies = steps[ stepName ].defaultDependencies; |
|
|
isFulfilledCallback && isFulfilledCallback( stepName, defaultDependencies, nextProps ); |
|
|
}; |
|
|
|
|
|
removeFulfilledSteps = ( nextProps ) => { |
|
|
const { flowName, isLoggedIn, stepName } = nextProps; |
|
|
const flowSteps = flows.getFlow( flowName, isLoggedIn ).steps; |
|
|
const excludedSteps = clone( flows.excludedSteps ); |
|
|
map( excludedSteps, ( flowStepName ) => this.processFulfilledSteps( flowStepName, nextProps ) ); |
|
|
map( flowSteps, ( flowStepName ) => this.processFulfilledSteps( flowStepName, nextProps ) ); |
|
|
|
|
|
if ( includes( flows.excludedSteps, stepName ) ) { |
|
|
this.goToNextStep( flowName ); |
|
|
} |
|
|
}; |
|
|
|
|
|
preloadNextStep() { |
|
|
const currentStepName = this.props.stepName; |
|
|
const nextStepName = flows.getNextStepNameInFlow( this.props.flowName, currentStepName ); |
|
|
|
|
|
nextStepName && getStepComponent( nextStepName ); |
|
|
} |
|
|
|
|
|
handleFlowComplete = ( dependencies, destination ) => { |
|
|
debug( 'The flow is completed. Destination: %s', destination ); |
|
|
|
|
|
const { existingSiteCount } = this.props; |
|
|
|
|
|
const isNewUser = !! ( dependencies && dependencies.is_new_account ); |
|
|
const siteId = dependencies && dependencies.siteId; |
|
|
const hasCartItems = dependenciesContainCartItem( dependencies ); |
|
|
|
|
|
|
|
|
const cartItem = get( dependencies, 'cartItem' ); |
|
|
const cartItems = get( dependencies, 'cartItems' ); |
|
|
const domainItem = get( dependencies, 'domainItem' ); |
|
|
const selectedDesign = get( dependencies, 'selectedDesign' ); |
|
|
const intent = get( dependencies, 'intent' ); |
|
|
const startingPoint = get( dependencies, 'startingPoint' ); |
|
|
const signupDomainOrigin = get( dependencies, 'signupDomainOrigin' ); |
|
|
const planProductSlug = cartItems?.length |
|
|
? cartItems.find( ( item ) => isPlan( item ) )?.product_slug |
|
|
: cartItem?.product_slug; |
|
|
|
|
|
const debugProps = { |
|
|
existingSiteCount, |
|
|
isNewUser, |
|
|
hasCartItems, |
|
|
flow: this.props.flowName, |
|
|
siteId, |
|
|
theme: selectedDesign?.theme, |
|
|
intent, |
|
|
startingPoint, |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( ! dependencies.toStepper ) { |
|
|
debug( 'Tracking signup completion.', debugProps ); |
|
|
const isMapping = domainItem && isDomainMapping( domainItem ); |
|
|
const isTransfer = domainItem && isDomainTransfer( domainItem ); |
|
|
const signupDomainOriginValue = |
|
|
isTransfer || isMapping |
|
|
? SIGNUP_DOMAIN_ORIGIN.USE_YOUR_DOMAIN |
|
|
: signupDomainOrigin ?? SIGNUP_DOMAIN_ORIGIN.NOT_SET; |
|
|
|
|
|
recordSignupComplete( { |
|
|
flow: this.props.flowName, |
|
|
siteId, |
|
|
isNewUser, |
|
|
hasCartItems, |
|
|
planProductSlug, |
|
|
domainProductSlug: |
|
|
undefined !== domainItem && domainItem.is_domain_registration |
|
|
? domainItem.product_slug |
|
|
: undefined, |
|
|
|
|
|
theme: selectedDesign?.theme, |
|
|
intent, |
|
|
startingPoint, |
|
|
isBlankCanvas: isBlankCanvasDesign( dependencies.selectedDesign ), |
|
|
isMapping: isMapping, |
|
|
isTransfer: isTransfer, |
|
|
signupDomainOrigin: signupDomainOriginValue, |
|
|
framework: 'start', |
|
|
} ); |
|
|
} |
|
|
}; |
|
|
|
|
|
handleDestination( dependencies, destination, flowName ) { |
|
|
if ( this.props.isLoggedIn ) { |
|
|
|
|
|
if ( /^https?:\/\//.test( destination ) ) { |
|
|
return ( window.location.href = destination ); |
|
|
} |
|
|
|
|
|
|
|
|
defer( () => { |
|
|
debug( `Redirecting you to "${ destination }"` ); |
|
|
|
|
|
if ( destination?.startsWith( '/checkout/' ) && 'website-design-services' === flowName ) { |
|
|
page( destination ); |
|
|
return; |
|
|
} |
|
|
window.location.href = destination; |
|
|
} ); |
|
|
|
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
if ( ! this.state.redirectTo ) { |
|
|
window.location.href = destination; |
|
|
} |
|
|
} |
|
|
|
|
|
handleLogin( dependencies, destination, resetSignupFlowController = true ) { |
|
|
const { isLoggedIn: userIsLoggedIn, progress } = this.props; |
|
|
|
|
|
debug( `Logging you in to "${ destination }"` ); |
|
|
if ( resetSignupFlowController ) { |
|
|
this.signupFlowController.reset(); |
|
|
|
|
|
if ( ! this.state.controllerHasReset ) { |
|
|
this.setState( { controllerHasReset: true } ); |
|
|
} |
|
|
} |
|
|
|
|
|
const isRegularOauth2ClientSignup = |
|
|
dependencies.oauth2_client_id && ! progress?.[ 'oauth2-user' ]?.service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( ! userIsLoggedIn && ( config.isEnabled( 'oauth' ) || isRegularOauth2ClientSignup ) ) { |
|
|
debug( `Handling oauth login` ); |
|
|
oauthToken.setToken( dependencies.bearer_token ); |
|
|
return; |
|
|
} |
|
|
|
|
|
if ( ! userIsLoggedIn && ! config.isEnabled( 'oauth' ) ) { |
|
|
debug( `Handling regular login` ); |
|
|
|
|
|
const { bearer_token: bearerToken, username } = dependencies; |
|
|
|
|
|
if ( |
|
|
isEmpty( bearerToken ) && |
|
|
isEmpty( username ) && |
|
|
'onboarding-registrationless' === this.props.flowName |
|
|
) { |
|
|
return; |
|
|
} |
|
|
|
|
|
if ( this.state.bearerToken !== bearerToken && this.state.username !== username ) { |
|
|
debug( 'Performing regular login' ); |
|
|
this.setState( { |
|
|
bearerToken: dependencies.bearer_token, |
|
|
username: dependencies.username, |
|
|
redirectTo: this.loginRedirectTo( destination ), |
|
|
} ); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
loginRedirectTo = ( path ) => { |
|
|
if ( startsWith( path, 'https://' ) || startsWith( path, 'http://' ) ) { |
|
|
return path; |
|
|
} |
|
|
|
|
|
return window.location.origin + path; |
|
|
}; |
|
|
|
|
|
extractFlowDependenciesFromQuery = ( dependencies ) => { |
|
|
const queryObject = this.props.initialContext?.query ?? {}; |
|
|
|
|
|
const result = {}; |
|
|
for ( const dependencyKey of dependencies ) { |
|
|
const value = queryObject[ dependencyKey ]; |
|
|
if ( value != null ) { |
|
|
result[ dependencyKey ] = value; |
|
|
} |
|
|
} |
|
|
|
|
|
return result; |
|
|
}; |
|
|
|
|
|
getDependenciesInQuery = () => { |
|
|
const flow = flows.getFlow( this.props.flowName, this.props.isLoggedIn ); |
|
|
const requiredDependenciesInQuery = flow?.providesDependenciesInQuery ?? []; |
|
|
|
|
|
return this.extractFlowDependenciesFromQuery( requiredDependenciesInQuery ); |
|
|
}; |
|
|
|
|
|
getCurrentFlowSupportedQueryParams = () => { |
|
|
const queryObject = this.props.initialContext?.query ?? {}; |
|
|
const dependenciesInQuery = this.getDependenciesInQuery( queryObject ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { siteId, siteSlug, flags } = queryObject; |
|
|
|
|
|
return { |
|
|
siteId, |
|
|
siteSlug, |
|
|
flags, |
|
|
...dependenciesInQuery, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
goToStep = ( stepName, stepSectionName, flowName = this.props.flowName ) => { |
|
|
|
|
|
|
|
|
|
|
|
if ( stepName && ! this.isEveryStepSubmitted() ) { |
|
|
const locale = ! this.props.isLoggedIn ? this.props.locale : ''; |
|
|
page( |
|
|
getStepUrl( |
|
|
flowName, |
|
|
stepName, |
|
|
stepSectionName, |
|
|
locale, |
|
|
this.getCurrentFlowSupportedQueryParams() |
|
|
) |
|
|
); |
|
|
} else if ( this.isEveryStepSubmitted() ) { |
|
|
this.goToFirstInvalidStep(); |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
goToNextStep = ( nextFlowName = this.props.flowName ) => { |
|
|
const { steps: flowSteps } = flows.getFlow( nextFlowName, this.props.isLoggedIn ); |
|
|
const currentStepIndex = flowSteps.indexOf( this.props.stepName ); |
|
|
const nextStepName = flowSteps[ currentStepIndex + 1 ]; |
|
|
const nextProgressItem = get( this.props.progress, nextStepName ); |
|
|
const nextStepSection = ( nextProgressItem && nextProgressItem.stepSectionName ) || ''; |
|
|
|
|
|
if ( nextFlowName !== this.props.flowName ) { |
|
|
this.setState( { previousFlowName: this.props.flowName } ); |
|
|
} |
|
|
|
|
|
this.goToStep( nextStepName, nextStepSection, nextFlowName ); |
|
|
}; |
|
|
|
|
|
goToFirstInvalidStep = ( progress = this.props.progress ) => { |
|
|
const firstInvalidStep = getFirstInvalidStep( |
|
|
this.props.flowName, |
|
|
progress, |
|
|
this.props.isLoggedIn |
|
|
); |
|
|
|
|
|
if ( firstInvalidStep ) { |
|
|
recordSignupInvalidStep( this.props.flowName, this.props.stepName ); |
|
|
|
|
|
if ( firstInvalidStep.stepName === this.props.stepName ) { |
|
|
|
|
|
debug( `Already navigated to the first invalid step: ${ firstInvalidStep.stepName }` ); |
|
|
return; |
|
|
} |
|
|
|
|
|
const locale = ! this.props.isLoggedIn ? this.props.locale : ''; |
|
|
debug( `Navigating to the first invalid step: ${ firstInvalidStep.stepName }` ); |
|
|
page( |
|
|
getStepUrl( |
|
|
this.props.flowName, |
|
|
firstInvalidStep.stepName, |
|
|
'', |
|
|
locale, |
|
|
this.getCurrentFlowSupportedQueryParams() |
|
|
) |
|
|
); |
|
|
} |
|
|
}; |
|
|
|
|
|
isEveryStepSubmitted = ( progress = this.props.progress ) => { |
|
|
const flowSteps = flows.getFlow( this.props.flowName, this.props.isLoggedIn ).steps; |
|
|
const completedSteps = getCompletedSteps( |
|
|
this.props.flowName, |
|
|
progress, |
|
|
{}, |
|
|
this.props.isLoggedIn |
|
|
); |
|
|
return flowSteps.length === completedSteps.length; |
|
|
}; |
|
|
|
|
|
getPositionInFlow() { |
|
|
const { flowName, stepName } = this.props; |
|
|
return flows.getFlow( flowName, this.props.isLoggedIn ).steps.indexOf( stepName ); |
|
|
} |
|
|
|
|
|
getInteractiveStepsCount() { |
|
|
const flowStepsSlugs = flows.getFlow( this.props.flowName, this.props.isLoggedIn ).steps; |
|
|
const flowSteps = flowStepsSlugs.filter( ( step ) => ! steps[ step ].props?.nonInteractive ); |
|
|
return flowSteps.length; |
|
|
} |
|
|
|
|
|
renderProcessingScreen() { |
|
|
const domainItem = get( this.props, 'signupDependencies.domainItem', {} ); |
|
|
const hasPaidDomain = isDomainRegistration( domainItem ); |
|
|
const destination = this.signupFlowController.getDestination(); |
|
|
|
|
|
return ( |
|
|
<ProcessingScreen |
|
|
flowName={ this.props.flowName } |
|
|
hasPaidDomain={ hasPaidDomain } |
|
|
isDestinationSetupSiteFlow={ destination.startsWith( '/setup' ) } |
|
|
/> |
|
|
); |
|
|
} |
|
|
|
|
|
renderCurrentStep() { |
|
|
const { stepName, flowName } = this.props; |
|
|
|
|
|
const flow = flows.getFlow( flowName, this.props.isLoggedIn ); |
|
|
const flowStepProps = flow?.props?.[ stepName ] || {}; |
|
|
|
|
|
const currentStepProgress = find( this.props.progress, { stepName } ); |
|
|
const CurrentComponent = this.props.stepComponent; |
|
|
const propsFromConfig = { |
|
|
...omit( this.props, 'locale' ), |
|
|
...steps[ stepName ].props, |
|
|
...flowStepProps, |
|
|
}; |
|
|
const stepKey = this.state.shouldShowLoadingScreen ? 'processing' : stepName; |
|
|
const shouldRenderLocaleSuggestions = 0 === this.getPositionInFlow() && ! this.props.isLoggedIn; |
|
|
|
|
|
let propsForCurrentStep = propsFromConfig; |
|
|
if ( this.props.isManageSiteFlow ) { |
|
|
propsForCurrentStep = { |
|
|
...propsFromConfig, |
|
|
showExampleSuggestions: false, |
|
|
showSkipButton: true, |
|
|
includeWordPressDotCom: false, |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hideFreePlan = this.props.signupDependencies.coupon ?? false; |
|
|
|
|
|
return ( |
|
|
<div className="signup__step" key={ stepKey }> |
|
|
<div className={ `signup__step is-${ stepName }` }> |
|
|
{ shouldRenderLocaleSuggestions && ( |
|
|
<LocaleSuggestions path={ this.props.path } locale={ this.props.locale } /> |
|
|
) } |
|
|
{ this.state.shouldShowLoadingScreen ? ( |
|
|
this.renderProcessingScreen() |
|
|
) : ( |
|
|
<CurrentComponent |
|
|
path={ this.props.path } |
|
|
step={ currentStepProgress } |
|
|
initialContext={ this.props.initialContext } |
|
|
steps={ flow.steps } |
|
|
stepName={ stepName } |
|
|
meta={ flow.meta || {} } |
|
|
goToNextStep={ this.goToNextStep } |
|
|
goToStep={ this.goToStep } |
|
|
previousFlowName={ this.state.previousFlowName } |
|
|
flowName={ flowName } |
|
|
signupDependencies={ this.props.signupDependencies } |
|
|
stepSectionName={ this.props.stepSectionName } |
|
|
positionInFlow={ this.getPositionInFlow() } |
|
|
hideFreePlan={ hideFreePlan } |
|
|
queryParams={ this.getCurrentFlowSupportedQueryParams() } |
|
|
{ ...propsForCurrentStep } |
|
|
/> |
|
|
) } |
|
|
</div> |
|
|
</div> |
|
|
); |
|
|
} |
|
|
|
|
|
isCurrentStepRemovedFromFlow() { |
|
|
return ! includes( |
|
|
flows.getFlow( this.props.flowName, this.props.isLoggedIn ).steps, |
|
|
this.props.stepName |
|
|
); |
|
|
} |
|
|
|
|
|
shouldWaitToRender() { |
|
|
const isStepRemovedFromFlow = this.isCurrentStepRemovedFromFlow(); |
|
|
const isDomainsForSiteEmpty = |
|
|
this.props.isLoggedIn && |
|
|
this.props.signupDependencies.siteSlug && |
|
|
0 === this.props.siteDomains.length; |
|
|
const isImportingFlow = this.props.flowName === 'from' && this.props.stepName === 'importing'; |
|
|
|
|
|
if ( isStepRemovedFromFlow ) { |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
if ( isDomainsForSiteEmpty && ! isImportingFlow && this.props.siteId ) { |
|
|
return <QuerySiteDomains siteId={ this.props.siteId } />; |
|
|
} |
|
|
} |
|
|
render() { |
|
|
|
|
|
if ( |
|
|
! this.props.stepName || |
|
|
( this.getPositionInFlow() > 0 && this.props.progress.length === 0 ) || |
|
|
this.state.resumingStep |
|
|
) { |
|
|
return null; |
|
|
} |
|
|
|
|
|
|
|
|
const waitToRenderReturnValue = this.shouldWaitToRender(); |
|
|
if ( waitToRenderReturnValue && ! this.state.shouldShowLoadingScreen ) { |
|
|
return this.props.siteId && waitToRenderReturnValue; |
|
|
} |
|
|
|
|
|
const showPageHeader = ! this.props.isGravatar; |
|
|
const isGravatarDomain = isDomainForGravatarFlow( this.props.flowName ); |
|
|
|
|
|
return ( |
|
|
<> |
|
|
<div className={ `signup is-${ kebabCase( this.props.flowName ) }` }> |
|
|
<DocumentHead title={ this.props.pageTitle } /> |
|
|
{ showPageHeader && ( |
|
|
<SignupHeader |
|
|
progressBar={ { |
|
|
flowName: this.props.flowName, |
|
|
stepName: this.props.stepName, |
|
|
} } |
|
|
shouldShowLoadingScreen={ this.state.shouldShowLoadingScreen } |
|
|
rightComponent={ |
|
|
showProgressIndicator( this.props.flowName ) && ( |
|
|
<FlowProgressIndicator |
|
|
positionInFlow={ this.getPositionInFlow() } |
|
|
flowLength={ this.getInteractiveStepsCount() } |
|
|
flowName={ this.props.flowName } |
|
|
/> |
|
|
) |
|
|
} |
|
|
logoComponent={ isGravatarDomain ? <GravatarTextLogo /> : undefined } |
|
|
/> |
|
|
) } |
|
|
<div className="signup__steps">{ this.renderCurrentStep() }</div> |
|
|
{ this.state.bearerToken && ( |
|
|
<WpcomLoginForm |
|
|
authorization={ 'Bearer ' + this.state.bearerToken } |
|
|
log={ this.state.username } |
|
|
redirectTo={ this.state.redirectTo } |
|
|
/> |
|
|
) } |
|
|
</div> |
|
|
</> |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
export default connect( |
|
|
( state ) => { |
|
|
const signupDependencies = getSignupDependencyStore( state ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const siteId = getSelectedSiteId( state ) || getSiteId( state, signupDependencies.siteSlug ); |
|
|
const siteDomains = getDomainsBySiteId( state, siteId ); |
|
|
const oauth2Client = getCurrentOAuth2Client( state ); |
|
|
const hostingFlow = startedInHostingFlow( state ); |
|
|
|
|
|
return { |
|
|
domainsWithPlansOnly: getCurrentUser( state ) |
|
|
? currentUserHasFlag( state, NON_PRIMARY_DOMAINS_TO_FREE_USERS ) |
|
|
: true, |
|
|
isDomainOnlySite: isDomainOnlySite( state, siteId ), |
|
|
progress: getSignupProgress( state ), |
|
|
signupDependencies, |
|
|
isLoggedIn: isUserLoggedIn( state ), |
|
|
isEmailVerified: isCurrentUserEmailVerified( state ), |
|
|
existingSiteCount: getCurrentUserSiteCount( state ), |
|
|
isPaidPlan: isCurrentPlanPaid( state, siteId ), |
|
|
sitePlanName: getSitePlanName( state, siteId ), |
|
|
sitePlanSlug: getSitePlanSlug( state, siteId ), |
|
|
siteDomains, |
|
|
siteId, |
|
|
localeSlug: getCurrentLocaleSlug( state ), |
|
|
oauth2Client, |
|
|
isGravatar: isGravatarOAuth2Client( oauth2Client ), |
|
|
wccomFrom: getWccomFrom( state ), |
|
|
hostingFlow, |
|
|
}; |
|
|
}, |
|
|
{ |
|
|
submitSignupStep, |
|
|
removeStep, |
|
|
addStep, |
|
|
} |
|
|
)( Signup ); |
|
|
|