File size: 4,042 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
import { isEnabled } from '@automattic/calypso-config';
import { CircularProgressBar } from '@automattic/components';
import { Checklist, ChecklistItem, type Task } from '@automattic/launchpad';
import { useTranslate } from 'i18n-calypso';
import { JETPACK_MANAGE_ONBOARDING_TOURS_PREFERENCE_NAME } from 'calypso/jetpack-cloud/sections/onboarding-tours/constants';
import { useDispatch, useSelector } from 'calypso/state';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import { savePreference } from 'calypso/state/preferences/actions';
import { getAllRemotePreferences } from 'calypso/state/preferences/selectors';

import './style.scss';

export default function NextSteps( { onDismiss = () => {} } ) {
	const dispatch = useDispatch();
	const translate = useTranslate();

	const preferences = useSelector( getAllRemotePreferences );

	const checkTourCompletion = ( prefSlug: string ): boolean => {
		if ( preferences && JETPACK_MANAGE_ONBOARDING_TOURS_PREFERENCE_NAME[ prefSlug ] ) {
			return JETPACK_MANAGE_ONBOARDING_TOURS_PREFERENCE_NAME[ prefSlug ] in preferences;
		}
		return false;
	};

	const resetTour = ( prefSlugs: string[] ): void => {
		prefSlugs.forEach( ( slug ) => {
			if ( JETPACK_MANAGE_ONBOARDING_TOURS_PREFERENCE_NAME[ slug ] ) {
				dispatch( savePreference( JETPACK_MANAGE_ONBOARDING_TOURS_PREFERENCE_NAME[ slug ], null ) );
			}
		} );
	};

	const tasks: Task[] = [
		{
			calypso_path: isEnabled( 'jetpack/manage-sites-v2-menu' )
				? '/sites?tour=dashboard-walkthrough'
				: '/dashboard?tour=dashboard-walkthrough',
			completed: checkTourCompletion( 'dashboardWalkthrough' ),
			disabled: false,
			actionDispatch: () => {
				dispatch(
					recordTracksEvent( 'calypso_jetpack_manage_overview_next_steps_get_familiar_click' )
				);
				resetTour( [ 'dashboardWalkthrough' ] );
			},
			id: 'get_familiar',
			title: translate( 'Get familiar with the sites management dashboard' ),
			useCalypsoPath: true,
		},
		{
			calypso_path: isEnabled( 'jetpack/manage-sites-v2-menu' )
				? '/sites?tour=add-new-site'
				: '/dashboard?tour=add-new-site',
			completed: checkTourCompletion( 'addSiteStep1' ),
			disabled: false,
			actionDispatch: () => {
				dispatch(
					recordTracksEvent( 'calypso_jetpack_manage_overview_next_steps_add_sites_click' )
				);
				resetTour( [ 'addSiteStep1', 'addSiteStep2' ] );
			},
			id: 'add_sites',
			title: translate( 'Learn how to add sites' ),
			useCalypsoPath: true,
		},
		{
			calypso_path: '/dashboard?tour=enable-monitor',
			completed: checkTourCompletion( 'enableMonitorStep2' ),
			disabled: false,
			actionDispatch: () => {
				dispatch(
					recordTracksEvent( 'calypso_jetpack_manage_overview_next_steps_bulk_editing_click' )
				);
				resetTour( [ 'enableMonitorStep1', 'enableMonitorStep2' ] );
			},
			id: 'bulk_editing',
			title: translate( 'Learn bulk editing and enabling downtime monitoring' ),
			useCalypsoPath: true,
		},
	];

	const numberOfTasks = tasks.length;
	const completedTasks = tasks.filter( ( task ) => task.completed ).length;

	const isCompleted = completedTasks === numberOfTasks;

	return (
		<div className="next-steps">
			<div className="next-steps__header">
				<h2>{ isCompleted ? translate( '🎉 Congratulations!' ) : translate( 'Next Steps' ) }</h2>
				<CircularProgressBar
					size={ 32 }
					enableDesktopScaling
					numberOfSteps={ numberOfTasks }
					currentStep={ completedTasks }
				/>
			</div>
			{ isCompleted && (
				<p>
					{ translate(
						"Right now there's nothing left for you to do. We'll let you know when anything needs your attention."
					) }{ ' ' }
					<button
						className="dismiss"
						onClick={ () => {
							dispatch(
								recordTracksEvent( 'calypso_jetpack_manage_overview_next_steps_dismiss_click' )
							);
							onDismiss();
						} }
					>
						{ translate( 'Hide' ) }
					</button>
				</p>
			) }
			<Checklist>
				{ tasks.map( ( task ) => (
					<ChecklistItem task={ task } key={ task.id } />
				) ) }
			</Checklist>
		</div>
	);
}