forked from vergnet/application-amicale
Improved error messages
This commit is contained in:
parent
2fc2db39c7
commit
0267ff70ce
5 changed files with 66 additions and 22 deletions
|
@ -15,6 +15,12 @@ type Props = {
|
|||
mandatory: boolean
|
||||
}>,
|
||||
renderFunction: (Array<{ [key: string]: any } | null>) => React.Node,
|
||||
errorViewOverride?: Array<{
|
||||
errorCode: number,
|
||||
message: string,
|
||||
icon: string,
|
||||
showRetryButton: boolean
|
||||
}>,
|
||||
}
|
||||
|
||||
type State = {
|
||||
|
@ -158,13 +164,38 @@ class AuthenticatedScreen extends React.Component<Props, State> {
|
|||
* @return {*}
|
||||
*/
|
||||
getErrorRender() {
|
||||
return (
|
||||
<ErrorView
|
||||
{...this.props}
|
||||
errorCode={this.getError()}
|
||||
onRefresh={this.fetchData}
|
||||
/>
|
||||
);
|
||||
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 (
|
||||
<ErrorView
|
||||
{...this.props}
|
||||
icon={override.icon}
|
||||
message={override.message}
|
||||
showRetryButton={override.showRetryButton}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<ErrorView
|
||||
{...this.props}
|
||||
errorCode={errorCode}
|
||||
onRefresh={this.fetchData}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,6 +12,7 @@ import type {category, club} from "./ClubListScreen";
|
|||
import type {CustomTheme} from "../../../managers/ThemeManager";
|
||||
import {StackNavigationProp} from "@react-navigation/stack";
|
||||
import {Linking} from "expo";
|
||||
import {ERROR_TYPE} from "../../../utils/WebData";
|
||||
|
||||
type Props = {
|
||||
navigation: StackNavigationProp,
|
||||
|
@ -179,7 +180,7 @@ class ClubDisplayScreen extends React.Component<Props, State> {
|
|||
</Card.Content>
|
||||
: <View/>}
|
||||
{this.getManagersRender(data.responsibles, data.email)}
|
||||
</ScrollView>
|
||||
q </ScrollView>
|
||||
);
|
||||
} else
|
||||
return null;
|
||||
|
@ -198,6 +199,14 @@ class ClubDisplayScreen extends React.Component<Props, State> {
|
|||
}
|
||||
]}
|
||||
renderFunction={this.getScreen}
|
||||
errorViewOverride={[
|
||||
{
|
||||
errorCode: ERROR_TYPE.BAD_INPUT,
|
||||
message: i18n.t("clubs.invalidClub"),
|
||||
icon: "account-question",
|
||||
showRetryButton: false
|
||||
}
|
||||
]}
|
||||
/>;
|
||||
else
|
||||
return this.getScreen([this.displayData]);
|
||||
|
|
|
@ -7,10 +7,11 @@ import {Card, withTheme} from 'react-native-paper';
|
|||
import DateManager from "../../managers/DateManager";
|
||||
import ImageModal from 'react-native-image-modal';
|
||||
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 CustomHTML from "../../components/Overrides/CustomHTML";
|
||||
import CustomTabBar from "../../components/Tabbar/CustomTabBar";
|
||||
import i18n from 'i18n-js';
|
||||
|
||||
type Props = {
|
||||
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() {
|
||||
if (this.state.loading)
|
||||
return <BasicLoadingScreen/>;
|
||||
else if (this.errorCode === 0)
|
||||
return this.getContent();
|
||||
else
|
||||
return <ErrorView {...this.props} errorCode={this.errorCode} onRefresh={this.fetchData}/>;
|
||||
return this.getErrorView();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,6 @@
|
|||
"vote": "Elections",
|
||||
"scanner": "Scanotron 3000"
|
||||
},
|
||||
"sidenav": {
|
||||
"divider1": "Student websites",
|
||||
"divider2": "Services",
|
||||
"divider3": "Personalisation",
|
||||
"divider4": "Amicale"
|
||||
},
|
||||
"intro": {
|
||||
"slide1": {
|
||||
"title": "Welcome to CAMPUS",
|
||||
|
@ -263,6 +257,7 @@
|
|||
"categoriesFilterMessage": "Click on a category to filter the list",
|
||||
"clubContact": "Contact the club",
|
||||
"amicaleContact": "Contact the Amicale",
|
||||
"invalidClub": "Could not find the club. Please make sure the club you are trying to access is valid.",
|
||||
"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!",
|
||||
"title": "A question ?",
|
||||
|
@ -390,5 +385,8 @@
|
|||
"students": "Student services",
|
||||
"insa": "INSA services",
|
||||
"notLoggedIn": "Not logged in"
|
||||
},
|
||||
"planningScreen": {
|
||||
"invalidEvent": "Could not find the event. Please make sure the event you are trying to access is valid."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,12 +26,6 @@
|
|||
"vote": "Élections",
|
||||
"scanner": "Scanotron 3000"
|
||||
},
|
||||
"sidenav": {
|
||||
"divider1": "Sites étudiants",
|
||||
"divider2": "Services",
|
||||
"divider3": "Personnalisation",
|
||||
"divider4": "Amicale"
|
||||
},
|
||||
"intro": {
|
||||
"slide1": {
|
||||
"title": "Bienvenue sur CAMPUS",
|
||||
|
@ -263,6 +257,7 @@
|
|||
"categoriesFilterMessage": "Cliquez sur une catégorie pour filtrer la liste",
|
||||
"clubContact": "Contacter le club",
|
||||
"amicaleContact": "Contacter l'Amicale",
|
||||
"invalidClub": "Impossible de trouver le club. Merci de vérifier que le club que vous voulez voir est valide.",
|
||||
"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 !",
|
||||
"title": "Une question ?",
|
||||
|
@ -390,5 +385,8 @@
|
|||
"students": "Services étudiants",
|
||||
"insa": "Services de l'INSA",
|
||||
"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."
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue