-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Anthony Grullon <[email protected]> Co-authored-by: Emanuele Buccelli <[email protected]>
- Loading branch information
1 parent
5e6ce23
commit d0c13e7
Showing
16 changed files
with
377 additions
and
75 deletions.
There are no files selected for viewing
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
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,175 @@ | ||
import { Onboard, OnboardActions, updateLaunchpadSettings } from '@automattic/data-stores'; | ||
import { EXAMPLE_FLOW } from '@automattic/onboarding'; | ||
import { dispatch } from '@wordpress/data'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
import { translate } from 'i18n-calypso'; | ||
import { useLaunchpadDecider } from 'calypso/landing/stepper/declarative-flow/internals/hooks/use-launchpad-decider'; | ||
import { useQuery } from 'calypso/landing/stepper/hooks/use-query'; | ||
import { skipLaunchpad } from 'calypso/landing/stepper/utils/skip-launchpad'; | ||
import { triggerGuidesForStep } from 'calypso/lib/guides/trigger-guides-for-step'; | ||
import { | ||
clearSignupDestinationCookie, | ||
setSignupCompleteSlug, | ||
persistSignupDestination, | ||
setSignupCompleteFlowName, | ||
} from 'calypso/signup/storageUtils'; | ||
import { useExitFlow } from '../hooks/use-exit-flow'; | ||
import { useSiteIdParam } from '../hooks/use-site-id-param'; | ||
import { useSiteSlug } from '../hooks/use-site-slug'; | ||
import { ONBOARD_STORE } from '../stores'; | ||
import { getQuery } from '../utils/get-query'; | ||
import { stepsWithRequiredLogin } from '../utils/steps-with-required-login'; | ||
import { STEPS } from './internals/steps'; | ||
import { ProvidedDependencies } from './internals/types'; | ||
import type { Flow } from './internals/types'; | ||
|
||
const newsletter: Flow = { | ||
name: EXAMPLE_FLOW, | ||
get title() { | ||
return translate( 'Newsletter Example Flow' ); | ||
}, | ||
isSignupFlow: true, | ||
initialize() { | ||
const query = getQuery(); | ||
const isComingFromMarketingPage = query[ 'ref' ] === 'newsletter-lp'; | ||
|
||
const { setHidePlansFeatureComparison, setIntent } = dispatch( | ||
ONBOARD_STORE | ||
) as OnboardActions; | ||
|
||
// We can just call these. They're guaranteed to run once. | ||
setHidePlansFeatureComparison( true ); | ||
clearSignupDestinationCookie(); | ||
setIntent( Onboard.SiteIntent.Newsletter ); | ||
|
||
const privateSteps = stepsWithRequiredLogin( [ | ||
STEPS.NEWSLETTER_SETUP, | ||
STEPS.NEWSLETTER_GOALS, | ||
STEPS.DOMAINS, | ||
STEPS.PLANS, | ||
STEPS.PROCESSING, | ||
STEPS.SUBSCRIBERS, | ||
STEPS.SITE_CREATION_STEP, | ||
STEPS.LAUNCHPAD, | ||
] ); | ||
|
||
if ( ! isComingFromMarketingPage ) { | ||
return [ STEPS.INTRO, ...privateSteps ]; | ||
} | ||
|
||
return privateSteps; | ||
}, | ||
|
||
useStepNavigation( _currentStep, navigate ) { | ||
const flowName = this.name; | ||
const siteId = useSiteIdParam(); | ||
const siteSlug = useSiteSlug(); | ||
const query = useQuery(); | ||
const { exitFlow } = useExitFlow(); | ||
const isComingFromMarketingPage = query.get( 'ref' ) === 'newsletter-lp'; | ||
|
||
const { getPostFlowUrl, initializeLaunchpadState } = useLaunchpadDecider( { | ||
exitFlow, | ||
navigate, | ||
} ); | ||
|
||
const completeSubscribersTask = async () => { | ||
if ( siteSlug ) { | ||
await updateLaunchpadSettings( siteSlug, { | ||
checklist_statuses: { subscribers_added: true }, | ||
} ); | ||
} | ||
}; | ||
|
||
triggerGuidesForStep( flowName, _currentStep ); | ||
|
||
function submit( providedDependencies: ProvidedDependencies = {} ) { | ||
const launchpadUrl = `/setup/${ flowName }/launchpad?siteSlug=${ providedDependencies.siteSlug }`; | ||
|
||
switch ( _currentStep ) { | ||
case 'intro': | ||
return navigate( 'newsletterSetup' ); | ||
|
||
case 'newsletterSetup': | ||
return navigate( 'newsletterGoals' ); | ||
|
||
case 'newsletterGoals': | ||
return navigate( 'domains' ); | ||
|
||
case 'domains': | ||
return navigate( 'plans' ); | ||
|
||
case 'plans': | ||
return navigate( 'createSite' ); | ||
|
||
case 'createSite': | ||
return navigate( 'processing' ); | ||
|
||
case 'processing': | ||
if ( providedDependencies?.goToHome && providedDependencies?.siteSlug ) { | ||
return window.location.replace( | ||
addQueryArgs( `/home/${ siteId ?? providedDependencies?.siteSlug }`, { | ||
celebrateLaunch: true, | ||
launchpadComplete: true, | ||
} ) | ||
); | ||
} | ||
|
||
if ( providedDependencies?.goToCheckout && providedDependencies?.siteSlug ) { | ||
persistSignupDestination( launchpadUrl ); | ||
setSignupCompleteSlug( providedDependencies?.siteSlug ); | ||
setSignupCompleteFlowName( flowName ); | ||
|
||
return window.location.assign( | ||
`/checkout/${ encodeURIComponent( | ||
providedDependencies?.siteSlug as string | ||
) }?redirect_to=${ encodeURIComponent( launchpadUrl ) }&signup=1` | ||
); | ||
} | ||
|
||
initializeLaunchpadState( { | ||
siteId: providedDependencies?.siteId as number, | ||
siteSlug: providedDependencies?.siteSlug as string, | ||
} ); | ||
|
||
return window.location.assign( | ||
getPostFlowUrl( { | ||
flow: flowName, | ||
siteId: providedDependencies?.siteId as number, | ||
siteSlug: providedDependencies?.siteSlug as string, | ||
} ) | ||
); | ||
|
||
case 'subscribers': | ||
completeSubscribersTask(); | ||
return navigate( 'launchpad' ); | ||
} | ||
} | ||
|
||
const goBack = () => { | ||
return; | ||
}; | ||
|
||
const goNext = async () => { | ||
switch ( _currentStep ) { | ||
case 'launchpad': | ||
skipLaunchpad( { | ||
siteId, | ||
siteSlug, | ||
} ); | ||
return; | ||
|
||
default: | ||
return navigate( isComingFromMarketingPage ? 'newsletterSetup' : 'intro' ); | ||
} | ||
}; | ||
|
||
const goToStep = ( step: string ) => { | ||
navigate( step ); | ||
}; | ||
|
||
return { goNext, goBack, goToStep, submit }; | ||
}, | ||
}; | ||
|
||
export default newsletter; |
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
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
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
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
Oops, something went wrong.