|
@@ -3,10 +3,10 @@
|
3
|
3
|
import * as React from 'react';
|
4
|
4
|
import {Keyboard, KeyboardAvoidingView, ScrollView, StyleSheet, TouchableWithoutFeedback, View} from "react-native";
|
5
|
5
|
import {Avatar, Button, Card, HelperText, Paragraph, TextInput, withTheme} from 'react-native-paper';
|
6
|
|
-import ConnectionManager, {ERROR_TYPE} from "../../managers/ConnectionManager";
|
|
6
|
+import ConnectionManager from "../../managers/ConnectionManager";
|
7
|
7
|
import {openBrowser} from "../../utils/WebBrowser";
|
8
|
8
|
import i18n from 'i18n-js';
|
9
|
|
-import AlertDialog from "../../components/Custom/AlertDialog";
|
|
9
|
+import ErrorDialog from "../../components/Dialog/ErrorDialog";
|
10
|
10
|
|
11
|
11
|
type Props = {
|
12
|
12
|
navigation: Object,
|
|
@@ -19,8 +19,7 @@ type State = {
|
19
|
19
|
isPasswordValidated: boolean,
|
20
|
20
|
loading: boolean,
|
21
|
21
|
dialogVisible: boolean,
|
22
|
|
- dialogTitle: string,
|
23
|
|
- dialogMessage: string,
|
|
22
|
+ dialogError: number,
|
24
|
23
|
}
|
25
|
24
|
|
26
|
25
|
const ICON_AMICALE = require('../../../assets/amicale.png');
|
|
@@ -38,8 +37,7 @@ class LoginScreen extends React.Component<Props, State> {
|
38
|
37
|
isPasswordValidated: false,
|
39
|
38
|
loading: false,
|
40
|
39
|
dialogVisible: false,
|
41
|
|
- dialogTitle: '',
|
42
|
|
- dialogMessage: '',
|
|
40
|
+ dialogError: 0,
|
43
|
41
|
};
|
44
|
42
|
|
45
|
43
|
colors: Object;
|
|
@@ -66,11 +64,10 @@ class LoginScreen extends React.Component<Props, State> {
|
66
|
64
|
this.colors = props.theme.colors;
|
67
|
65
|
}
|
68
|
66
|
|
69
|
|
- showErrorDialog = (title: string, message: string) =>
|
|
67
|
+ showErrorDialog = (error: number) =>
|
70
|
68
|
this.setState({
|
71
|
|
- dialogTitle: title,
|
72
|
|
- dialogMessage: message,
|
73
|
|
- dialogVisible: true
|
|
69
|
+ dialogVisible: true,
|
|
70
|
+ dialogError: error,
|
74
|
71
|
});
|
75
|
72
|
|
76
|
73
|
hideErrorDialog = () => this.setState({dialogVisible: false});
|
|
@@ -132,9 +129,7 @@ class LoginScreen extends React.Component<Props, State> {
|
132
|
129
|
.then((data) => {
|
133
|
130
|
this.handleSuccess();
|
134
|
131
|
})
|
135
|
|
- .catch((error) => {
|
136
|
|
- this.handleErrors(error);
|
137
|
|
- })
|
|
132
|
+ .catch(this.showErrorDialog)
|
138
|
133
|
.finally(() => {
|
139
|
134
|
this.setState({loading: false});
|
140
|
135
|
});
|
|
@@ -145,29 +140,6 @@ class LoginScreen extends React.Component<Props, State> {
|
145
|
140
|
this.props.navigation.navigate('ProfileScreen');
|
146
|
141
|
}
|
147
|
142
|
|
148
|
|
- handleErrors(error: number) {
|
149
|
|
- const title = i18n.t("loginScreen.errors.title");
|
150
|
|
- let message;
|
151
|
|
- switch (error) {
|
152
|
|
- case ERROR_TYPE.BAD_CREDENTIALS:
|
153
|
|
- message = i18n.t("loginScreen.errors.credentials");
|
154
|
|
- break;
|
155
|
|
- case ERROR_TYPE.NO_CONSENT:
|
156
|
|
- message = i18n.t("loginScreen.errors.consent");
|
157
|
|
- break;
|
158
|
|
- case ERROR_TYPE.CONNECTION_ERROR:
|
159
|
|
- message = i18n.t("loginScreen.errors.connection");
|
160
|
|
- break;
|
161
|
|
- case ERROR_TYPE.SERVER_ERROR:
|
162
|
|
- message = "SERVER ERROR"; // TODO translate
|
163
|
|
- break;
|
164
|
|
- default:
|
165
|
|
- message = i18n.t("loginScreen.errors.unknown");
|
166
|
|
- break;
|
167
|
|
- }
|
168
|
|
- this.showErrorDialog(title, message);
|
169
|
|
- }
|
170
|
|
-
|
171
|
143
|
getFormInput() {
|
172
|
144
|
return (
|
173
|
145
|
<View>
|
|
@@ -297,12 +269,10 @@ class LoginScreen extends React.Component<Props, State> {
|
297
|
269
|
{this.getSecondaryCard()}
|
298
|
270
|
</View>
|
299
|
271
|
</TouchableWithoutFeedback>
|
300
|
|
- <AlertDialog
|
301
|
|
- {...this.props}
|
|
272
|
+ <ErrorDialog
|
302
|
273
|
visible={this.state.dialogVisible}
|
303
|
|
- title={this.state.dialogTitle}
|
304
|
|
- message={this.state.dialogMessage}
|
305
|
274
|
onDismiss={this.hideErrorDialog}
|
|
275
|
+ errorCode={this.state.dialogError}
|
306
|
276
|
/>
|
307
|
277
|
</ScrollView>
|
308
|
278
|
</KeyboardAvoidingView>
|