File size: 3,249 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
import { recordTracksEvent } from '@automattic/calypso-analytics';
import { BackButton, NextButton, SubTitle, Title } from '@automattic/onboarding';
import { useI18n } from '@wordpress/react-i18n';
import React, { useEffect } from 'react';
import { HintJetpackConnection } from './hint-jetpack-connection';
import { HintJetpackConnectionMovePlugin } from './hint-jetpack-connection-move-plugin';

import './style.scss';

export type NotAuthorizedType =
	| 'generic'
	| 'target-site-staging'
	| 'source-site-not-connected'
	| 'source-site-not-connected-move-plugin';

interface Props {
	type?: NotAuthorizedType;
	sourceSiteUrl?: string;
	targetSiteUrl?: string;
	startImport?: () => void;
	onBackToStart?: () => void;
	onStartBuilding?: () => void;
	onStartBuildingText?: string;
}

const NotAuthorized: React.FunctionComponent< Props > = ( props ) => {
	const { __ } = useI18n();
	const {
		type = 'generic',
		sourceSiteUrl,
		targetSiteUrl,
		startImport,
		onBackToStart,
		onStartBuilding,
		onStartBuildingText,
	} = props;

	const startBuildingText = onStartBuildingText ?? __( 'Start building' );

	useEffect( () => {
		recordTracksEvent( 'calypso_site_importer_unauthorized' );
	}, [] );

	return (
		<div className="import__not-authorized import-layout__center">
			<div className="import__header">
				<div className="import__heading  import__heading-center">
					{ type === 'generic' && (
						<>
							<Title>{ __( 'You are not authorized to import content' ) }</Title>
							<SubTitle>{ __( 'Please check with your site admin.' ) }</SubTitle>

							<div className="import__buttons-group">
								{ onStartBuilding && (
									<NextButton onClick={ onStartBuilding }>{ startBuildingText }</NextButton>
								) }
								{ onBackToStart && (
									<div>
										<BackButton onClick={ onBackToStart }>{ __( 'Back to start' ) }</BackButton>
									</div>
								) }
							</div>
						</>
					) }

					{ type === 'target-site-staging' && (
						<>
							<Title>
								{ __( 'You are not authorized to perform migration on the staging site' ) }
							</Title>

							<div className="import__buttons-group">
								{ onStartBuilding && (
									<NextButton onClick={ onStartBuilding }>{ startBuildingText }</NextButton>
								) }
							</div>
						</>
					) }

					{ type === 'source-site-not-connected' && (
						<>
							<Title>{ __( "We couldn't start the migration" ) }</Title>

							<HintJetpackConnection
								sourceSiteUrl={ sourceSiteUrl || '' }
								targetSiteUrl={ targetSiteUrl || '' }
							/>

							<div className="import__buttons-group">
								{ startImport && (
									<NextButton onClick={ startImport }>{ __( 'Try again' ) }</NextButton>
								) }
							</div>
						</>
					) }

					{ type === 'source-site-not-connected-move-plugin' && (
						<>
							<Title>{ __( "We couldn't start the migration" ) }</Title>

							<HintJetpackConnectionMovePlugin sourceSiteUrl={ sourceSiteUrl || '' } />

							<div className="import__buttons-group">
								{ startImport && (
									<NextButton onClick={ startImport }>{ __( 'Try again' ) }</NextButton>
								) }
							</div>
						</>
					) }
				</div>
			</div>
		</div>
	);
};

export default NotAuthorized;