Browse Source

auth: fix rendering error and progress messages

Also removed some no longer used styles.
j8
Saúl Ibarra Corretgé 5 years ago
parent
commit
36455c24c8

+ 77
- 50
react/features/authentication/components/LoginDialog.native.js View File

5
 import { connect as reduxConnect } from 'react-redux';
5
 import { connect as reduxConnect } from 'react-redux';
6
 import type { Dispatch } from 'redux';
6
 import type { Dispatch } from 'redux';
7
 
7
 
8
+import { ColorSchemeRegistry } from '../../base/color-scheme';
8
 import { toJid } from '../../base/connection';
9
 import { toJid } from '../../base/connection';
9
 import { connect } from '../../base/connection/actions.native';
10
 import { connect } from '../../base/connection/actions.native';
10
 import {
11
 import {
19
 import type { StyleType } from '../../base/styles';
20
 import type { StyleType } from '../../base/styles';
20
 
21
 
21
 import { authenticateAndUpgradeRole, cancelLogin } from '../actions';
22
 import { authenticateAndUpgradeRole, cancelLogin } from '../actions';
22
-import styles from './styles';
23
+
24
+// Register styles.
25
+import './styles';
23
 
26
 
24
 /**
27
 /**
25
  * The type of the React {@link Component} props of {@link LoginDialog}.
28
  * The type of the React {@link Component} props of {@link LoginDialog}.
58
      */
61
      */
59
     _progress: number,
62
     _progress: number,
60
 
63
 
64
+    /**
65
+     * The color-schemed stylesheet of this feature.
66
+     */
67
+    _styles: StyleType,
68
+
61
     /**
69
     /**
62
      * Redux store dispatch method.
70
      * Redux store dispatch method.
63
      */
71
      */
144
         const {
152
         const {
145
             _connecting: connecting,
153
             _connecting: connecting,
146
             _dialogStyles,
154
             _dialogStyles,
155
+            _styles: styles,
156
+            t
157
+        } = this.props;
158
+
159
+        return (
160
+            <CustomSubmitDialog
161
+                okDisabled = { connecting }
162
+                onCancel = { this._onCancel }
163
+                onSubmit = { this._onLogin }>
164
+                <View style = { styles.loginDialog }>
165
+                    <TextInput
166
+                        autoCapitalize = { 'none' }
167
+                        autoCorrect = { false }
168
+                        onChangeText = { this._onUsernameChange }
169
+                        placeholder = { 'user@domain.com' }
170
+                        placeholderTextColor = { PLACEHOLDER_COLOR }
171
+                        style = { _dialogStyles.field }
172
+                        underlineColorAndroid = { FIELD_UNDERLINE }
173
+                        value = { this.state.username } />
174
+                    <TextInput
175
+                        onChangeText = { this._onPasswordChange }
176
+                        placeholder = { t('dialog.userPassword') }
177
+                        placeholderTextColor = { PLACEHOLDER_COLOR }
178
+                        secureTextEntry = { true }
179
+                        style = { [
180
+                            _dialogStyles.field,
181
+                            inputDialogStyle.bottomField
182
+                        ] }
183
+                        underlineColorAndroid = { FIELD_UNDERLINE }
184
+                        value = { this.state.password } />
185
+                    { this._renderMessage() }
186
+                </View>
187
+            </CustomSubmitDialog>
188
+        );
189
+    }
190
+
191
+    /**
192
+     * Renders an optional message, if applicable.
193
+     *
194
+     * @returns {ReactElement}
195
+     * @private
196
+     */
197
+    _renderMessage() {
198
+        const {
199
+            _connecting: connecting,
147
             _error: error,
200
             _error: error,
148
             _progress: progress,
201
             _progress: progress,
202
+            _styles: styles,
149
             t
203
             t
150
         } = this.props;
204
         } = this.props;
151
 
205
 
152
         let messageKey;
206
         let messageKey;
207
+        let messageIsError = false;
153
         const messageOptions = {};
208
         const messageOptions = {};
154
 
209
 
155
         if (progress && progress < 1) {
210
         if (progress && progress < 1) {
170
                                 this.props._configHosts)
225
                                 this.props._configHosts)
171
                         && credentials.password === this.state.password) {
226
                         && credentials.password === this.state.password) {
172
                     messageKey = 'dialog.incorrectPassword';
227
                     messageKey = 'dialog.incorrectPassword';
228
+                    messageIsError = true;
173
                 }
229
                 }
174
             } else if (name) {
230
             } else if (name) {
175
                 messageKey = 'dialog.connectErrorWithMsg';
231
                 messageKey = 'dialog.connectErrorWithMsg';
176
                 messageOptions.msg = `${name} ${error.message}`;
232
                 messageOptions.msg = `${name} ${error.message}`;
233
+                messageIsError = true;
177
             }
234
             }
235
+        } else if (connecting) {
236
+            messageKey = 'connection.CONNECTING';
178
         }
237
         }
179
 
238
 
180
-        const showMessage = messageKey || connecting;
181
-        const message = messageKey
182
-            ? t(messageKey, messageOptions)
183
-            : connecting
184
-                ? t('connection.CONNECTING')
185
-                : '';
239
+        if (messageKey) {
240
+            const message = t(messageKey, messageOptions);
241
+            const messageStyles = [
242
+                styles.dialogText,
243
+                messageIsError ? styles.errorMessage : styles.progressMessage
244
+            ];
245
+
246
+            return (
247
+                <Text style = { messageStyles }>
248
+                    { message }
249
+                </Text>
250
+            );
251
+        }
186
 
252
 
187
-        return (
188
-            <CustomSubmitDialog
189
-                okDisabled = { connecting }
190
-                onCancel = { this._onCancel }
191
-                onSubmit = { this._onLogin }>
192
-                <View style = { styles.loginDialog }>
193
-                    <TextInput
194
-                        autoCapitalize = { 'none' }
195
-                        autoCorrect = { false }
196
-                        onChangeText = { this._onUsernameChange }
197
-                        placeholder = { 'user@domain.com' }
198
-                        placeholderTextColor = { PLACEHOLDER_COLOR }
199
-                        style = { _dialogStyles.field }
200
-                        underlineColorAndroid = { FIELD_UNDERLINE }
201
-                        value = { this.state.username } />
202
-                    <TextInput
203
-                        onChangeText = { this._onPasswordChange }
204
-                        placeholder = { t('dialog.userPassword') }
205
-                        placeholderTextColor = { PLACEHOLDER_COLOR }
206
-                        secureTextEntry = { true }
207
-                        style = { [
208
-                            _dialogStyles.field,
209
-                            inputDialogStyle.bottomField
210
-                        ] }
211
-                        underlineColorAndroid = { FIELD_UNDERLINE }
212
-                        value = { this.state.password } />
213
-                    { showMessage && (
214
-                        <Text style = { styles.dialogText }>
215
-                            { message }
216
-                        </Text>
217
-                    ) }
218
-                </View>
219
-            </CustomSubmitDialog>
220
-        );
253
+        return null;
221
     }
254
     }
222
 
255
 
223
     _onUsernameChange: (string) => void;
256
     _onUsernameChange: (string) => void;
295
  *
328
  *
296
  * @param {Object} state - The Redux state.
329
  * @param {Object} state - The Redux state.
297
  * @private
330
  * @private
298
- * @returns {{
299
- *     _conference: JitsiConference,
300
- *     _configHosts: Object,
301
- *     _connecting: boolean,
302
- *     _dialogStyles: StyleType,
303
- *     _error: Object,
304
- *     _progress: number
305
- * }}
331
+ * @returns {Props}
306
  */
332
  */
307
 function _mapStateToProps(state) {
333
 function _mapStateToProps(state) {
308
     const {
334
     const {
323
         _configHosts: configHosts,
349
         _configHosts: configHosts,
324
         _connecting: Boolean(connecting) || Boolean(thenableWithCancel),
350
         _connecting: Boolean(connecting) || Boolean(thenableWithCancel),
325
         _error: connectionError || authenticateAndUpgradeRoleError,
351
         _error: connectionError || authenticateAndUpgradeRoleError,
326
-        _progress: progress
352
+        _progress: progress,
353
+        _styles: ColorSchemeRegistry.get(state, 'LoginDialog')
327
     };
354
     };
328
 }
355
 }
329
 
356
 

+ 16
- 25
react/features/authentication/components/styles.js View File

1
-import { BoxModel, ColorPalette, createStyleSheet } from '../../base/styles';
2
-
3
-/**
4
- * The style common to {@code LoginDialog} and {@code WaitForOwnerDialog}.
5
- */
6
-const dialog = {
7
-    marginBottom: BoxModel.margin,
8
-    marginTop: BoxModel.margin
9
-};
10
-
11
-/**
12
- * The style common to {@code Text} rendered by {@code LoginDialog} and
13
- * {@code WaitForOwnerDialog}.
14
- */
15
-const text = {
16
-    color: ColorPalette.white
17
-};
1
+import { ColorSchemeRegistry, schemeColor } from '../../base/color-scheme';
2
+import { BoxModel } from '../../base/styles';
18
 
3
 
19
 /**
4
 /**
20
  * The styles of the authentication feature.
5
  * The styles of the authentication feature.
21
  */
6
  */
22
-export default createStyleSheet({
7
+ColorSchemeRegistry.register('LoginDialog', {
23
 
8
 
24
     /**
9
     /**
25
      * The style of {@code Text} rendered by the {@code Dialog}s of the
10
      * The style of {@code Text} rendered by the {@code Dialog}s of the
26
      * feature authentication.
11
      * feature authentication.
27
      */
12
      */
28
     dialogText: {
13
     dialogText: {
29
-        ...text,
30
         margin: BoxModel.margin,
14
         margin: BoxModel.margin,
31
         marginTop: BoxModel.margin * 2
15
         marginTop: BoxModel.margin * 2
32
     },
16
     },
33
 
17
 
18
+    /**
19
+     * The style used when an error message is rendered.
20
+     */
21
+    errorMessage: {
22
+        color: schemeColor('errorText')
23
+    },
24
+
34
     /**
25
     /**
35
      * The style of {@code LoginDialog}.
26
      * The style of {@code LoginDialog}.
36
      */
27
      */
37
     loginDialog: {
28
     loginDialog: {
38
-        ...dialog,
39
         flex: 0,
29
         flex: 0,
40
-        flexDirection: 'column'
30
+        flexDirection: 'column',
31
+        marginBottom: BoxModel.margin,
32
+        marginTop: BoxModel.margin
41
     },
33
     },
42
 
34
 
43
     /**
35
     /**
44
-     * The style of {@code WaitForOwnerDialog}.
36
+     * The style used then a progress message is rendered.
45
      */
37
      */
46
-    waitForOwnerDialog: {
47
-        ...dialog,
48
-        ...text
38
+    progressMessage: {
39
+        color: schemeColor('text')
49
     }
40
     }
50
 });
41
 });

+ 1
- 0
react/features/base/color-scheme/defaultScheme.js View File

10
         // Generic app theme colors that are used accross the entire app.
10
         // Generic app theme colors that are used accross the entire app.
11
         // All scheme definitions below inherit these values.
11
         // All scheme definitions below inherit these values.
12
         background: 'rgb(255, 255, 255)',
12
         background: 'rgb(255, 255, 255)',
13
+        errorText: ColorPalette.red,
13
         icon: 'rgb(28, 32, 37)',
14
         icon: 'rgb(28, 32, 37)',
14
         text: 'rgb(28, 32, 37)'
15
         text: 'rgb(28, 32, 37)'
15
     },
16
     },

Loading…
Cancel
Save