/
App.js
405 lines (379 loc) · 13.9 KB
/
App.js
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import React, { Component } from 'react';
import { Switch, Route } from 'react-router-dom';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { StylesProvider } from '@material-ui/styles';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { ThemeProvider as MuiThemeProvider } from '@material-ui/core/styles';
import { theme } from './MUItheme';
import VerifyAccount from './components/Auth/VerifyAccount/VerifyAccount';
import ChatApp from './components/ChatApp/ChatApp.react';
import Contact from './components/About/Contact/Contact.react';
import Devices from './components/About/Devices';
import Logout from './components/Auth/Logout';
import NotFound from './components/NotFound/NotFound.react';
import Overview from './components/About/Overview';
import Settings from './components/Settings/Settings.react';
import Support from './components/About/Support';
import Team from './components/About/Team';
import Terms from './components/About/Terms/Terms.react';
import Privacy from './components/About/Privacy/Privacy.react';
import appActions from './redux/actions/app';
import uiActions from './redux/actions/ui';
import ProtectedRoute from './components/shared/ProtectedRoute';
import DeviceProtectedRoute from './components/shared/DeviceProtectedRoute';
import DialogSection from '../src/components/shared/Dialog';
import settingActions from './redux/actions/settings';
import BrowseSkill from './components/cms/BrowseSkill/BrowseSkill';
import BrowseSkillByCategory from './components/cms/BrowseSkill/BrowseSkillByCategory';
import BrowseSkillByLanguage from './components/cms/BrowseSkill/BrowseSkillByLanguage';
import SkillListing from './components/cms/SkillPage/SkillListing';
import SkillFeedbackPage from './components/cms/SkillFeedbackPage/SkillFeedbackPage';
import Dashboard from './components/cms/Dashboard';
import SkillVersion from './components/cms/SkillVersion/SkillVersion';
import SkillHistory from './components/cms/SkillHistory/SkillHistory';
import SkillRollBack from './components/cms/SkillRollBack/SkillRollBack';
import SkillWizard from './components/cms/SkillCreator/SkillWizard';
import BotBuilderWrap from './components/cms/BotBuilder/BotBuilderWrap';
import NavigationBar from './components/NavigationBar';
import Footer from './components/Footer/Footer.react';
import CookiePolicy from './components/CookiePolicy/CookiePolicy.react';
import Admin from './components/Admin/Admin';
import CustomSnackbar from './components/shared/CustomSnackbar';
import AppBanner from './components/shared/AppBanner';
import DeviceSetupPage from './components/smart-speaker/Setup';
import ConfigureSpeaker from './components/smart-speaker/Configure';
import ScrollTopButton from './components/shared/ScrollTopButton';
import withTracker from './withTracker';
import GoogleAnalytics from 'react-ga';
import { isProduction } from './utils/helperFunctions';
import { checkDeviceWiFiAccessPoint, fetchActiveDeviceMacId } from './apis';
const RootContainer = styled.div`
min-height: calc(100vh - 120px);
margin-top: 50px;
`;
const EnhancedBrowseSkill = withTracker(BrowseSkill);
const EnhancedBrowseSkillByCategory = withTracker(BrowseSkillByCategory);
const EnhancedBrowseSkillByLanguage = withTracker(BrowseSkillByLanguage);
const EnhancedSkillListing = withTracker(SkillListing);
const EnhancedSkillFeedbackPage = withTracker(SkillFeedbackPage);
const EnhancedDashboard = withTracker(Dashboard);
const EnhancedSkillVersion = withTracker(SkillVersion);
const EnhancedSkillHistory = withTracker(SkillHistory);
const EnhancedSkillRollBack = withTracker(SkillRollBack);
const EnhancedSkillWizard = withTracker(SkillWizard);
const EnhancedBotBuilderWrap = withTracker(BotBuilderWrap);
const EnhancedOverview = withTracker(Overview);
const EnhancedDevices = withTracker(Devices);
const EnhancedTeam = withTracker(Team);
const EnhancedContact = withTracker(Contact);
const EnhancedSupport = withTracker(Support);
const EnhancedConfigureSpeaker = withTracker(ConfigureSpeaker);
const EnhancedTerms = withTracker(Terms);
const EnhancedPrivacy = withTracker(Privacy);
const EnhancedVerifyAccount = withTracker(VerifyAccount);
const EnhancedSettings = withTracker(Settings);
const EnhancedNotFound = withTracker(NotFound);
class App extends Component {
static propTypes = {
history: PropTypes.object,
location: PropTypes.object,
actions: PropTypes.object,
accessToken: PropTypes.string,
snackBarProps: PropTypes.object,
showCookiePolicy: PropTypes.bool,
modalProps: PropTypes.object,
visited: PropTypes.bool,
isLocalEnv: PropTypes.bool,
mode: PropTypes.string,
};
state = {
activeDeviceMacId: '',
deviceAccessPoint: false,
};
componentDidMount = async () => {
const { accessToken, actions, isLocalEnv } = this.props;
if (!isLocalEnv) {
this.setState({ deviceAccessPoint: false });
} else {
try {
let payload = await fetchActiveDeviceMacId();
this.setState({ activeDeviceMacId: payload.macid });
} catch (error) {
console.log(error, 'error');
}
try {
let payload = await checkDeviceWiFiAccessPoint();
this.setState({ deviceAccessPoint: payload.status === 'true' });
} catch (error) {
console.log('Error, catched', error);
this.setState({ deviceAccessPoint: false });
}
}
let isGAInitialised = false;
window.addEventListener('offline', this.onUserOffline);
window.addEventListener('online', this.onUserOnline);
let { payload } = await actions.getApiKeys();
const {
keys: { googleAnalyticsKey = null },
} = payload;
if (accessToken && !isProduction()) {
let { payload } = await actions.getApiKeys({ apiType: 'user' });
const userKeys = payload.keys;
if (userKeys && userKeys.googleAnalyticsKey) {
isGAInitialised = true;
userKeys.googleAnalyticsKey &&
GoogleAnalytics.initialize(userKeys.googleAnalyticsKey);
}
}
if (!isGAInitialised) {
googleAnalyticsKey && GoogleAnalytics.initialize(googleAnalyticsKey);
}
actions.getCaptchaConfig();
if (accessToken) {
actions.getAdmin();
actions.getUserSettings().catch((e) => {
console.log(e);
});
}
};
componentWillUnmount = () => {
window.removeEventListener('offline', this.onUserOffline);
window.removeEventListener('online', this.onUserOnline);
};
onUserOffline = () => {
const { actions } = this.props;
actions.openSnackBar({
snackBarMessage: 'It seems you are offline!',
});
};
onUserOnline = () => {
const { actions } = this.props;
actions.openSnackBar({
snackBarMessage: 'Welcome back!',
});
};
render() {
const {
actions,
snackBarProps: {
snackBarMessage,
isSnackBarOpen,
snackBarDuration,
snackBarPosition,
variant,
},
modalProps: { isModalOpen },
location: { pathname },
showCookiePolicy,
isLocalEnv,
mode,
location,
// visited,
} = this.props;
const { deviceAccessPoint, activeDeviceMacId } = this.state;
const renderFooterPagesList = [
deviceAccessPoint ? null : '/',
'/about',
'/team',
'/devices',
'/support',
'/privacy',
'/terms',
'/contact',
];
const hideBubble = [
'skillWizard',
'botWizard',
'admin',
'edit',
deviceAccessPoint ? '' : null,
];
const skillListRegex = new RegExp('^/');
const pathLength = pathname.split('/').length;
const renderAppBanner = isLocalEnv ? (
<AppBanner macId={activeDeviceMacId} />
) : null;
const renderAppBar =
pathname !== '/chat' && !deviceAccessPoint ? <NavigationBar /> : null;
const renderFooter =
((skillListRegex.test(pathname) && pathLength > 2 && pathLength <= 4) ||
renderFooterPagesList.includes(pathname)) &&
!pathname.includes('/admin/') ? (
<Footer />
) : null;
const renderCookiePolicy =
showCookiePolicy === true ? <CookiePolicy /> : null;
// const renderDialog = isModalOpen || !visited ? <DialogSection /> : null;
const renderDialog =
isModalOpen ||
mode === 'fullScreen' ||
location.pathname === '/resetpass' ? (
<DialogSection />
) : null;
const renderChatBubble =
hideBubble.includes(location.pathname.split('/')[1]) ||
(hideBubble.includes(location.pathname.split('/')[3]) &&
deviceAccessPoint) ? null : (
<ChatApp />
);
return (
<StylesProvider injectFirst>
<MuiThemeProvider theme={theme}>
<div>
{renderDialog}
{isSnackBarOpen && (
<CustomSnackbar
autoHideDuration={snackBarDuration}
open={isSnackBarOpen}
message={snackBarMessage}
onClose={actions.closeSnackBar}
anchorOrigin={snackBarPosition}
variant={variant}
/>
)}
{renderAppBar}
{renderAppBanner}
{renderChatBubble}
<ScrollTopButton />
<RootContainer>
<Switch>
{!deviceAccessPoint ? (
<Route exact path="/" component={EnhancedBrowseSkill} />
) : (
<Route exact path="/" component={DeviceSetupPage} />
)}
<Route
exact
path="/resetPass"
component={EnhancedBrowseSkill}
/>
<Route
exact
path="/category/:category"
component={EnhancedBrowseSkillByCategory}
/>
<Route
exact
path="/language/:language"
component={EnhancedBrowseSkillByLanguage}
/>
<Route
exact
path="/:category/:skills/:lang"
component={EnhancedSkillListing}
/>
<Route
exact
path="/:category/:skills/:lang/feedbacks"
component={EnhancedSkillFeedbackPage}
/>
<ProtectedRoute
exact
path="/dashboard/"
component={EnhancedDashboard}
/>
<Route
exact
path="/:category/:skill/versions/:lang"
component={EnhancedSkillVersion}
/>
<Route
exact
path="/:category/:skill/compare/:lang/:oldid/:recentid"
component={EnhancedSkillHistory}
/>
<Route
exact
path="/:category/:skill/edit/:lang/:latestid/:revertid"
component={EnhancedSkillRollBack}
/>
<DeviceProtectedRoute
exact
path="/:category/:skill/edit/:lang"
component={EnhancedSkillWizard}
/>
<DeviceProtectedRoute
exact
path="/:category/:skill/edit/:lang/:commit"
component={EnhancedSkillWizard}
/>
<ProtectedRoute
exact
path="/myskills"
component={EnhancedDashboard}
/>
<ProtectedRoute
path="/mydevices"
component={EnhancedDashboard}
/>
<ProtectedRoute
exact
path="/skillWizard"
component={EnhancedSkillWizard}
/>
<ProtectedRoute
path="/botWizard"
component={EnhancedBotBuilderWrap}
/>
<Route
path="/configure-speaker"
component={EnhancedConfigureSpeaker}
/>
<ProtectedRoute path="/mybots" component={EnhancedDashboard} />
<Route exact path="/about" component={EnhancedOverview} />
<Route exact path="/devices" component={EnhancedDevices} />
<Route exact path="/team" component={EnhancedTeam} />
<Route exact path="/contact" component={EnhancedContact} />
<Route exact path="/support" component={EnhancedSupport} />
<Route exact path="/terms" component={EnhancedTerms} />
<Route exact path="/privacy" component={EnhancedPrivacy} />
<Route
exact
path="/verify-account"
component={EnhancedVerifyAccount}
/>
<Route exact path="/logout" component={Logout} />
<Route path="/admin" component={Admin} />
<ProtectedRoute
exact
path="/settings"
component={EnhancedSettings}
/>
<Route
exact
path="/*:path(error-404|)"
component={EnhancedNotFound}
/>
</Switch>
</RootContainer>
<div>{renderFooter}</div>
{renderCookiePolicy}
</div>
</MuiThemeProvider>
</StylesProvider>
);
}
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(
{ ...appActions, ...uiActions, ...settingActions },
dispatch,
),
};
}
function mapStateToProps(store) {
return {
...store.router,
...store.ui,
accessToken: store.app.accessToken,
showCookiePolicy: store.app.showCookiePolicy,
visited: store.app.visited,
isLocalEnv: store.app.isLocalEnv,
googleAnalyticsKey: store.app.apiKeys.googleAnalyticsKey,
mode: store.ui.mode,
};
}
export default connect(mapStateToProps, mapDispatchToProps)(App);