Show information message when no group is selected

This commit is contained in:
Arnaud Vergnet 2020-04-15 22:38:57 +02:00
parent ffb0b03b41
commit ac59121609
4 changed files with 86 additions and 53 deletions

View file

@ -12,6 +12,9 @@ type Props = {
route: Object, route: Object,
errorCode: number, errorCode: number,
onRefresh: Function, onRefresh: Function,
icon: string,
message: string,
showRetryButton: boolean,
} }
type State = { type State = {
@ -27,6 +30,13 @@ class ErrorView extends React.PureComponent<Props, State> {
showLoginButton: boolean; showLoginButton: boolean;
static defaultProps = {
errorCode: 0,
icon: '',
message: '',
showRetryButton: true,
}
state = { state = {
refreshing: false, refreshing: false,
}; };
@ -38,6 +48,7 @@ class ErrorView extends React.PureComponent<Props, State> {
generateMessage() { generateMessage() {
this.showLoginButton = false; this.showLoginButton = false;
if (this.props.errorCode !== 0) {
switch (this.props.errorCode) { switch (this.props.errorCode) {
case ERROR_TYPE.BAD_CREDENTIALS: case ERROR_TYPE.BAD_CREDENTIALS:
this.message = i18n.t("errors.badCredentials"); this.message = i18n.t("errors.badCredentials");
@ -73,6 +84,11 @@ class ErrorView extends React.PureComponent<Props, State> {
this.icon = "alert-circle-outline"; this.icon = "alert-circle-outline";
break; break;
} }
} else {
this.message = this.props.message;
this.icon = this.props.icon;
}
} }
getRetryButton() { getRetryButton() {
@ -91,7 +107,8 @@ class ErrorView extends React.PureComponent<Props, State> {
{ {
screen: 'login', screen: 'login',
params: {nextScreen: this.props.route.name} params: {nextScreen: this.props.route.name}
})}; })
};
getLoginButton() { getLoginButton() {
return <Button return <Button
@ -124,9 +141,11 @@ class ErrorView extends React.PureComponent<Props, State> {
}}> }}>
{this.message} {this.message}
</Subheading> </Subheading>
{this.showLoginButton {this.props.showRetryButton
? (this.showLoginButton
? this.getLoginButton() ? this.getLoginButton()
: this.getRetryButton()} : this.getRetryButton())
: null}
</View> </View>
</View> </View>
); );
@ -148,6 +167,7 @@ const styles = StyleSheet.create({
}, },
subheading: { subheading: {
textAlign: 'center', textAlign: 'center',
paddingHorizontal: 20
}, },
button: { button: {
marginTop: 10, marginTop: 10,

View file

@ -13,6 +13,7 @@ import {dateToString, getTimeOnlyString} from "../../utils/Planning";
import DateManager from "../../managers/DateManager"; import DateManager from "../../managers/DateManager";
import AnimatedBottomBar from "../../components/Custom/AnimatedBottomBar"; import AnimatedBottomBar from "../../components/Custom/AnimatedBottomBar";
import {CommonActions} from "@react-navigation/native"; import {CommonActions} from "@react-navigation/native";
import ErrorView from "../../components/Custom/ErrorView";
type Props = { type Props = {
navigation: Object, navigation: Object,
@ -143,7 +144,7 @@ class PlanexScreen extends React.Component<Props, State> {
let currentGroup = AsyncStorageManager.getInstance().preferences.planexCurrentGroup.current; let currentGroup = AsyncStorageManager.getInstance().preferences.planexCurrentGroup.current;
if (currentGroup === '') if (currentGroup === '')
currentGroup = {name: "SELECT GROUP", id: 0}; currentGroup = {name: "SELECT GROUP", id: -1};
else else
currentGroup = JSON.parse(currentGroup); currentGroup = JSON.parse(currentGroup);
this.state = { this.state = {
@ -260,6 +261,7 @@ class PlanexScreen extends React.Component<Props, State> {
}; };
getWebView() { getWebView() {
if (this.state.currentGroup.id !== -1) {
return ( return (
<WebViewScreen <WebViewScreen
ref={this.webScreenRef} ref={this.webScreenRef}
@ -270,6 +272,15 @@ class PlanexScreen extends React.Component<Props, State> {
onScroll={this.onScroll} onScroll={this.onScroll}
/> />
); );
} else {
return <ErrorView
{...this.props}
icon={'account-clock'}
message={i18n.t("planexScreen.noGroupSelected")}
showRetryButton={false}
/>
}
} }
render() { render() {

View file

@ -212,7 +212,8 @@
"planexScreen": { "planexScreen": {
"enableStartScreen": "Come here often? Set it as default screen!", "enableStartScreen": "Come here often? Set it as default screen!",
"enableStartOK": "Yes please!", "enableStartOK": "Yes please!",
"enableStartCancel": "Later" "enableStartCancel": "Later",
"noGroupSelected": "No group selected. Please select your group using the big beautiful red button bellow."
}, },
"availableRoomScreen": { "availableRoomScreen": {
"normalRoom": "Work", "normalRoom": "Work",

View file

@ -212,7 +212,8 @@
"planexScreen": { "planexScreen": {
"enableStartScreen": "Vous venez souvent ici ? Démarrez l'appli sur cette page!", "enableStartScreen": "Vous venez souvent ici ? Démarrez l'appli sur cette page!",
"enableStartOK": "Oui svp!", "enableStartOK": "Oui svp!",
"enableStartCancel": "Plus tard" "enableStartCancel": "Plus tard",
"noGroupSelected": "Pas de group sélectionné. Merci de choisir un groupe avec le beau bouton rouge ci-dessous."
}, },
"availableRoomScreen": { "availableRoomScreen": {
"normalRoom": "Travail", "normalRoom": "Travail",