forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next_steps_view.tsx
347 lines (312 loc) · 13.1 KB
/
next_steps_view.tsx
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import classNames from 'classnames';
import {FormattedMessage} from 'react-intl';
import {PreferenceType} from 'mattermost-redux/types/preferences';
import {UserProfile} from 'mattermost-redux/types/users';
import {pageVisited, trackEvent} from 'actions/telemetry_actions';
import Accordion from 'components/accordion';
import Card from 'components/card/card';
import {getAnalyticsCategory} from 'components/next_steps_view/step_helpers';
import {Preferences, RecommendedNextSteps} from 'utils/constants';
import loadingIcon from 'images/spinner-48x48-blue.apng';
import {StepType} from './steps';
import './next_steps_view.scss';
import NextStepsTips from './next_steps_tips';
import OnboardingBgSvg from './images/onboarding-bg-svg';
import GettingStartedSvg from './images/getting-started-svg';
import CloudLogoSvg from './images/cloud-logo-svg';
import OnboardingSuccessSvg from './images/onboarding-success-svg';
const TRANSITION_SCREEN_TIMEOUT = 3000;
type Props = {
currentUser: UserProfile;
preferences: PreferenceType[];
isFirstAdmin: boolean;
steps: StepType[];
actions: {
savePreferences: (userId: string, preferences: PreferenceType[]) => void;
setShowNextStepsView: (show: boolean) => void;
closeRightHandSide: () => void;
getProfiles: () => void;
};
};
type State = {
showFinalScreen: boolean;
showTransitionScreen: boolean;
animating: boolean;
show: boolean;
}
export default class NextStepsView extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
showFinalScreen: false,
showTransitionScreen: false,
animating: false,
show: false,
};
}
async componentDidMount() {
await this.props.actions.getProfiles();
// If all steps are complete, or user has skipped, don't render this and skip to the tips screen
if (this.getIncompleteStep() === null || this.checkStepsSkipped()) {
this.showFinalScreenNoAnimation();
}
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({show: true});
pageVisited(getAnalyticsCategory(this.props.isFirstAdmin), 'pageview_welcome');
this.props.actions.closeRightHandSide();
}
checkStepsSkipped = () => {
return this.props.preferences.some((pref) => pref.name === RecommendedNextSteps.SKIP && pref.value === 'true');
}
getStartingStep = () => {
for (let i = 0; i < this.props.steps.length; i++) {
if (!this.isStepComplete(this.props.steps[i].id)) {
return this.props.steps[i].id;
}
}
return this.props.steps[0].id;
}
getIncompleteStep = () => {
for (let i = 0; i < this.props.steps.length; i++) {
if (!this.isStepComplete(this.props.steps[i].id)) {
return this.props.steps[i].id;
}
}
return null;
}
onClickHeader = (setExpanded: (expandedKey: string) => void, id: string) => {
const stepIndex = this.getStepNumberFromId(id);
trackEvent(getAnalyticsCategory(this.props.isFirstAdmin), `click_onboarding_step${stepIndex}`);
setExpanded(id);
}
getStepNumberFromId = (id: string) => {
return this.props.steps.findIndex((step) => step.id === id) + 1;
}
onSkip = (setExpanded: (expandedKey: string) => void) => {
return (id: string) => {
this.nextStep(setExpanded, id);
};
}
onSkipAll = async () => {
this.showFinalScreen();
this.props.actions.savePreferences(this.props.currentUser.id, [{
user_id: this.props.currentUser.id,
category: Preferences.RECOMMENDED_NEXT_STEPS,
name: RecommendedNextSteps.SKIP,
value: 'true',
}]);
}
onFinish = (setExpanded: (expandedKey: string) => void) => {
return async (id: string) => {
const stepIndex = this.getStepNumberFromId(id);
trackEvent(getAnalyticsCategory(this.props.isFirstAdmin), `complete_onboarding_step${stepIndex}`);
await this.props.actions.savePreferences(this.props.currentUser.id, [{
category: Preferences.RECOMMENDED_NEXT_STEPS,
user_id: this.props.currentUser.id,
name: id,
value: 'true',
}]);
this.nextStep(setExpanded, id);
};
}
showFinalScreenNoAnimation = () => {
pageVisited(getAnalyticsCategory(this.props.isFirstAdmin), 'pageview_tips_next_steps');
this.setState({showFinalScreen: true, animating: false});
}
showFinalScreen = () => {
trackEvent(getAnalyticsCategory(this.props.isFirstAdmin), 'click_skip_getting_started', {channel_sidebar: false});
pageVisited(getAnalyticsCategory(this.props.isFirstAdmin), 'pageview_tips_next_steps');
this.setState({showFinalScreen: true, animating: true});
}
transitionToFinalScreen = () => {
this.setState({showTransitionScreen: true, animating: true});
}
setTimerToFinalScreen = () => {
if (this.state.showTransitionScreen) {
setTimeout(() => {
pageVisited(getAnalyticsCategory(this.props.isFirstAdmin), 'pageview_tips_next_steps');
this.setState({showFinalScreen: true});
}, TRANSITION_SCREEN_TIMEOUT);
}
}
stopAnimating = () => {
this.setState({animating: false});
}
nextStep = (setExpanded: (expandedKey: string) => void, id: string) => {
const currentIndex = this.props.steps.findIndex((step) => step.id === id);
if (currentIndex + 1 > this.props.steps.length - 1) {
// Check if previous steps were skipped before moving on
const incompleteStep = this.getIncompleteStep();
if (incompleteStep === null) {
// Collapse all accordion tiles
setExpanded('');
setTimeout(() => {
this.transitionToFinalScreen();
}, 300);
} else {
setExpanded(incompleteStep);
}
} else if (this.isStepComplete(this.props.steps[currentIndex + 1].id)) {
this.nextStep(setExpanded, this.props.steps[currentIndex + 1].id);
} else {
setExpanded(this.props.steps[currentIndex + 1].id);
}
}
isStepComplete = (id: string) => {
return this.props.preferences.some((pref) => pref.name === id && pref.value === 'true');
}
renderStep = (step: StepType, index: number) => {
const {id, title} = step;
let icon = (
<div className='NextStepsView__cardHeaderBadge'>
<span>{index + 1}</span>
</div>
);
if (this.isStepComplete(id)) {
icon = (
<i className='icon icon-check-circle'/>
);
}
return (setExpanded: (expandedKey: string) => void, expandedKey: string) => (
<Card
className={classNames({complete: this.isStepComplete(id)})}
expanded={expandedKey === id}
>
<Card.Header>
<button
onClick={() => this.onClickHeader(setExpanded, id)}
disabled={this.isStepComplete(id)}
className='NextStepsView__cardHeader'
>
{icon}
<span>{title}</span>
</button>
</Card.Header>
<Card.Body>
<step.component
id={id}
expanded={expandedKey === id}
isAdmin={this.props.isFirstAdmin}
currentUser={this.props.currentUser}
onFinish={this.onFinish(setExpanded)}
onSkip={this.onSkip(setExpanded)}
/>
</Card.Body>
</Card>
);
}
renderTransitionScreen = () => {
return (
<div
className={classNames('NextStepsView__viewWrapper NextStepsView__transitionView', {
transitioning: this.state.showTransitionScreen,
completed: this.state.showTransitionScreen && this.state.showFinalScreen,
animating: this.state.animating,
})}
onTransitionEnd={this.setTimerToFinalScreen}
>
<div className='NextStepsView__transitionBody'>
<OnboardingSuccessSvg/>
<h1 className='NextStepsView__transitionTopText'>
<FormattedMessage
id='next_steps_view.nicelyDone'
defaultMessage='Nicely done! You’re all set.'
/>
</h1>
<h2 className='NextStepsView__transitionBottomText'>
<img src={loadingIcon}/>
<FormattedMessage
id='next_steps_view.oneMoment'
defaultMessage='One moment'
/>
</h2>
</div>
</div>
);
}
renderMainBody = () => {
const renderedSteps = this.props.steps.map(this.renderStep);
return (
<div
className={classNames('NextStepsView__viewWrapper NextStepsView__mainView', {
completed: this.state.showFinalScreen || this.state.showTransitionScreen,
animating: this.state.animating,
})}
>
<header className='NextStepsView__header'>
<div className='NextStepsView__header-headerText'>
<h1 className='NextStepsView__header-headerTopText'>
<FormattedMessage
id='next_steps_view.welcomeToMattermost'
defaultMessage='Welcome to Mattermost'
/>
</h1>
<h2 className='NextStepsView__header-headerBottomText'>
<FormattedMessage
id='next_steps_view.hereAreSomeNextSteps'
defaultMessage='Here are some recommended next steps to help you get started'
/>
</h2>
</div>
<div className='NextStepsView__header-logo'>
<CloudLogoSvg/>
</div>
</header>
<div className='NextStepsView__body'>
<div className='NextStepsView__body-main'>
<Accordion defaultExpandedKey={this.getIncompleteStep() === null ? '' : this.getStartingStep()}>
{(setExpanded, expandedKey) => {
return (
<>
{renderedSteps.map((step) => step(setExpanded, expandedKey))}
</>
);
}}
</Accordion>
<div className='NextStepsView__skipGettingStarted'>
<button
className='NextStepsView__button tertiary'
onClick={this.onSkipAll}
>
<FormattedMessage
id='next_steps_view.skipGettingStarted'
defaultMessage='Skip Getting Started'
/>
</button>
</div>
</div>
<div className='NextStepsView__body-graphic'>
<GettingStartedSvg/>
</div>
</div>
</div>
);
}
render() {
return (
<section
id='app-content'
className='app__content NextStepsView'
>
{this.state.show &&
<>
<OnboardingBgSvg/>
{this.renderMainBody()}
{this.renderTransitionScreen()}
<NextStepsTips
showFinalScreen={this.state.showFinalScreen}
animating={this.state.animating}
stopAnimating={this.stopAnimating}
isFirstAdmin={this.props.isFirstAdmin}
savePreferences={this.props.actions.savePreferences}
currentUserId={this.props.currentUser.id}
setShowNextStepsView={this.props.actions.setShowNextStepsView}
/>
</>}
</section>
);
}
}