-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
68 lines (62 loc) · 1.66 KB
/
App.jsx
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
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
import React from 'react';
import { connect } from 'react-redux';
import { string, func } from 'prop-types';
import ConnectionStatus from './components/ConnectionStatus';
import IdleView from './components/views/IdleView';
import ManualActivationView from './components/views/ManualActivationView';
import { manualActivation as manualActivationAction } from './redux/actions/activation';
import { viewTypes } from './redux/reducers/viewReducer';
import TwentyFourHourView from './components/views/24HourView';
const getView = currentView => {
switch (currentView) {
case viewTypes.idle:
return <IdleView />;
case viewTypes.manualActivation:
return <ManualActivationView />;
case viewTypes.twentyFourView:
return <TwentyFourHourView />;
default:
return null;
}
};
const App = ({ currentView, manualActivation }) => {
const view = getView(currentView);
const trigger = e => {
e.preventDefault();
if (currentView === 'idle') {
manualActivation();
}
};
return (
<>
<div
className="openbot-container"
onClick={trigger}
onKeyPress={trigger}
role="main"
>
{view}
<ConnectionStatus />
</div>
</>
);
};
App.propTypes = {
currentView: string.isRequired,
manualActivation: func.isRequired,
};
const mapStateToProps = state => {
return {
currentView: state.views.currentView,
};
};
const mapDispatchToProps = dispatch => {
return {
manualActivation: () => dispatch(manualActivationAction()),
};
};
export default connect(
mapStateToProps,
mapDispatchToProps,
)(App);