Compare commits

...

4 commits

7 changed files with 245 additions and 82 deletions

37
components/AlertDialog.js Normal file
View file

@ -0,0 +1,37 @@
import * as React from 'react';
import {Button, Dialog, Paragraph, Portal, withTheme} from 'react-native-paper';
type Props = {
navigation: Object,
visible: boolean,
onDismiss: Function,
title: string,
message: string,
}
class AlertDialog extends React.PureComponent<Props> {
constructor(props) {
super(props);
}
render() {
return (
<Portal>
<Dialog
visible={this.props.visible}
onDismiss={this.props.onDismiss}>
<Dialog.Title>{this.props.title}</Dialog.Title>
<Dialog.Content>
<Paragraph>{this.props.message}</Paragraph>
</Dialog.Content>
<Dialog.Actions>
<Button onPress={this.props.onDismiss}>OK</Button>
</Dialog.Actions>
</Dialog>
</Portal>
);
}
}
export default withTheme(AlertDialog);

View file

@ -0,0 +1,81 @@
import * as React from 'react';
import {ActivityIndicator, Button, Dialog, Paragraph, Portal, withTheme} from 'react-native-paper';
import ConnectionManager from "../managers/ConnectionManager";
import i18n from 'i18n-js';
type Props = {
navigation: Object,
visible: boolean,
onDismiss: Function,
}
type State = {
loading: boolean,
}
class LogoutDialog extends React.PureComponent<Props, State> {
colors: Object;
state = {
loading: false,
};
constructor(props) {
super(props);
this.colors = props.theme.colors;
}
onClickAccept = () => {
this.setState({loading: true});
ConnectionManager.getInstance().disconnect()
.then(() => {
this.props.onDismiss();
this.setState({loading: false});
this.props.navigation.reset({
index: 0,
routes: [{name: 'Main'}],
});
});
};
onDismiss = () => {
if (!this.state.loading)
this.props.onDismiss();
};
render() {
return (
<Portal>
<Dialog
visible={this.props.visible}
onDismiss={this.onDismiss}>
<Dialog.Title>
{this.state.loading
? i18n.t("dialog.disconnect.titleLoading")
: i18n.t("dialog.disconnect.title")}
</Dialog.Title>
<Dialog.Content>
{this.state.loading
? <ActivityIndicator
animating={true}
size={'large'}
color={this.colors.primary}/>
: <Paragraph>{i18n.t("dialog.disconnect.message")}</Paragraph>
}
</Dialog.Content>
{this.state.loading
? null
: <Dialog.Actions>
<Button onPress={this.onDismiss} style={{marginRight: 10}}>{i18n.t("dialog.cancel")}</Button>
<Button onPress={this.onClickAccept}>{i18n.t("dialog.yes")}</Button>
</Dialog.Actions>
}
</Dialog>
</Portal>
);
}
}
export default withTheme(LogoutDialog);

View file

@ -1,13 +1,14 @@
// @flow
import * as React from 'react';
import {Alert, Dimensions, FlatList, Image, Platform, StyleSheet, View} from 'react-native';
import {Dimensions, FlatList, Image, Platform, StyleSheet, View,} from 'react-native';
import i18n from "i18n-js";
import {openBrowser} from "../utils/WebBrowser";
import SidebarDivider from "./SidebarDivider";
import SidebarItem from "./SidebarItem";
import {TouchableRipple, withTheme} from "react-native-paper";
import ConnectionManager from "../managers/ConnectionManager";
import LogoutDialog from "./LogoutDialog";
const deviceWidth = Dimensions.get("window").width;
@ -20,6 +21,7 @@ type Props = {
type State = {
active: string,
isLoggedIn: boolean,
dialogVisible: boolean,
};
/**
@ -47,7 +49,7 @@ class SideBar extends React.PureComponent<Props, State> {
icon: "home",
},
{
name: "AMICALE",
name: i18n.t('sidenav.divider4'),
route: "Divider4"
},
{
@ -65,7 +67,7 @@ class SideBar extends React.PureComponent<Props, State> {
{
name: i18n.t('screens.logout'),
route: 'disconnect',
action: () => this.onClickDisconnect(),
action: this.showDisconnectDialog,
icon: "logout",
onlyWhenLoggedIn: true,
},
@ -149,31 +151,15 @@ class SideBar extends React.PureComponent<Props, State> {
this.state = {
active: 'Home',
isLoggedIn: false,
dialogVisible: false,
};
ConnectionManager.getInstance().isLoggedIn()
ConnectionManager.getInstance().isLoggedIn().then(data => undefined).catch(error => undefined);
}
onClickDisconnect() {
Alert.alert(
'DISCONNECT',
'DISCONNECT?',
[
{
text: 'YES', onPress: () => {
ConnectionManager.getInstance().disconnect()
.then(() => {
this.props.navigation.reset({
index: 0,
routes: [{name: 'Main'}],
});
});
}
},
{text: 'NO', undefined},
],
{cancelable: false},
);
}
showDisconnectDialog = () => this.setState({ dialogVisible: true });
hideDisconnectDialog = () => this.setState({ dialogVisible: false });
onLoginStateChange(isLoggedIn: boolean) {
this.setState({isLoggedIn: isLoggedIn});
@ -250,6 +236,11 @@ class SideBar extends React.PureComponent<Props, State> {
keyExtractor={this.listKeyExtractor}
renderItem={this.getRenderItem}
/>
<LogoutDialog
{...this.props}
visible={this.state.dialogVisible}
onDismiss={this.hideDisconnectDialog}
/>
</View>
);
}

View file

@ -1,19 +1,12 @@
// @flow
import * as React from 'react';
import {
Alert,
Keyboard,
KeyboardAvoidingView,
ScrollView,
StyleSheet,
TouchableWithoutFeedback,
View
} from "react-native";
import {Keyboard, KeyboardAvoidingView, ScrollView, StyleSheet, TouchableWithoutFeedback, View} from "react-native";
import {Avatar, Button, Card, HelperText, Text, TextInput, withTheme} from 'react-native-paper';
import ConnectionManager, {ERROR_TYPE} from "../../managers/ConnectionManager";
import {openBrowser} from "../../utils/WebBrowser";
import i18n from 'i18n-js';
import AlertDialog from "../../components/AlertDialog";
type Props = {
navigation: Object,
@ -25,6 +18,9 @@ type State = {
isEmailValidated: boolean,
isPasswordValidated: boolean,
loading: boolean,
dialogVisible: boolean,
dialogTitle: string,
dialogMessage: string,
}
const ICON_AMICALE = require('../../assets/amicale.png');
@ -41,6 +37,9 @@ class LoginScreen extends React.Component<Props, State> {
isEmailValidated: false,
isPasswordValidated: false,
loading: false,
dialogVisible: false,
dialogTitle: '',
dialogMessage: '',
};
colors: Object;
@ -67,6 +66,15 @@ class LoginScreen extends React.Component<Props, State> {
this.colors = props.theme.colors;
}
showErrorDialog = (title: string, message: string) =>
this.setState({
dialogTitle: title,
dialogMessage: message,
dialogVisible: true
});
hideErrorDialog = () => this.setState({ dialogVisible: false });
onResetPasswordClick() {
openBrowser(RESET_PASSWORD_LINK, this.colors.primary);
}
@ -96,7 +104,7 @@ class LoginScreen extends React.Component<Props, State> {
}
shouldEnableLogin() {
return this.isEmailValid() && this.isPasswordValid();
return this.isEmailValid() && this.isPasswordValid() && !this.state.loading;
}
onInputChange(isEmail: boolean, value: string) {
@ -157,7 +165,7 @@ class LoginScreen extends React.Component<Props, State> {
message = i18n.t("loginScreen.errors.unknown");
break;
}
Alert.alert(title, message);
this.showErrorDialog(title, message);
}
getFormInput() {
@ -279,6 +287,13 @@ class LoginScreen extends React.Component<Props, State> {
{this.getSecondaryCard()}
</View>
</TouchableWithoutFeedback>
<AlertDialog
{...this.props}
visible={this.state.dialogVisible}
title={this.state.dialogTitle}
message={this.state.dialogMessage}
onDismiss={this.hideErrorDialog}
/>
</ScrollView>
</KeyboardAvoidingView>
);

View file

@ -1,22 +1,26 @@
import * as React from 'react';
import {FlatList, StyleSheet} from "react-native";
import {FlatList, StyleSheet, View} from "react-native";
import {Avatar, Button, Card, Divider, List, withTheme} from 'react-native-paper';
import AuthenticatedScreen from "../../components/AuthenticatedScreen";
import {openBrowser} from "../../utils/WebBrowser";
import ConnectionManager from "../../managers/ConnectionManager";
import HeaderButton from "../../components/HeaderButton";
import i18n from 'i18n-js';
import LogoutDialog from "../../components/LogoutDialog";
type Props = {
navigation: Object,
theme: Object,
}
type State = {}
type State = {
dialogVisible: boolean,
}
class ProfileScreen extends React.Component<Props, State> {
state = {};
state = {
dialogVisible: false,
};
colors: Object;
@ -27,11 +31,10 @@ class ProfileScreen extends React.Component<Props, State> {
constructor(props) {
super(props);
this.colors = props.theme.colors;
this.onClickDisconnect = this.onClickDisconnect.bind(this);
this.flatListData = [
{id: 0},
{id: 1},
{id: 2},
{id: '0'},
{id: '1'},
{id: '2'},
]
}
@ -42,38 +45,40 @@ class ProfileScreen extends React.Component<Props, State> {
});
}
getHeaderButtons() {
return <HeaderButton icon={'logout'} onPress={this.onClickDisconnect}/>;
}
showDisconnectDialog = () => this.setState({ dialogVisible: true });
onClickDisconnect() {
ConnectionManager.getInstance().disconnect()
.then(() => {
this.props.navigation.reset({
index: 0,
routes: [{name: 'Main'}],
});
});
hideDisconnectDialog = () => this.setState({ dialogVisible: false });
getHeaderButtons() {
return <HeaderButton icon={'logout'} onPress={this.showDisconnectDialog}/>;
}
getScreen(data: Object) {
this.data = data;
return (
<FlatList
renderItem={item => this.getRenderItem(item)}
keyExtractor={item => item.id}
data={this.flatListData}
/>
<View>
<FlatList
renderItem={item => this.getRenderItem(item)}
keyExtractor={item => item.id}
data={this.flatListData}
/>
<LogoutDialog
{...this.props}
visible={this.state.dialogVisible}
onDismiss={this.hideDisconnectDialog}
/>
</View>
)
}
getRenderItem({item}: Object) {
switch (item.id) {
case 0:
case '0':
return this.getPersonalCard();
case 1:
case '1':
return this.getClubCard();
case 2:
case '2':
return this.getMembershipCar();
}
}
@ -96,22 +101,10 @@ class ProfileScreen extends React.Component<Props, State> {
<Divider/>
<List.Section>
<List.Subheader>{i18n.t("profileScreen.personalInformation")}</List.Subheader>
<List.Item
title={this.getFieldValue(this.data.birthday)}
left={props => <List.Icon {...props} icon="cake-variant"/>}
/>
<List.Item
title={this.getFieldValue(this.data.phone)}
left={props => <List.Icon {...props} icon="phone"/>}
/>
<List.Item
title={this.getFieldValue(this.data.email)}
left={props => <List.Icon {...props} icon="email"/>}
/>
<List.Item
title={this.getFieldValue(this.data.branch)}
left={props => <List.Icon {...props} icon="school"/>}
/>
{this.getPersonalListItem(this.data.birthday, "cake-variant")}
{this.getPersonalListItem(this.data.phone, "phone")}
{this.getPersonalListItem(this.data.email, "email")}
{this.getPersonalListItem(this.data.branch, "school")}
</List.Section>
<Divider/>
<Card.Actions>
@ -203,12 +196,36 @@ class ProfileScreen extends React.Component<Props, State> {
);
}
isFieldAvailable(field: ?string) {
return field !== null;
}
getFieldValue(field: ?string) {
return field !== null
return this.isFieldAvailable(field)
? field
: i18n.t("profileScreen.noData");
}
getFieldColor(field: ?string) {
return this.isFieldAvailable(field)
? this.colors.text
: this.colors.textDisabled;
}
getPersonalListItem(field: ?string, icon: string) {
return (
<List.Item
title={this.getFieldValue(field)}
left={props => <List.Icon
{...props}
icon={icon}
color={this.getFieldColor(field)}
/>}
titleStyle={{color: this.getFieldColor(field)}}
/>
);
}
render() {
return (
<AuthenticatedScreen

View file

@ -20,7 +20,8 @@
"sidenav": {
"divider1": "Student websites",
"divider2": "Services",
"divider3": "Personalisation"
"divider3": "Personalisation",
"divider4": "Amicale"
},
"intro": {
"slide1": {
@ -241,6 +242,16 @@
"unknown": "Unknown error, please contact support."
}
},
"dialog": {
"ok": "OK",
"yes": "Yes",
"cancel": "Cancel",
"disconnect": {
"title": "Disconnect",
"titleLoading": "Disconnecting...",
"message": "Are you sure you want to disconnect from your Amicale account?"
}
},
"general": {
"loading": "Loading...",
"networkError": "Unable to contact servers. Make sure you are connected to Internet."

View file

@ -20,7 +20,8 @@
"sidenav": {
"divider1": "Sites étudiants",
"divider2": "Services",
"divider3": "Personnalisation"
"divider3": "Personnalisation",
"divider4": "Amicale"
},
"intro": {
"slide1": {
@ -242,6 +243,16 @@
"unknown": "Erreur inconnue, merci de contacter le support."
}
},
"dialog": {
"ok": "OK",
"yes": "Oui",
"cancel": "Annuler",
"disconnect": {
"title": "Déconnexion",
"titleLoading": "Déconnexion...",
"message": "Voulez vous vraiment vous déconnecter de votre compte Amicale ??"
}
},
"general": {
"loading": "Chargement...",
"networkError": "Impossible de contacter les serveurs. Assurez-vous d'être connecté à internet."