Open login screen when user tries to access an amicale service instead of showing an error

This commit is contained in:
Arnaud Vergnet 2020-06-26 17:50:42 +02:00
parent aaf7084297
commit 88b2120c8a

View file

@ -11,6 +11,7 @@ import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-nat
import type {CustomTheme} from "../../managers/ThemeManager"; import type {CustomTheme} from "../../managers/ThemeManager";
import i18n from 'i18n-js'; import i18n from 'i18n-js';
import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton"; import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
import ConnectionManager from "../../managers/ConnectionManager";
type Props = { type Props = {
navigation: Object, navigation: Object,
@ -61,13 +62,13 @@ class ServicesScreen extends React.Component<Props, State> {
title: i18n.t('screens.clubsAbout'), title: i18n.t('screens.clubsAbout'),
subtitle: i18n.t('servicesScreen.descriptions.clubs'), subtitle: i18n.t('servicesScreen.descriptions.clubs'),
image: CLUBS_IMAGE, image: CLUBS_IMAGE,
onPress: () => nav.navigate("club-list"), onPress: () => this.onAmicaleServicePress("club-list"),
}, },
{ {
title: i18n.t('screens.profile'), title: i18n.t('screens.profile'),
subtitle: i18n.t('servicesScreen.descriptions.profile'), subtitle: i18n.t('servicesScreen.descriptions.profile'),
image: PROFILE_IMAGE, image: PROFILE_IMAGE,
onPress: () => nav.navigate("profile"), onPress: () => this.onAmicaleServicePress("profile"),
}, },
{ {
title: i18n.t('screens.amicaleWebsite'), title: i18n.t('screens.amicaleWebsite'),
@ -79,7 +80,7 @@ class ServicesScreen extends React.Component<Props, State> {
title: i18n.t('screens.vote'), title: i18n.t('screens.vote'),
subtitle: i18n.t('servicesScreen.descriptions.vote'), subtitle: i18n.t('servicesScreen.descriptions.vote'),
image: VOTE_IMAGE, image: VOTE_IMAGE,
onPress: () => nav.navigate("vote"), onPress: () => this.onAmicaleServicePress("vote"),
}, },
]; ];
this.studentsDataset = [ this.studentsDataset = [
@ -196,6 +197,13 @@ class ServicesScreen extends React.Component<Props, State> {
/> />
} }
onAmicaleServicePress(route: string) {
if (ConnectionManager.getInstance().isLoggedIn())
this.props.navigation.navigate(route);
else
this.props.navigation.navigate("login", {nextScreen: route});
}
renderItem = ({item}: { item: listItem }) => { renderItem = ({item}: { item: listItem }) => {
return ( return (
<TouchableRipple <TouchableRipple