-
Notifications
You must be signed in to change notification settings - Fork 2k
/
helper.ts
62 lines (56 loc) · 1.95 KB
/
helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { isEnabled } from '@automattic/calypso-config';
import { addQueryArgs } from '@wordpress/url';
import { camelCase } from 'lodash';
import { ImporterPlatform } from 'calypso/blocks/import/types';
import {
getImporterUrl,
getWpComOnboardingUrl,
getWpOrgImporterUrl,
} from 'calypso/blocks/import/util';
import { WPImportOption } from 'calypso/blocks/importer/wordpress/types';
import { BASE_ROUTE } from './config';
import type { StepPath } from '../../steps-repository';
export function getFinalImporterUrl(
targetSlug: string,
fromSite: string,
platform: ImporterPlatform,
isAtomicSite: boolean | null,
framework: 'signup' | 'stepper' = 'signup'
) {
let importerUrl;
// Escape WordPress, has two sub-flows "Import everything" and "Content only"
// firstly show import type chooser screen and then decide about importer url
if ( isAtomicSite && platform !== 'wordpress' ) {
importerUrl = getWpOrgImporterUrl( targetSlug, platform );
} else if (
[ 'blogger', 'medium', 'squarespace', 'wix', 'wordpress' ].some( ( targetPlatform ) => {
return (
platform === targetPlatform && isEnabled( `onboarding/import-from-${ targetPlatform }` )
);
} )
) {
importerUrl = getWpComOnboardingUrl( targetSlug, platform, fromSite, framework );
if ( platform === 'wordpress' && ! fromSite ) {
importerUrl = addQueryArgs( importerUrl, {
option: WPImportOption.CONTENT_ONLY,
} );
}
} else {
importerUrl = getImporterUrl( targetSlug, platform, fromSite );
}
return importerUrl;
}
/**
* Stepper's redirection handlers
* generateStepPath share the same interface/params between 'signup' & 'stepper' frameworks
*/
export function generateStepPath(
stepName: string | StepPath,
stepSectionName?: string
): StepPath {
if ( stepName === 'intent' ) return 'goals';
else if ( stepName === 'capture' ) return BASE_ROUTE;
const routes = [ BASE_ROUTE, stepName, stepSectionName ];
const path = routes.join( '_' );
return camelCase( path ) as StepPath;
}