|
|
import { isEnabled } from '@automattic/calypso-config'; |
|
|
import { Plans } from '@automattic/data-stores'; |
|
|
import languages from '@automattic/languages'; |
|
|
import { addQueryArgs } from '@wordpress/url'; |
|
|
import { useFlowLocale } from '../hooks/use-flow-locale'; |
|
|
|
|
|
const plansPaths = Plans.plansSlugs; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const Step = { |
|
|
IntentGathering: undefined, |
|
|
DesignSelection: 'design', |
|
|
Style: 'style', |
|
|
Features: 'features', |
|
|
Signup: 'signup', |
|
|
Login: 'login', |
|
|
CreateSite: 'create-site', |
|
|
Domains: 'domains', |
|
|
Emails: 'emails', |
|
|
Plans: 'plans', |
|
|
DomainsModal: 'domains-modal', |
|
|
PlansModal: 'plans-modal', |
|
|
LanguageModal: 'language-modal', |
|
|
} as const; |
|
|
|
|
|
|
|
|
export const steps = Object.values( Step ).filter( Boolean ); |
|
|
|
|
|
const routeFragments = { |
|
|
|
|
|
step: `:step(${ steps.join( '|' ) })?`, |
|
|
plan: `:plan(${ plansPaths.join( '|' ) })?`, |
|
|
lang: `:lang(${ languages.map( ( lang ) => lang.langSlug ).join( '|' ) })?`, |
|
|
}; |
|
|
|
|
|
export const path = [ '', ...Object.values( routeFragments ) ].join( '/' ); |
|
|
|
|
|
export const getLoginUrl = ( { |
|
|
variationName, |
|
|
redirectTo, |
|
|
pageTitle, |
|
|
locale, |
|
|
customLoginPath, |
|
|
extra = {}, |
|
|
}: { |
|
|
|
|
|
|
|
|
|
|
|
variationName?: string | null; |
|
|
redirectTo?: string | null; |
|
|
pageTitle?: string | null; |
|
|
locale: string; |
|
|
customLoginPath?: string | null; |
|
|
extra?: Record< string, string | number >; |
|
|
} ): string => { |
|
|
const defaultLoginPath = `/start/account/${ |
|
|
isEnabled( 'signup/social-first' ) ? 'user-social' : 'user' |
|
|
}`; |
|
|
const loginPath = customLoginPath || defaultLoginPath; |
|
|
const localizedLoginPath = locale && locale !== 'en' ? `${ loginPath }/${ locale }` : loginPath; |
|
|
|
|
|
|
|
|
return addQueryArgs( localizedLoginPath, { |
|
|
variationName, |
|
|
redirect_to: redirectTo, |
|
|
pageTitle, |
|
|
toStepper: true, |
|
|
...extra, |
|
|
} ); |
|
|
}; |
|
|
|
|
|
export const useLoginUrl = ( { |
|
|
variationName, |
|
|
redirectTo, |
|
|
pageTitle, |
|
|
locale, |
|
|
customLoginPath, |
|
|
extra = {}, |
|
|
}: { |
|
|
|
|
|
|
|
|
|
|
|
variationName?: string | null; |
|
|
redirectTo?: string | null; |
|
|
pageTitle?: string | null; |
|
|
locale?: string; |
|
|
customLoginPath?: string | null; |
|
|
extra?: Record< string, string | number >; |
|
|
} ): string => { |
|
|
const currentLocale = useFlowLocale(); |
|
|
return getLoginUrl( { |
|
|
variationName, |
|
|
redirectTo, |
|
|
pageTitle, |
|
|
locale: locale ?? currentLocale, |
|
|
customLoginPath, |
|
|
extra, |
|
|
} ); |
|
|
}; |
|
|
|