File size: 4,199 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {
	PLAN_MIGRATION_TRIAL_MONTHLY,
	PLAN_ECOMMERCE_TRIAL_MONTHLY,
	PLAN_HOSTING_TRIAL_MONTHLY,
} from '@automattic/calypso-products';
import type { SiteExcerptData, SiteExcerptNetworkData } from '@automattic/sites';

export const TRACK_SOURCE_NAME = 'sites-dashboard';

export const getLaunchpadUrl = ( slug: string, flow: string ) => {
	return `/setup/${ flow }/launchpad?siteSlug=${ slug }`;
};

export const getDashboardUrl = ( slug: string ) => {
	return `/home/${ slug }`;
};

export const getPluginsUrl = ( slug: string ) => {
	return `/plugins/${ slug }`;
};

export const getManagePluginsUrl = ( slug: string ) => {
	return `/plugins/manage/${ slug }`;
};

export const getHostingConfigUrl = ( slug: string ) => {
	return `/hosting-config/${ slug }`;
};

export const displaySiteUrl = ( siteUrl: string ) => {
	return siteUrl.replace( 'https://', '' ).replace( 'http://', '' );
};

export function isCustomDomain( siteSlug: string | null | undefined ): boolean {
	if ( ! siteSlug ) {
		return false;
	}
	return ! siteSlug.endsWith( '.wordpress.com' ) && ! siteSlug.endsWith( '.wpcomstaging.com' );
}

export function getSiteAdminUrl( site: SiteExcerptNetworkData ) {
	return site.options?.admin_url ?? '';
}

export const isNotAtomicJetpack = ( site: SiteExcerptNetworkData ) => {
	return site.jetpack && ! site?.is_wpcom_atomic;
};

// Sites connected through A4A plugin are listed on wordpress.com/sites even when Jetpack is deactivated.
export const isDisconnectedJetpackAndNotAtomic = ( site: SiteExcerptNetworkData ) => {
	return ! site?.is_wpcom_atomic && site?.jetpack_connection && ! site?.jetpack;
};

export const isSimpleSite = ( site: SiteExcerptNetworkData ) => {
	return ! site?.jetpack && ! site?.is_wpcom_atomic;
};

export const isP2Site = ( site: SiteExcerptNetworkData ) => {
	return site.options?.is_wpforteams_site;
};

export const isStagingSite = ( site: SiteExcerptNetworkData | undefined ) => {
	return site?.is_wpcom_staging_site;
};

export const isMigrationTrialSite = ( site: SiteExcerptNetworkData ) => {
	return site?.plan?.product_slug === PLAN_MIGRATION_TRIAL_MONTHLY;
};

export const isHostingTrialSite = ( site: SiteExcerptNetworkData ) => {
	return site?.plan?.product_slug === PLAN_HOSTING_TRIAL_MONTHLY;
};

export const isECommerceTrialSite = ( site: SiteExcerptNetworkData ) => {
	return site?.plan?.product_slug === PLAN_ECOMMERCE_TRIAL_MONTHLY;
};

export const isBusinessTrialSite = ( site: SiteExcerptNetworkData ) => {
	return isMigrationTrialSite( site ) || isHostingTrialSite( site );
};

export const isTrialSite = ( site: SiteExcerptNetworkData ) => {
	return isBusinessTrialSite( site ) || isECommerceTrialSite( site );
};

export const getAdminInterface = ( site: SiteExcerptNetworkData ) => {
	return site?.options?.wpcom_admin_interface;
};

export const siteUsesWpAdminInterface = ( site: SiteExcerptNetworkData ) => {
	return ( site.jetpack && ! site.is_wpcom_atomic ) || getAdminInterface( site ) === 'wp-admin';
};

export const isSitePreviewPaneEligible = ( site: SiteExcerptData, canManageOptions: boolean ) => {
	return (
		! isDisconnectedJetpackAndNotAtomic( site ) &&
		! isNotAtomicJetpack( site ) &&
		! isP2Site( site ) &&
		canManageOptions
	);
};
export interface InterfaceURLFragment {
	calypso: `/${ string }`;
	wpAdmin: `/${ string }`;
}

export const generateSiteInterfaceLink = (
	site: SiteExcerptData,
	urlFragment: InterfaceURLFragment
) => {
	const targetLink = siteUsesWpAdminInterface( site )
		? `${ site.URL }/wp-admin${ urlFragment.wpAdmin }`
		: `${ urlFragment.calypso }/${ site.slug }`;

	return targetLink;
};

export const SMALL_MEDIA_QUERY = 'screen and ( max-width: 600px )';

export const MEDIA_QUERIES = {
	small: `@media ${ SMALL_MEDIA_QUERY }`,
	mediumOrSmaller: '@media screen and ( max-width: 781px )',
	mediumOrLarger: '@media screen and ( min-width: 660px )',
	hideTableRows: '@media screen and ( max-width: 1100px )',
	large: '@media screen and ( min-width: 960px )',
	wide: '@media screen and ( min-width: 1280px )',
};

export const PLAN_RENEW_NAG_EVENT_NAMES = {
	IN_VIEW: 'calypso_sites_dashboard_plan_renew_nag_inview',
	ON_CLICK: 'calypso_sites_dashboard_plan_renew_nag_click',
};