Skip to content

Commit

Permalink
Handle redirect for successful passwordless form signup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyip committed Jun 25, 2024
1 parent f650a98 commit 0d822ff
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
15 changes: 5 additions & 10 deletions client/blocks/signup-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1302,16 +1302,11 @@ class SignupForm extends Component {
onInputBlur={ this.handleBlur }
onInputChange={ this.handleChangeEvent }
onCreateAccountError={ ( error, email ) => {
if ( [ 'already_taken', 'already_active', 'email_exists' ].includes( error.error ) ) {
page(
addQueryArgs(
{
email_address: email,
is_signup_existing_account: true,
},
logInUrl
)
);
// TODO: Determine if there's a better way to handle a custom create account error
if ( this.props.onPasswordlessCreateAccountError ) {
this.props.onPasswordlessCreateAccountError( error, email );
this.setState( { disabled: false, submitting: false } );
return;
}
} }
{ ...formProps }
Expand Down
5 changes: 5 additions & 0 deletions client/blocks/signup-form/passwordless.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ class PasswordlessSignupForm extends Component {
isSubmitting: false,
} );
}

// TODO: Figure out how to appropriately update submitting property
this.setState( {
isSubmitting: false,
} );
this.props.onCreateAccountError?.( error, this.state.email );
};

Expand Down
2 changes: 1 addition & 1 deletion client/signup/config/flows-pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getEmailSubscriptionFlow = () => {
{
name: 'email-subscription',
steps: [ 'subscribing-email' ],
destination: ( dependencies ) => `${ dependencies.redirectUrl }`,
destination: ( dependencies ) => `${ dependencies.redirect }`,
description:
'Signup flow that subscripes user to guides appointments for email campaigns',
lastModified: '2024-06-17',
Expand Down
2 changes: 1 addition & 1 deletion client/signup/config/steps-pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export function generateSteps( {
'subscribing-email': {
stepName: 'subscribing-email',
dependencies: [ 'email', 'redirect_to', 'mailing_list' ],
providesDependencies: [ 'redirectUrl' ],
providesDependencies: [ 'redirect', 'username', 'marketing_price_group', 'bearer_token' ],
},
mailbox: {
stepName: 'mailbox',
Expand Down
24 changes: 20 additions & 4 deletions client/signup/steps/subscribing-email/content.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { addQueryArgs } from '@wordpress/url';
import { localize } from 'i18n-calypso';
import SignupForm from 'calypso/blocks/signup-form';
import ReskinnedProcessingScreen from 'calypso/signup/reskinned-processing-screen';

function SubscribingEmailStepContent( props ) {
const { flowName, handleSubmitSignup, isLoading, stepName, step, translate, queryParams } = props;
const {
flowName,
handleSubmitSignup,
isLoading,
stepName,
step,
translate,
queryParams,
goToNextStep,
} = props;

const redirectUrl = queryParams?.redirect_to || 'https://wordpress.com';
const redirect_to = queryParams?.redirect_to
? addQueryArgs( queryParams.redirect_to, { subscribed: true } )
: 'https://wordpress.com';
const email = queryParams?.email;

if ( isLoading ) {
Expand All @@ -19,11 +31,12 @@ function SubscribingEmailStepContent( props ) {
stepName={ stepName }
flowName={ flowName }
email={ email || '' }
redirectToAfterLoginUrl={ redirectUrl }
goToNextStep={ goToNextStep }
displayUsernameInput={ false }
redirectToAfterLoginUrl={ redirect_to }
suggestedUsername=""
isPasswordless
queryArgs={ { user_email: email } || {} }
queryArgs={ { user_email: email, redirect_to } || {} }
isSocialSignupEnabled={ false }
// recaptchaClientId={ this.state.recaptchaClientId }
isReskinned
Expand All @@ -32,6 +45,9 @@ function SubscribingEmailStepContent( props ) {
labelText={ translate( 'Your email' ) }
submitButtonText={ translate( 'Create an account' ) }
submitForm={ handleSubmitSignup }
onPasswordlessCreateAccountError={ () => {} }
// TODO: Do we need the save property?
save={ () => {} }
/>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions client/signup/steps/subscribing-email/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const createNewAccount = async ( {
} );
submitSignupStep(
{ stepName: 'subscribing-email' },
{ redirectUrl: addQueryArgs( redirect_to, { subscribed: true } ) }
{ redirect: addQueryArgs( redirect_to, { subscribed: true } ) }
);
goToNextStep();
return;
Expand All @@ -53,7 +53,7 @@ const createNewAccount = async ( {

submitSignupStep(
{ stepName: 'subscribing-email' },
{ redirectUrl: addQueryArgs( redirect_to, { subscribed: true } ) }
{ redirect: addQueryArgs( redirect_to, { subscribed: true } ) }
);
goToNextStep();
}
Expand Down

0 comments on commit 0d822ff

Please sign in to comment.