Browse Source

Improved error messages

Arnaud Vergnet 3 years ago
parent
commit
0267ff70ce

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

15
         mandatory: boolean
15
         mandatory: boolean
16
     }>,
16
     }>,
17
     renderFunction: (Array<{ [key: string]: any } | null>) => React.Node,
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
 type State = {
26
 type State = {
158
      * @return {*}
164
      * @return {*}
159
      */
165
      */
160
     getErrorRender() {
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
 import type {CustomTheme} from "../../../managers/ThemeManager";
12
 import type {CustomTheme} from "../../../managers/ThemeManager";
13
 import {StackNavigationProp} from "@react-navigation/stack";
13
 import {StackNavigationProp} from "@react-navigation/stack";
14
 import {Linking} from "expo";
14
 import {Linking} from "expo";
15
+import {ERROR_TYPE} from "../../../utils/WebData";
15
 
16
 
16
 type Props = {
17
 type Props = {
17
     navigation: StackNavigationProp,
18
     navigation: StackNavigationProp,
179
                         </Card.Content>
180
                         </Card.Content>
180
                         : <View/>}
181
                         : <View/>}
181
                     {this.getManagersRender(data.responsibles, data.email)}
182
                     {this.getManagersRender(data.responsibles, data.email)}
182
-                </ScrollView>
183
+q                </ScrollView>
183
             );
184
             );
184
         } else
185
         } else
185
             return null;
186
             return null;
198
                     }
199
                     }
199
                 ]}
200
                 ]}
200
                 renderFunction={this.getScreen}
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
         else
211
         else
203
             return this.getScreen([this.displayData]);
212
             return this.getScreen([this.displayData]);

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

7
 import DateManager from "../../managers/DateManager";
7
 import DateManager from "../../managers/DateManager";
8
 import ImageModal from 'react-native-image-modal';
8
 import ImageModal from 'react-native-image-modal';
9
 import BasicLoadingScreen from "../../components/Screens/BasicLoadingScreen";
9
 import BasicLoadingScreen from "../../components/Screens/BasicLoadingScreen";
10
-import {apiRequest} from "../../utils/WebData";
10
+import {apiRequest, ERROR_TYPE} from "../../utils/WebData";
11
 import ErrorView from "../../components/Screens/ErrorView";
11
 import ErrorView from "../../components/Screens/ErrorView";
12
 import CustomHTML from "../../components/Overrides/CustomHTML";
12
 import CustomHTML from "../../components/Overrides/CustomHTML";
13
 import CustomTabBar from "../../components/Tabbar/CustomTabBar";
13
 import CustomTabBar from "../../components/Tabbar/CustomTabBar";
14
+import i18n from 'i18n-js';
14
 
15
 
15
 type Props = {
16
 type Props = {
16
     navigation: Object,
17
     navigation: Object,
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
     render() {
124
     render() {
117
         if (this.state.loading)
125
         if (this.state.loading)
118
             return <BasicLoadingScreen/>;
126
             return <BasicLoadingScreen/>;
119
         else if (this.errorCode === 0)
127
         else if (this.errorCode === 0)
120
             return this.getContent();
128
             return this.getContent();
121
         else
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
     "vote": "Elections",
26
     "vote": "Elections",
27
     "scanner": "Scanotron 3000"
27
     "scanner": "Scanotron 3000"
28
   },
28
   },
29
-  "sidenav": {
30
-    "divider1": "Student websites",
31
-    "divider2": "Services",
32
-    "divider3": "Personalisation",
33
-    "divider4": "Amicale"
34
-  },
35
   "intro": {
29
   "intro": {
36
     "slide1": {
30
     "slide1": {
37
       "title": "Welcome to CAMPUS",
31
       "title": "Welcome to CAMPUS",
263
     "categoriesFilterMessage": "Click on a category to filter the list",
257
     "categoriesFilterMessage": "Click on a category to filter the list",
264
     "clubContact": "Contact the club",
258
     "clubContact": "Contact the club",
265
     "amicaleContact": "Contact the Amicale",
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
     "about": {
261
     "about": {
267
       "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!",
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
       "title": "A question ?",
263
       "title": "A question ?",
390
     "students": "Student services",
385
     "students": "Student services",
391
     "insa": "INSA services",
386
     "insa": "INSA services",
392
     "notLoggedIn": "Not logged in"
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
     "vote": "Élections",
26
     "vote": "Élections",
27
     "scanner": "Scanotron 3000"
27
     "scanner": "Scanotron 3000"
28
   },
28
   },
29
-  "sidenav": {
30
-    "divider1": "Sites étudiants",
31
-    "divider2": "Services",
32
-    "divider3": "Personnalisation",
33
-    "divider4": "Amicale"
34
-  },
35
   "intro": {
29
   "intro": {
36
     "slide1": {
30
     "slide1": {
37
       "title": "Bienvenue sur CAMPUS",
31
       "title": "Bienvenue sur CAMPUS",
263
     "categoriesFilterMessage": "Cliquez sur une catégorie pour filtrer la liste",
257
     "categoriesFilterMessage": "Cliquez sur une catégorie pour filtrer la liste",
264
     "clubContact": "Contacter le club",
258
     "clubContact": "Contacter le club",
265
     "amicaleContact": "Contacter l'Amicale",
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
     "about": {
261
     "about": {
267
       "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 !",
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
       "title": "Une question ?",
263
       "title": "Une question ?",
390
     "students": "Services étudiants",
385
     "students": "Services étudiants",
391
     "insa": "Services de l'INSA",
386
     "insa": "Services de l'INSA",
392
     "notLoggedIn": "Non connecté"
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