-
Notifications
You must be signed in to change notification settings - Fork 2k
/
helper.ts
70 lines (61 loc) · 1.82 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
63
64
65
66
67
68
69
70
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 { getImporterEngines } from 'calypso/lib/importer/importer-config';
import { BASE_ROUTE } from './config';
export function getFinalImporterUrl(
targetSlug: string,
fromSite: string,
platform: ImporterPlatform,
backToFlow?: string
) {
let importerUrl;
const encodedFromSite = encodeURIComponent( fromSite );
const productImporters = getImporterEngines();
if ( productImporters.includes( platform ) ) {
importerUrl = isEnabled( `onboarding/import-from-${ platform }` )
? getWpComOnboardingUrl( targetSlug, platform, encodedFromSite )
: getImporterUrl( targetSlug, platform, encodedFromSite );
if ( platform === 'wordpress' && ! fromSite ) {
importerUrl = addQueryArgs( importerUrl, {
option: WPImportOption.CONTENT_ONLY,
} );
} else if ( platform === 'wix' && fromSite ) {
importerUrl = addQueryArgs( importerUrl, {
run: true,
} );
}
} else {
importerUrl = getWpOrgImporterUrl( targetSlug, platform );
}
if ( backToFlow ) {
importerUrl = addQueryArgs( importerUrl, {
backToFlow,
} );
}
return importerUrl;
}
/**
* Stepper's redirection handlers
*/
export function generateStepPath( stepName: string, stepSectionName?: string ) {
switch ( stepName ) {
case 'intent':
case 'goals':
return 'goals';
case 'capture':
return BASE_ROUTE;
default: {
const routes = [ BASE_ROUTE, stepName, stepSectionName ];
const path = routes.join( '_' );
return camelCase( path ) as string;
}
}
}