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
|
// @flow
import Avatar from '@atlaskit/avatar';
import FieldText from '@atlaskit/field-text';
import ArrowLeft from '@atlaskit/icon/glyph/arrow-left';
import { AkCustomDrawer } from '@atlaskit/navigation';
import { SpotlightTarget } from '@atlaskit/onboarding';
import Panel from '@atlaskit/panel';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import type { Dispatch } from 'redux';
import { closeDrawer, DrawerContainer, Logo } from '../../navbar';
import { Onboarding, startOnboarding } from '../../onboarding';
import { AvatarContainer, SettingsContainer, TogglesContainer } from '../styled';
import { setEmail, setName } from '../actions';
import AlwaysOnTopWindowToggle from './AlwaysOnTopWindowToggle';
import ServerURLField from './ServerURLField';
import ServerTimeoutField from './ServerTimeoutField';
import StartMutedToggles from './StartMutedToggles';
type Props = {
/**
* Redux dispatch.
*/
dispatch: Dispatch<*>;
/**
* Is the drawer open or not.
*/
isOpen: boolean;
/**
* Avatar URL.
*/
_avatarURL: string;
/**
* Email of the user.
*/
_email: string;
/**
* Name of the user.
*/
_name: string;
};
/**
* Drawer that open when SettingsAction is clicked.
*/
class SettingsDrawer extends Component<Props, *> {
/**
* Initializes a new {@code SettingsDrawer} instance.
*
* @inheritdoc
*/
constructor(props) {
super(props);
this._onBackButton = this._onBackButton.bind(this);
this._onEmailBlur = this._onEmailBlur.bind(this);
this._onEmailFormSubmit = this._onEmailFormSubmit.bind(this);
this._onNameBlur = this._onNameBlur.bind(this);
this._onNameFormSubmit = this._onNameFormSubmit.bind(this);
}
/**
* Start Onboarding once component is mounted.
*
* NOTE: It automatically checks if the onboarding is shown or not.
*
* @param {Props} prevProps - Props before component updated.
* @returns {void}
*/
componentDidUpdate(prevProps: Props) {
if (!prevProps.isOpen && this.props.isOpen) {
// TODO - Find a better way for this.
// Delay for 300ms to let drawer open.
setTimeout(() => {
this.props.dispatch(startOnboarding('settings-drawer'));
}, 300);
}
}
/**
* Render function of component.
*
* @returns {ReactElement}
*/
render() {
return (
<AkCustomDrawer
backIcon = { <ArrowLeft label = 'Back' /> }
isOpen = { this.props.isOpen }
onBackButton = { this._onBackButton }
primaryIcon = { <Logo /> } >
<DrawerContainer>
<SettingsContainer>
<AvatarContainer>
<Avatar
size = 'xlarge'
src = { this.props._avatarURL } />
</AvatarContainer>
<SpotlightTarget
name = 'name-setting'>
<form onSubmit = { this._onNameFormSubmit }>
<FieldText
label = 'Name'
onBlur = { this._onNameBlur }
shouldFitContainer = { true }
type = 'text'
value = { this.props._name } />
</form>
</SpotlightTarget>
<SpotlightTarget
name = 'email-setting'>
<form onSubmit = { this._onEmailFormSubmit }>
<FieldText
label = 'Email'
onBlur = { this._onEmailBlur }
shouldFitContainer = { true }
type = 'text'
value = { this.props._email } />
</form>
</SpotlightTarget>
<SpotlightTarget
name = 'server-setting'>
<ServerURLField />
</SpotlightTarget>
<TogglesContainer>
<SpotlightTarget
name = 'start-muted-toggles'>
<StartMutedToggles />
</SpotlightTarget>
<SpotlightTarget
name = 'always-on-top-window'>
<AlwaysOnTopWindowToggle />
</SpotlightTarget>
</TogglesContainer>
<Panel header = 'Advanced Settings'>
<ServerTimeoutField />
</Panel>
<Onboarding section = 'settings-drawer' />
</SettingsContainer>
</DrawerContainer>
</AkCustomDrawer>
);
}
_onBackButton: (*) => void;
/**
* Closes the drawer when back button is clicked.
*
* @returns {void}
*/
_onBackButton() {
this.props.dispatch(closeDrawer());
}
_onEmailBlur: (*) => void;
/**
* Updates Avatar URL in (redux) state when email is updated.
*
* @param {SyntheticInputEvent<HTMLInputElement>} event - Event by which
* this function is called.
* @returns {void}
*/
_onEmailBlur(event: SyntheticInputEvent<HTMLInputElement>) {
this.props.dispatch(setEmail(event.currentTarget.value));
}
_onEmailFormSubmit: (*) => void;
/**
* Prevents submission of the form and updates email.
*
* @param {SyntheticEvent<HTMLFormElement>} event - Event by which
* this function is called.
* @returns {void}
*/
_onEmailFormSubmit(event: SyntheticEvent<HTMLFormElement>) {
event.preventDefault();
// $FlowFixMe
this.props.dispatch(setEmail(event.currentTarget.elements[0].value));
}
_onNameBlur: (*) => void;
/**
* Updates Avatar URL in (redux) state when name is updated.
*
* @param {SyntheticInputEvent<HTMLInputElement>} event - Event by which
* this function is called.
* @returns {void}
*/
_onNameBlur(event: SyntheticInputEvent<HTMLInputElement>) {
this.props.dispatch(setName(event.currentTarget.value));
}
_onNameFormSubmit: (*) => void;
/**
* Prevents submission of the form and updates name.
*
* @param {SyntheticEvent<HTMLFormElement>} event - Event by which
* this function is called.
* @returns {void}
*/
_onNameFormSubmit(event: SyntheticEvent<HTMLFormElement>) {
event.preventDefault();
// $FlowFixMe
this.props.dispatch(setName(event.currentTarget.elements[0].value));
}
}
/**
* Maps (parts of) the redux state to the React props.
*
* @param {Object} state - The redux state.
* @returns {{
* _avatarURL: string,
* _email: string,
* _name: string
* }}
*/
function _mapStateToProps(state: Object) {
return {
_avatarURL: state.settings.avatarURL,
_email: state.settings.email,
_name: state.settings.name
};
}
export default connect(_mapStateToProps)(SettingsDrawer);
|