Browse Source

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

Arnaud Vergnet 1 year ago
parent
commit
88b2120c8a
1 changed files with 11 additions and 3 deletions
  1. 11
    3
      src/screens/Services/ServicesScreen.js

+ 11
- 3
src/screens/Services/ServicesScreen.js View File

@@ -11,6 +11,7 @@ import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-nat
11 11
 import type {CustomTheme} from "../../managers/ThemeManager";
12 12
 import i18n from 'i18n-js';
13 13
 import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
14
+import ConnectionManager from "../../managers/ConnectionManager";
14 15
 
15 16
 type Props = {
16 17
     navigation: Object,
@@ -61,13 +62,13 @@ class ServicesScreen extends React.Component<Props, State> {
61 62
                 title: i18n.t('screens.clubsAbout'),
62 63
                 subtitle: i18n.t('servicesScreen.descriptions.clubs'),
63 64
                 image: CLUBS_IMAGE,
64
-                onPress: () => nav.navigate("club-list"),
65
+                onPress: () => this.onAmicaleServicePress("club-list"),
65 66
             },
66 67
             {
67 68
                 title: i18n.t('screens.profile'),
68 69
                 subtitle: i18n.t('servicesScreen.descriptions.profile'),
69 70
                 image: PROFILE_IMAGE,
70
-                onPress: () => nav.navigate("profile"),
71
+                onPress: () => this.onAmicaleServicePress("profile"),
71 72
             },
72 73
             {
73 74
                 title: i18n.t('screens.amicaleWebsite'),
@@ -79,7 +80,7 @@ class ServicesScreen extends React.Component<Props, State> {
79 80
                 title: i18n.t('screens.vote'),
80 81
                 subtitle: i18n.t('servicesScreen.descriptions.vote'),
81 82
                 image: VOTE_IMAGE,
82
-                onPress: () => nav.navigate("vote"),
83
+                onPress: () => this.onAmicaleServicePress("vote"),
83 84
             },
84 85
         ];
85 86
         this.studentsDataset = [
@@ -196,6 +197,13 @@ class ServicesScreen extends React.Component<Props, State> {
196 197
             />
197 198
     }
198 199
 
200
+    onAmicaleServicePress(route: string) {
201
+        if (ConnectionManager.getInstance().isLoggedIn())
202
+            this.props.navigation.navigate(route);
203
+        else
204
+            this.props.navigation.navigate("login", {nextScreen: route});
205
+    }
206
+
199 207
     renderItem = ({item}: { item: listItem }) => {
200 208
         return (
201 209
             <TouchableRipple

Loading…
Cancel
Save