File size: 1,209 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { FEATURE_UPLOAD_THEMES_PLUGINS, planHasFeature } from '@automattic/calypso-products';
import { CAPTURE_URL_RGX } from 'calypso/blocks/import/util';
import { untrailingslashit } from 'calypso/lib/route';
import type { Importer } from './types';
import type { SiteDetails } from '@automattic/data-stores';

export const getImporterTypeForEngine = ( engine: Importer ) => `importer-type-${ engine }`;

export function isTargetSitePlanCompatible( targetSite: SiteDetails | undefined ) {
	const planSlug = targetSite?.plan?.product_slug;
	return planSlug && planHasFeature( planSlug, FEATURE_UPLOAD_THEMES_PLUGINS );
}

export function formatSlugToURL( inputUrl: string ) {
	if ( ! inputUrl ) {
		return '';
	}
	// If it's not a valid URL, return it
	if ( ! CAPTURE_URL_RGX.test( inputUrl ) ) {
		return inputUrl;
	}
	let url = inputUrl.trim().toLowerCase();
	if ( url && ! url.startsWith( 'http' ) ) {
		url = 'http://' + url;
	}
	url = url.replace( /wp-admin\/?$/, '' );
	return untrailingslashit( url );
}

export function buildCheckoutUrl( siteSlug: string | undefined | null, plan = 'business' ) {
	if ( ! siteSlug ) {
		return `/checkout/${ plan }`;
	}
	return `/checkout/${ siteSlug }/${ plan }`;
}