Improved error messages

This commit is contained in:
Arnaud Vergnet 2020-04-23 11:05:35 +02:00
parent 2fc2db39c7
commit 0267ff70ce
5 changed files with 66 additions and 22 deletions

View file

@ -15,6 +15,12 @@ type Props = {
mandatory: boolean mandatory: boolean
}>, }>,
renderFunction: (Array<{ [key: string]: any } | null>) => React.Node, renderFunction: (Array<{ [key: string]: any } | null>) => React.Node,
errorViewOverride?: Array<{
errorCode: number,
message: string,
icon: string,
showRetryButton: boolean
}>,
} }
type State = { type State = {
@ -158,15 +164,40 @@ class AuthenticatedScreen extends React.Component<Props, State> {
* @return {*} * @return {*}
*/ */
getErrorRender() { getErrorRender() {
const errorCode = this.getError();
let shouldOverride = false;
let override = null;
const overrideList = this.props.errorViewOverride;
if (overrideList != null) {
for (let i = 0; i < overrideList.length; i++) {
if (overrideList[i].errorCode === errorCode) {
shouldOverride = true;
override = overrideList[i];
break;
}
}
}
if (shouldOverride && override != null) {
return ( return (
<ErrorView <ErrorView
{...this.props} {...this.props}
errorCode={this.getError()} icon={override.icon}
message={override.message}
showRetryButton={override.showRetryButton}
/>
);
} else {
return (
<ErrorView
{...this.props}
errorCode={errorCode}
onRefresh={this.fetchData} onRefresh={this.fetchData}
/> />
); );
} }
}
/** /**
* Reloads the data, to be called using ref by parent components * Reloads the data, to be called using ref by parent components
*/ */

View file

@ -12,6 +12,7 @@ import type {category, club} from "./ClubListScreen";
import type {CustomTheme} from "../../../managers/ThemeManager"; import type {CustomTheme} from "../../../managers/ThemeManager";
import {StackNavigationProp} from "@react-navigation/stack"; import {StackNavigationProp} from "@react-navigation/stack";
import {Linking} from "expo"; import {Linking} from "expo";
import {ERROR_TYPE} from "../../../utils/WebData";
type Props = { type Props = {
navigation: StackNavigationProp, navigation: StackNavigationProp,
@ -179,7 +180,7 @@ class ClubDisplayScreen extends React.Component<Props, State> {
</Card.Content> </Card.Content>
: <View/>} : <View/>}
{this.getManagersRender(data.responsibles, data.email)} {this.getManagersRender(data.responsibles, data.email)}
</ScrollView> q </ScrollView>
); );
} else } else
return null; return null;
@ -198,6 +199,14 @@ class ClubDisplayScreen extends React.Component<Props, State> {
} }
]} ]}
renderFunction={this.getScreen} renderFunction={this.getScreen}
errorViewOverride={[
{
errorCode: ERROR_TYPE.BAD_INPUT,
message: i18n.t("clubs.invalidClub"),
icon: "account-question",
showRetryButton: false
}
]}
/>; />;
else else
return this.getScreen([this.displayData]); return this.getScreen([this.displayData]);

View file

@ -7,10 +7,11 @@ import {Card, withTheme} from 'react-native-paper';
import DateManager from "../../managers/DateManager"; import DateManager from "../../managers/DateManager";
import ImageModal from 'react-native-image-modal'; import ImageModal from 'react-native-image-modal';
import BasicLoadingScreen from "../../components/Screens/BasicLoadingScreen"; import BasicLoadingScreen from "../../components/Screens/BasicLoadingScreen";
import {apiRequest} from "../../utils/WebData"; import {apiRequest, ERROR_TYPE} from "../../utils/WebData";
import ErrorView from "../../components/Screens/ErrorView"; import ErrorView from "../../components/Screens/ErrorView";
import CustomHTML from "../../components/Overrides/CustomHTML"; import CustomHTML from "../../components/Overrides/CustomHTML";
import CustomTabBar from "../../components/Tabbar/CustomTabBar"; import CustomTabBar from "../../components/Tabbar/CustomTabBar";
import i18n from 'i18n-js';
type Props = { type Props = {
navigation: Object, navigation: Object,
@ -113,13 +114,20 @@ class PlanningDisplayScreen extends React.Component<Props, State> {
); );
} }
getErrorView() {
if (this.errorCode === ERROR_TYPE.BAD_INPUT)
return <ErrorView {...this.props} showRetryButton={false} message={i18n.t("planningScreen.invalidEvent")} icon={"calendar-remove"}/>;
else
return <ErrorView {...this.props} errorCode={this.errorCode} onRefresh={this.fetchData}/>;
}
render() { render() {
if (this.state.loading) if (this.state.loading)
return <BasicLoadingScreen/>; return <BasicLoadingScreen/>;
else if (this.errorCode === 0) else if (this.errorCode === 0)
return this.getContent(); return this.getContent();
else else
return <ErrorView {...this.props} errorCode={this.errorCode} onRefresh={this.fetchData}/>; return this.getErrorView();
} }
} }

View file

@ -26,12 +26,6 @@
"vote": "Elections", "vote": "Elections",
"scanner": "Scanotron 3000" "scanner": "Scanotron 3000"
}, },
"sidenav": {
"divider1": "Student websites",
"divider2": "Services",
"divider3": "Personalisation",
"divider4": "Amicale"
},
"intro": { "intro": {
"slide1": { "slide1": {
"title": "Welcome to CAMPUS", "title": "Welcome to CAMPUS",
@ -263,6 +257,7 @@
"categoriesFilterMessage": "Click on a category to filter the list", "categoriesFilterMessage": "Click on a category to filter the list",
"clubContact": "Contact the club", "clubContact": "Contact the club",
"amicaleContact": "Contact the Amicale", "amicaleContact": "Contact the Amicale",
"invalidClub": "Could not find the club. Please make sure the club you are trying to access is valid.",
"about": { "about": {
"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!", "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!",
"title": "A question ?", "title": "A question ?",
@ -390,5 +385,8 @@
"students": "Student services", "students": "Student services",
"insa": "INSA services", "insa": "INSA services",
"notLoggedIn": "Not logged in" "notLoggedIn": "Not logged in"
},
"planningScreen": {
"invalidEvent": "Could not find the event. Please make sure the event you are trying to access is valid."
} }
} }

View file

@ -26,12 +26,6 @@
"vote": "Élections", "vote": "Élections",
"scanner": "Scanotron 3000" "scanner": "Scanotron 3000"
}, },
"sidenav": {
"divider1": "Sites étudiants",
"divider2": "Services",
"divider3": "Personnalisation",
"divider4": "Amicale"
},
"intro": { "intro": {
"slide1": { "slide1": {
"title": "Bienvenue sur CAMPUS", "title": "Bienvenue sur CAMPUS",
@ -263,6 +257,7 @@
"categoriesFilterMessage": "Cliquez sur une catégorie pour filtrer la liste", "categoriesFilterMessage": "Cliquez sur une catégorie pour filtrer la liste",
"clubContact": "Contacter le club", "clubContact": "Contacter le club",
"amicaleContact": "Contacter l'Amicale", "amicaleContact": "Contacter l'Amicale",
"invalidClub": "Impossible de trouver le club. Merci de vérifier que le club que vous voulez voir est valide.",
"about": { "about": {
"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 !", "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 !",
"title": "Une question ?", "title": "Une question ?",
@ -390,5 +385,8 @@
"students": "Services étudiants", "students": "Services étudiants",
"insa": "Services de l'INSA", "insa": "Services de l'INSA",
"notLoggedIn": "Non connecté" "notLoggedIn": "Non connecté"
},
"planningScreen": {
"invalidEvent": "Impossible de trouver l'événement. Merci de vérifier que l'événement que vous voulez voir est valide."
} }
} }