Improved login flow
This commit is contained in:
parent
92fce1d425
commit
fc7754588f
2 changed files with 93 additions and 29 deletions
|
@ -8,8 +8,9 @@ import {withCollapsible} from "../../utils/withCollapsible";
|
||||||
import {Collapsible} from "react-navigation-collapsible";
|
import {Collapsible} from "react-navigation-collapsible";
|
||||||
import {CommonActions} from "@react-navigation/native";
|
import {CommonActions} from "@react-navigation/native";
|
||||||
import {Animated, View} from "react-native";
|
import {Animated, View} from "react-native";
|
||||||
import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-native-paper";
|
import {Avatar, Button, Card, Divider, List, Title, TouchableRipple, withTheme} from "react-native-paper";
|
||||||
import type {CustomTheme} from "../../managers/ThemeManager";
|
import type {CustomTheme} from "../../managers/ThemeManager";
|
||||||
|
import ConnectionManager from "../../managers/ConnectionManager";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: Object,
|
navigation: Object,
|
||||||
|
@ -29,14 +30,19 @@ const AMICALE_IMAGE = require("../../../assets/amicale.png");
|
||||||
const EE_IMAGE = "https://etud.insa-toulouse.fr/~eeinsat/wp-content/uploads/2019/09/logo-blanc.png";
|
const EE_IMAGE = "https://etud.insa-toulouse.fr/~eeinsat/wp-content/uploads/2019/09/logo-blanc.png";
|
||||||
const TUTORINSA_IMAGE = "https://www.etud.insa-toulouse.fr/~tutorinsa/public/images/logo-gray.png";
|
const TUTORINSA_IMAGE = "https://www.etud.insa-toulouse.fr/~tutorinsa/public/images/logo-gray.png";
|
||||||
|
|
||||||
type listItem = {
|
export type listItem = {
|
||||||
title: string,
|
title: string,
|
||||||
description: string,
|
description: string,
|
||||||
image: string | number,
|
image: string | number,
|
||||||
|
shouldLogin: boolean,
|
||||||
content: cardList,
|
content: cardList,
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServicesScreen extends React.Component<Props> {
|
type State = {
|
||||||
|
isLoggedIn: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServicesScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
amicaleDataset: cardList;
|
amicaleDataset: cardList;
|
||||||
studentsDataset: cardList;
|
studentsDataset: cardList;
|
||||||
|
@ -148,29 +154,40 @@ class ServicesScreen extends React.Component<Props> {
|
||||||
title: "AMICALE",
|
title: "AMICALE",
|
||||||
description: "LOGIN",
|
description: "LOGIN",
|
||||||
image: AMICALE_IMAGE,
|
image: AMICALE_IMAGE,
|
||||||
|
shouldLogin: true,
|
||||||
content: this.amicaleDataset
|
content: this.amicaleDataset
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "STUDENTS",
|
title: "STUDENTS",
|
||||||
description: "SERVICES OFFERED BY STUDENTS",
|
description: "SERVICES OFFERED BY STUDENTS",
|
||||||
image: 'account-group',
|
image: 'account-group',
|
||||||
|
shouldLogin: false,
|
||||||
content: this.studentsDataset
|
content: this.studentsDataset
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "INSA",
|
title: "INSA",
|
||||||
description: "SERVICES OFFERED BY INSA",
|
description: "SERVICES OFFERED BY INSA",
|
||||||
image: 'school',
|
image: 'school',
|
||||||
|
shouldLogin: false,
|
||||||
content: this.insaDataset
|
content: this.insaDataset
|
||||||
},
|
},
|
||||||
]
|
];
|
||||||
|
this.state = {
|
||||||
|
isLoggedIn: ConnectionManager.getInstance().isLoggedIn()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.navigation.addListener('focus', this.handleNavigationParams);
|
this.props.navigation.addListener('focus', this.onFocus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNavigationParams = () => {
|
onFocus = () => {
|
||||||
|
this.handleNavigationParams();
|
||||||
|
this.setState({isLoggedIn: ConnectionManager.getInstance().isLoggedIn()})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleNavigationParams() {
|
||||||
if (this.props.route.params != null) {
|
if (this.props.route.params != null) {
|
||||||
if (this.props.route.params.nextScreen != null) {
|
if (this.props.route.params.nextScreen != null) {
|
||||||
this.props.navigation.navigate(this.props.route.params.nextScreen);
|
this.props.navigation.navigate(this.props.route.params.nextScreen);
|
||||||
|
@ -198,25 +215,57 @@ class ServicesScreen extends React.Component<Props> {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLoginMessage() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Title style={{
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginRight: 'auto',
|
||||||
|
}}>
|
||||||
|
NOT LOGGED IN
|
||||||
|
</Title>
|
||||||
|
<Button
|
||||||
|
icon="login"
|
||||||
|
mode="contained"
|
||||||
|
onPress={() => this.props.navigation.navigate("login")}
|
||||||
|
style={{
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginRight: 'auto',
|
||||||
|
}}>
|
||||||
|
LOGIN
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
renderItem = ({item}: { item: listItem }) => {
|
renderItem = ({item}: { item: listItem }) => {
|
||||||
|
const shouldShowLogin = !this.state.isLoggedIn && item.shouldLogin;
|
||||||
return (
|
return (
|
||||||
<TouchableRipple
|
<TouchableRipple
|
||||||
style={{
|
style={{
|
||||||
margin: 5,
|
margin: 5,
|
||||||
marginBottom: 20,
|
marginBottom: 20,
|
||||||
}}
|
}}
|
||||||
onPress={() => this.props.navigation.navigate("services-section", {data: item})}
|
onPress={shouldShowLogin
|
||||||
|
? undefined
|
||||||
|
: () => this.props.navigation.navigate("services-section", {data: item})}
|
||||||
>
|
>
|
||||||
<View>
|
<View>
|
||||||
<Card.Title
|
<Card.Title
|
||||||
title={item.title}
|
title={item.title}
|
||||||
left={(props) => this.getAvatar(props, item.image)}
|
left={(props) => this.getAvatar(props, item.image)}
|
||||||
right={(props) => <List.Icon {...props} icon="chevron-right"/>}
|
right={shouldShowLogin
|
||||||
|
? undefined
|
||||||
|
: (props) => <List.Icon {...props} icon="chevron-right"/>}
|
||||||
/>
|
/>
|
||||||
<CardList
|
{
|
||||||
|
shouldShowLogin
|
||||||
|
? this.getLoginMessage()
|
||||||
|
: <CardList
|
||||||
dataset={item.content}
|
dataset={item.content}
|
||||||
isHorizontal={true}
|
isHorizontal={true}
|
||||||
/>
|
/>
|
||||||
|
}
|
||||||
</View>
|
</View>
|
||||||
</TouchableRipple>
|
</TouchableRipple>
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import type {cardList} from "../../components/Lists/CardList/CardList";
|
|
||||||
import CardList from "../../components/Lists/CardList/CardList";
|
import CardList from "../../components/Lists/CardList/CardList";
|
||||||
import CustomTabBar from "../../components/Tabbar/CustomTabBar";
|
import CustomTabBar from "../../components/Tabbar/CustomTabBar";
|
||||||
import {withCollapsible} from "../../utils/withCollapsible";
|
import {withCollapsible} from "../../utils/withCollapsible";
|
||||||
import {Collapsible} from "react-navigation-collapsible";
|
import {Collapsible} from "react-navigation-collapsible";
|
||||||
import {CommonActions} from "@react-navigation/native";
|
import {CommonActions} from "@react-navigation/native";
|
||||||
|
import ConnectionManager from "../../managers/ConnectionManager";
|
||||||
|
import type {listItem} from "./ServicesScreen";
|
||||||
|
import ErrorView from "../../components/Screens/ErrorView";
|
||||||
|
import {ERROR_TYPE} from "../../utils/WebData";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: Object,
|
navigation: Object,
|
||||||
|
@ -14,20 +17,29 @@ type Props = {
|
||||||
collapsibleStack: Collapsible,
|
collapsibleStack: Collapsible,
|
||||||
}
|
}
|
||||||
|
|
||||||
type listItem = {
|
type State = {
|
||||||
title: string,
|
isLoggedIn: boolean,
|
||||||
description: string,
|
|
||||||
image: string | number,
|
|
||||||
content: cardList,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServicesSectionScreen extends React.Component<Props> {
|
class ServicesSectionScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
finalDataset: listItem;
|
finalDataset: listItem;
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.handleNavigationParams();
|
this.handleNavigationParams();
|
||||||
|
this.state = {
|
||||||
|
isLoggedIn: ConnectionManager.getInstance().isLoggedIn(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.props.navigation.addListener('focus', this.onFocus);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
onFocus = () => {
|
||||||
|
this.setState({isLoggedIn: ConnectionManager.getInstance().isLoggedIn()})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNavigationParams() {
|
handleNavigationParams() {
|
||||||
|
@ -45,6 +57,9 @@ class ServicesSectionScreen extends React.Component<Props> {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack;
|
const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack;
|
||||||
|
if (!this.state.isLoggedIn && this.finalDataset.shouldLogin)
|
||||||
|
return <ErrorView {...this.props} errorCode={ERROR_TYPE.BAD_TOKEN}/>;
|
||||||
|
else
|
||||||
return <CardList
|
return <CardList
|
||||||
dataset={this.finalDataset.content}
|
dataset={this.finalDataset.content}
|
||||||
isHorizontal={false}
|
isHorizontal={false}
|
||||||
|
|
Loading…
Reference in a new issue