|
@@ -12,6 +12,9 @@ type Props = {
|
12
|
12
|
route: Object,
|
13
|
13
|
errorCode: number,
|
14
|
14
|
onRefresh: Function,
|
|
15
|
+ icon: string,
|
|
16
|
+ message: string,
|
|
17
|
+ showRetryButton: boolean,
|
15
|
18
|
}
|
16
|
19
|
|
17
|
20
|
type State = {
|
|
@@ -27,6 +30,13 @@ class ErrorView extends React.PureComponent<Props, State> {
|
27
|
30
|
|
28
|
31
|
showLoginButton: boolean;
|
29
|
32
|
|
|
33
|
+ static defaultProps = {
|
|
34
|
+ errorCode: 0,
|
|
35
|
+ icon: '',
|
|
36
|
+ message: '',
|
|
37
|
+ showRetryButton: true,
|
|
38
|
+ }
|
|
39
|
+
|
30
|
40
|
state = {
|
31
|
41
|
refreshing: false,
|
32
|
42
|
};
|
|
@@ -38,41 +48,47 @@ class ErrorView extends React.PureComponent<Props, State> {
|
38
|
48
|
|
39
|
49
|
generateMessage() {
|
40
|
50
|
this.showLoginButton = false;
|
41
|
|
- switch (this.props.errorCode) {
|
42
|
|
- case ERROR_TYPE.BAD_CREDENTIALS:
|
43
|
|
- this.message = i18n.t("errors.badCredentials");
|
44
|
|
- this.icon = "account-alert-outline";
|
45
|
|
- break;
|
46
|
|
- case ERROR_TYPE.BAD_TOKEN:
|
47
|
|
- this.message = i18n.t("errors.badToken");
|
48
|
|
- this.icon = "account-alert-outline";
|
49
|
|
- this.showLoginButton = true;
|
50
|
|
- break;
|
51
|
|
- case ERROR_TYPE.NO_CONSENT:
|
52
|
|
- this.message = i18n.t("errors.noConsent");
|
53
|
|
- this.icon = "account-remove-outline";
|
54
|
|
- break;
|
55
|
|
- case ERROR_TYPE.BAD_INPUT:
|
56
|
|
- this.message = i18n.t("errors.badInput");
|
57
|
|
- this.icon = "alert-circle-outline";
|
58
|
|
- break;
|
59
|
|
- case ERROR_TYPE.FORBIDDEN:
|
60
|
|
- this.message = i18n.t("errors.forbidden");
|
61
|
|
- this.icon = "lock";
|
62
|
|
- break;
|
63
|
|
- case ERROR_TYPE.CONNECTION_ERROR:
|
64
|
|
- this.message = i18n.t("errors.connectionError");
|
65
|
|
- this.icon = "access-point-network-off";
|
66
|
|
- break;
|
67
|
|
- case ERROR_TYPE.SERVER_ERROR:
|
68
|
|
- this.message = i18n.t("errors.serverError");
|
69
|
|
- this.icon = "server-network-off";
|
70
|
|
- break;
|
71
|
|
- default:
|
72
|
|
- this.message = i18n.t("errors.unknown");
|
73
|
|
- this.icon = "alert-circle-outline";
|
74
|
|
- break;
|
|
51
|
+ if (this.props.errorCode !== 0) {
|
|
52
|
+ switch (this.props.errorCode) {
|
|
53
|
+ case ERROR_TYPE.BAD_CREDENTIALS:
|
|
54
|
+ this.message = i18n.t("errors.badCredentials");
|
|
55
|
+ this.icon = "account-alert-outline";
|
|
56
|
+ break;
|
|
57
|
+ case ERROR_TYPE.BAD_TOKEN:
|
|
58
|
+ this.message = i18n.t("errors.badToken");
|
|
59
|
+ this.icon = "account-alert-outline";
|
|
60
|
+ this.showLoginButton = true;
|
|
61
|
+ break;
|
|
62
|
+ case ERROR_TYPE.NO_CONSENT:
|
|
63
|
+ this.message = i18n.t("errors.noConsent");
|
|
64
|
+ this.icon = "account-remove-outline";
|
|
65
|
+ break;
|
|
66
|
+ case ERROR_TYPE.BAD_INPUT:
|
|
67
|
+ this.message = i18n.t("errors.badInput");
|
|
68
|
+ this.icon = "alert-circle-outline";
|
|
69
|
+ break;
|
|
70
|
+ case ERROR_TYPE.FORBIDDEN:
|
|
71
|
+ this.message = i18n.t("errors.forbidden");
|
|
72
|
+ this.icon = "lock";
|
|
73
|
+ break;
|
|
74
|
+ case ERROR_TYPE.CONNECTION_ERROR:
|
|
75
|
+ this.message = i18n.t("errors.connectionError");
|
|
76
|
+ this.icon = "access-point-network-off";
|
|
77
|
+ break;
|
|
78
|
+ case ERROR_TYPE.SERVER_ERROR:
|
|
79
|
+ this.message = i18n.t("errors.serverError");
|
|
80
|
+ this.icon = "server-network-off";
|
|
81
|
+ break;
|
|
82
|
+ default:
|
|
83
|
+ this.message = i18n.t("errors.unknown");
|
|
84
|
+ this.icon = "alert-circle-outline";
|
|
85
|
+ break;
|
|
86
|
+ }
|
|
87
|
+ } else {
|
|
88
|
+ this.message = this.props.message;
|
|
89
|
+ this.icon = this.props.icon;
|
75
|
90
|
}
|
|
91
|
+
|
76
|
92
|
}
|
77
|
93
|
|
78
|
94
|
getRetryButton() {
|
|
@@ -88,10 +104,11 @@ class ErrorView extends React.PureComponent<Props, State> {
|
88
|
104
|
|
89
|
105
|
goToLogin = () => {
|
90
|
106
|
this.props.navigation.navigate("login",
|
91
|
|
- {
|
92
|
|
- screen: 'login',
|
93
|
|
- params: {nextScreen: this.props.route.name}
|
94
|
|
- })};
|
|
107
|
+ {
|
|
108
|
+ screen: 'login',
|
|
109
|
+ params: {nextScreen: this.props.route.name}
|
|
110
|
+ })
|
|
111
|
+ };
|
95
|
112
|
|
96
|
113
|
getLoginButton() {
|
97
|
114
|
return <Button
|
|
@@ -124,9 +141,11 @@ class ErrorView extends React.PureComponent<Props, State> {
|
124
|
141
|
}}>
|
125
|
142
|
{this.message}
|
126
|
143
|
</Subheading>
|
127
|
|
- {this.showLoginButton
|
128
|
|
- ? this.getLoginButton()
|
129
|
|
- : this.getRetryButton()}
|
|
144
|
+ {this.props.showRetryButton
|
|
145
|
+ ? (this.showLoginButton
|
|
146
|
+ ? this.getLoginButton()
|
|
147
|
+ : this.getRetryButton())
|
|
148
|
+ : null}
|
130
|
149
|
</View>
|
131
|
150
|
</View>
|
132
|
151
|
);
|
|
@@ -148,6 +167,7 @@ const styles = StyleSheet.create({
|
148
|
167
|
},
|
149
|
168
|
subheading: {
|
150
|
169
|
textAlign: 'center',
|
|
170
|
+ paddingHorizontal: 20
|
151
|
171
|
},
|
152
|
172
|
button: {
|
153
|
173
|
marginTop: 10,
|