Skip to content

Commit

Permalink
Stepper: Replace domain upsell exitFlow() usage with stepper submit()…
Browse files Browse the repository at this point in the history
… function (Automattic#76604)

* Replace exitFlow usage with stepper submit function

* Fix type check issue

* Update type check

* use goBack function in domain upsell flow
  • Loading branch information
agrullon95 authored May 19, 2023
1 parent 88782a4 commit bd8c101
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
9 changes: 4 additions & 5 deletions client/landing/stepper/declarative-flow/domain-upsell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ const domainUpsell: Flow = {
const returnUrl = `/setup/${ flowName ?? 'free' }/launchpad?siteSlug=${ siteSlug }`;
const encodedReturnUrl = encodeURIComponent( returnUrl );

const exitFlow = ( location = '/sites' ) => {
window.location.assign( location );
};

function goBack() {
if ( currentStep === 'domains' ) {
return window.location.assign( returnUrl );
}
if ( currentStep === 'plans' ) {
navigate( 'domains' );
}
Expand Down Expand Up @@ -88,7 +87,7 @@ const domainUpsell: Flow = {
}
}

return { submit, exitFlow, goBack };
return { submit, goBack };
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { useI18n } from '@wordpress/react-i18n';
import { useState } from 'react';
import { useDispatch as useReduxDispatch } from 'react-redux';
import FormattedHeader from 'calypso/components/formatted-header';
import { useQuery } from 'calypso/landing/stepper/hooks/use-query';
import { useSiteSlug } from 'calypso/landing/stepper/hooks/use-site-slug';
import {
domainRegistration,
domainMapping,
Expand Down Expand Up @@ -44,10 +42,8 @@ const DomainsStep: Step = function DomainsStep( { navigation, flow } ) {
const [ showUseYourDomain, setShowUseYourDomain ] = useState( false );

const dispatch = useReduxDispatch();
const flowToReturnTo = useQuery().get( 'flowToReturnTo' );
const siteSlug = useSiteSlug();

const { submit, exitFlow } = navigation;
const { submit, exitFlow, goBack } = navigation;

const submitDomainStepSelection = ( suggestion: DomainSuggestion, section: string ) => {
let domainType = 'domain_reg';
Expand Down Expand Up @@ -239,13 +235,13 @@ const DomainsStep: Step = function DomainsStep( { navigation, flow } ) {
/>
);

const handleGoBack = () => {
const handleGoBack = ( goBack: ( () => void ) | undefined ) => {
if ( showUseYourDomain ) {
return setShowUseYourDomain( false );
}

if ( flow === DOMAIN_UPSELL_FLOW ) {
return exitFlow?.( `/setup/${ flowToReturnTo }/launchpad?siteSlug=${ siteSlug }` );
return goBack?.();
}
return exitFlow?.( '/sites' );
};
Expand Down Expand Up @@ -274,7 +270,7 @@ const DomainsStep: Step = function DomainsStep( { navigation, flow } ) {
flowName={ flow as string }
stepContent={ <div className="domains__content">{ renderContent() }</div> }
recordTracksEvent={ recordTracksEvent }
goBack={ handleGoBack }
goBack={ () => handleGoBack( goBack ) }
goNext={ () => submit?.() }
formattedHeader={
<FormattedHeader
Expand Down

0 comments on commit bd8c101

Please sign in to comment.