Skip to content
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

P2 signup: add 'post-email confirmation' screen #59573

Merged
merged 4 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/assets/stylesheets/_p2-extends.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
margin: 0 0 1em;
padding: 1em 2em;
transition: 0.2s ease-in-out;
height: auto;
width: 100%;

&:hover {
Expand Down
10 changes: 10 additions & 0 deletions client/lib/signup/step-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,16 @@ export function excludeStepIfEmailVerified( stepName, defaultDependencies, nextP
return;
}

/* For the P2 signup flow, if we displayed the email verification step before,
we need to display it again when the user comes back to the flow
after verification. */
if (
nextProps.flowName === 'p2-new' &&
nextProps?.progress[ stepName ]?.status === 'in-progress'
) {
return;
}

if ( ! nextProps.isEmailVerified ) {
return;
}
Expand Down
83 changes: 71 additions & 12 deletions client/signup/steps/p2-confirm-email/index.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { Button } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';
import { check } from '@wordpress/icons';
import { useTranslate } from 'i18n-calypso';
import { useSelector, useDispatch } from 'react-redux';
import wpcom from 'calypso/lib/wp';
import P2StepWrapper from 'calypso/signup/p2-step-wrapper';
import { getCurrentUserEmail } from 'calypso/state/current-user/selectors';
import { errorNotice, successNotice } from 'calypso/state/notices/actions';
import { saveSignupStep } from 'calypso/state/signup/progress/actions';
import './style.scss';

function P2ConfirmEmail( { flowName, stepName, positionInFlow } ) {
function P2ConfirmEmail( {
flowName,
goToNextStep,
isEmailVerified,
positionInFlow,
stepName,
submitSignupStep,
} ) {
const translate = useTranslate();
const dispatch = useDispatch();
const userEmail = useSelector( getCurrentUserEmail );
Expand All @@ -27,13 +36,23 @@ function P2ConfirmEmail( { flowName, stepName, positionInFlow } ) {
</svg>
);

// Remember that we loaded, not skipped, this step for the user.
useEffect( () => {
dispatch( saveSignupStep( { stepName } ) );
}, [ dispatch, stepName ] );

const handleResendEmailClick = () => {
if ( emailResendCount >= EMAIL_RESEND_MAX ) {
return;
}

wpcom.req
.post( '/me/send-verification-email' )
.post( {
path: '/me/send-verification-email',
body: {
from: 'p2-signup',
},
} )
.then( () => {
setEmailResendCount( emailResendCount + 1 );
dispatch(
Expand All @@ -45,15 +64,18 @@ function P2ConfirmEmail( { flowName, stepName, positionInFlow } ) {
} );
};

return (
<P2StepWrapper
flowName={ flowName }
stepName={ stepName }
positionInFlow={ positionInFlow }
headerIcon={ mailIcon }
headerText={ translate( 'Check your email' ) }
>
<div className="p2-confirm-email">
const handleNextStepClick = ( option ) => {
submitSignupStep( {
stepName,
option,
} );

goToNextStep();
};

const renderCheckEmailNotice = () => {
return (
<>
<div className="p2-confirm-email__message">
{ translate(
"We've sent an email with a verification link to {{strong}}%(email)s{{/strong}}. Please follow that link to confirm your email address and continue.",
Expand All @@ -75,6 +97,43 @@ function P2ConfirmEmail( { flowName, stepName, positionInFlow } ) {
</div>
</div>
) }
</>
);
};

const renderPostConfirmationNotice = () => {
return (
<>
<div className="p2-confirm-email__message">
{ translate(
"Thanks for confirming your email address. Your account is now active. We're almost finished!"
) }
</div>
<div className="p2-confirm-email__buttons">
<Button
className="p2-confirm-email__continue"
isPrimary={ true }
onClick={ handleNextStepClick }
>
{ translate( 'Continue' ) }
</Button>
</div>
</>
);
};

return (
<P2StepWrapper
flowName={ flowName }
stepName={ stepName }
positionInFlow={ positionInFlow }
headerIcon={ isEmailVerified ? check : mailIcon }
headerText={
isEmailVerified ? translate( 'Email confirmed' ) : translate( 'Check your email' )
annemirasol marked this conversation as resolved.
Show resolved Hide resolved
}
>
<div className="p2-confirm-email">
{ isEmailVerified ? renderPostConfirmationNotice() : renderCheckEmailNotice() }
</div>
</P2StepWrapper>
);
Expand Down
6 changes: 6 additions & 0 deletions client/signup/steps/p2-confirm-email/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
box-shadow: none;
}
}

button.p2-confirm-email__continue {
margin-top: 2.5em;
max-width: 228px;
}
}

.p2-confirm-email__message {
Expand All @@ -66,6 +71,7 @@
.p2-confirm-email__buttons {
display: flex;
align-items: center;
justify-content: center;
}

.p2-confirm-email__buttons-separator {
Expand Down