Browse Source

Improved error messages

Arnaud Vergnet 3 years ago
parent
commit
0267ff70ce

+ 38
- 7
src/components/Amicale/AuthenticatedScreen.js View File

@@ -15,6 +15,12 @@ type Props = {
15 15
         mandatory: boolean
16 16
     }>,
17 17
     renderFunction: (Array<{ [key: string]: any } | null>) => React.Node,
18
+    errorViewOverride?: Array<{
19
+        errorCode: number,
20
+        message: string,
21
+        icon: string,
22
+        showRetryButton: boolean
23
+    }>,
18 24
 }
19 25
 
20 26
 type State = {
@@ -158,13 +164,38 @@ class AuthenticatedScreen extends React.Component<Props, State> {
158 164
      * @return {*}
159 165
      */
160 166
     getErrorRender() {
161
-        return (
162
-            <ErrorView
163
-                {...this.props}
164
-                errorCode={this.getError()}
165
-                onRefresh={this.fetchData}
166
-            />
167
-        );
167
+        const errorCode = this.getError();
168
+        let shouldOverride = false;
169
+        let override = null;
170
+        const overrideList = this.props.errorViewOverride;
171
+        if (overrideList != null) {
172
+            for (let i = 0; i < overrideList.length; i++) {
173
+                if (overrideList[i].errorCode === errorCode) {
174
+                    shouldOverride = true;
175
+                    override = overrideList[i];
176
+                    break;
177
+                }
178
+            }
179
+        }
180
+        if (shouldOverride && override != null) {
181
+            return (
182
+                <ErrorView
183
+                    {...this.props}
184
+                    icon={override.icon}
185
+                    message={override.message}
186
+                    showRetryButton={override.showRetryButton}
187
+                />
188
+            );
189
+        } else {
190
+            return (
191
+                <ErrorView
192
+                    {...this.props}
193
+                    errorCode={errorCode}
194
+                    onRefresh={this.fetchData}
195
+                />
196
+            );
197
+        }
198
+
168 199
     }
169 200
 
170 201
     /**

+ 10
- 1
src/screens/Amicale/Clubs/ClubDisplayScreen.js View File

@@ -12,6 +12,7 @@ import type {category, club} from "./ClubListScreen";
12 12
 import type {CustomTheme} from "../../../managers/ThemeManager";
13 13
 import {StackNavigationProp} from "@react-navigation/stack";
14 14
 import {Linking} from "expo";
15
+import {ERROR_TYPE} from "../../../utils/WebData";
15 16
 
16 17
 type Props = {
17 18
     navigation: StackNavigationProp,
@@ -179,7 +180,7 @@ class ClubDisplayScreen extends React.Component<Props, State> {
179 180
                         </Card.Content>
180 181
                         : <View/>}
181 182
                     {this.getManagersRender(data.responsibles, data.email)}
182
-                </ScrollView>
183
+q                </ScrollView>
183 184
             );
184 185
         } else
185 186
             return null;
@@ -198,6 +199,14 @@ class ClubDisplayScreen extends React.Component<Props, State> {
198 199
                     }
199 200
                 ]}
200 201
                 renderFunction={this.getScreen}
202
+                errorViewOverride={[
203
+                    {
204
+                        errorCode: ERROR_TYPE.BAD_INPUT,
205
+                        message: i18n.t("clubs.invalidClub"),
206
+                        icon: "account-question",
207
+                        showRetryButton: false
208
+                    }
209
+                ]}
201 210
             />;
202 211
         else
203 212
             return this.getScreen([this.displayData]);

+ 10
- 2
src/screens/Planning/PlanningDisplayScreen.js View File

@@ -7,10 +7,11 @@ import {Card, withTheme} from 'react-native-paper';
7 7
 import DateManager from "../../managers/DateManager";
8 8
 import ImageModal from 'react-native-image-modal';
9 9
 import BasicLoadingScreen from "../../components/Screens/BasicLoadingScreen";
10
-import {apiRequest} from "../../utils/WebData";
10
+import {apiRequest, ERROR_TYPE} from "../../utils/WebData";
11 11
 import ErrorView from "../../components/Screens/ErrorView";
12 12
 import CustomHTML from "../../components/Overrides/CustomHTML";
13 13
 import CustomTabBar from "../../components/Tabbar/CustomTabBar";
14
+import i18n from 'i18n-js';
14 15
 
15 16
 type Props = {
16 17
     navigation: Object,
@@ -113,13 +114,20 @@ class PlanningDisplayScreen extends React.Component<Props, State> {
113 114
         );
114 115
     }
115 116
 
117
+    getErrorView() {
118
+        if (this.errorCode === ERROR_TYPE.BAD_INPUT)
119
+            return <ErrorView {...this.props} showRetryButton={false} message={i18n.t("planningScreen.invalidEvent")} icon={"calendar-remove"}/>;
120
+        else
121
+            return <ErrorView {...this.props} errorCode={this.errorCode} onRefresh={this.fetchData}/>;
122
+    }
123
+
116 124
     render() {
117 125
         if (this.state.loading)
118 126
             return <BasicLoadingScreen/>;
119 127
         else if (this.errorCode === 0)
120 128
             return this.getContent();
121 129
         else
122
-            return <ErrorView {...this.props} errorCode={this.errorCode} onRefresh={this.fetchData}/>;
130
+            return this.getErrorView();
123 131
     }
124 132
 }
125 133
 

+ 4
- 6
translations/en.json View File

@@ -26,12 +26,6 @@
26 26
     "vote": "Elections",
27 27
     "scanner": "Scanotron 3000"
28 28
   },
29
-  "sidenav": {
30
-    "divider1": "Student websites",
31
-    "divider2": "Services",
32
-    "divider3": "Personalisation",
33
-    "divider4": "Amicale"
34
-  },
35 29
   "intro": {
36 30
     "slide1": {
37 31
       "title": "Welcome to CAMPUS",
@@ -263,6 +257,7 @@
263 257
     "categoriesFilterMessage": "Click on a category to filter the list",
264 258
     "clubContact": "Contact the club",
265 259
     "amicaleContact": "Contact the Amicale",
260
+    "invalidClub": "Could not find the club. Please make sure the club you are trying to access is valid.",
266 261
     "about": {
267 262
       "text": "The clubs, making the campus live, with more than sixty clubs offering various activities! From the philosophy club to the PABI (Production Artisanale de Bière Insaienne), without forgetting the multiple music and dance clubs, you will surely find an activity that suits you!",
268 263
       "title": "A question ?",
@@ -390,5 +385,8 @@
390 385
     "students": "Student services",
391 386
     "insa": "INSA services",
392 387
     "notLoggedIn": "Not logged in"
388
+  },
389
+  "planningScreen": {
390
+    "invalidEvent": "Could not find the event. Please make sure the event you are trying to access is valid."
393 391
   }
394 392
 }

+ 4
- 6
translations/fr.json View File

@@ -26,12 +26,6 @@
26 26
     "vote": "Élections",
27 27
     "scanner": "Scanotron 3000"
28 28
   },
29
-  "sidenav": {
30
-    "divider1": "Sites étudiants",
31
-    "divider2": "Services",
32
-    "divider3": "Personnalisation",
33
-    "divider4": "Amicale"
34
-  },
35 29
   "intro": {
36 30
     "slide1": {
37 31
       "title": "Bienvenue sur CAMPUS",
@@ -263,6 +257,7 @@
263 257
     "categoriesFilterMessage": "Cliquez sur une catégorie pour filtrer la liste",
264 258
     "clubContact": "Contacter le club",
265 259
     "amicaleContact": "Contacter l'Amicale",
260
+    "invalidClub": "Impossible de trouver le club. Merci de vérifier que le club que vous voulez voir est valide.",
266 261
     "about": {
267 262
       "text": "Les clubs, c'est ce qui fait vivre le campus au quotidien, plus d'une soixantaine de clubs qui proposent des activités diverses et variées ! Du club Philosophie au PABI (Production Artisanale de Bière Insaienne), en passant par les multiples clubs de musique et de danse, vous trouverez forcément une activité qui vous permettra de vous épanouir sur le campus !",
268 263
       "title": "Une question ?",
@@ -390,5 +385,8 @@
390 385
     "students": "Services étudiants",
391 386
     "insa": "Services de l'INSA",
392 387
     "notLoggedIn": "Non connecté"
388
+  },
389
+  "planningScreen": {
390
+    "invalidEvent": "Impossible de trouver l'événement. Merci de vérifier que l'événement que vous voulez voir est valide."
393 391
   }
394 392
 }

Loading…
Cancel
Save