Improved translations and improved alert popup

This commit is contained in:
Arnaud Vergnet 2020-04-01 14:25:25 +02:00
parent f10242b187
commit ee13d099fe
5 changed files with 91 additions and 14 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

@ -1,6 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import {ActivityIndicator, Button, Dialog, Paragraph, Portal, withTheme} from 'react-native-paper'; import {ActivityIndicator, Button, Dialog, Paragraph, Portal, withTheme} from 'react-native-paper';
import ConnectionManager from "../managers/ConnectionManager"; import ConnectionManager from "../managers/ConnectionManager";
import i18n from 'i18n-js';
type Props = { type Props = {
navigation: Object, navigation: Object,
@ -49,21 +50,25 @@ class LogoutDialog extends React.PureComponent<Props, State> {
<Dialog <Dialog
visible={this.props.visible} visible={this.props.visible}
onDismiss={this.onDismiss}> onDismiss={this.onDismiss}>
<Dialog.Title>DISCONNECT</Dialog.Title> <Dialog.Title>
{this.state.loading
? i18n.t("dialog.disconnect.titleLoading")
: i18n.t("dialog.disconnect.title")}
</Dialog.Title>
<Dialog.Content> <Dialog.Content>
{this.state.loading {this.state.loading
? <ActivityIndicator ? <ActivityIndicator
animating={true} animating={true}
size={'large'} size={'large'}
color={this.colors.primary}/> color={this.colors.primary}/>
: <Paragraph>DISCONNECT?</Paragraph> : <Paragraph>{i18n.t("dialog.disconnect.message")}</Paragraph>
} }
</Dialog.Content> </Dialog.Content>
{this.state.loading {this.state.loading
? null ? null
: <Dialog.Actions> : <Dialog.Actions>
<Button onPress={this.onClickAccept}>YES</Button> <Button onPress={this.onDismiss} style={{marginRight: 10}}>{i18n.t("dialog.cancel")}</Button>
<Button onPress={this.onDismiss}>NO</Button> <Button onPress={this.onClickAccept}>{i18n.t("dialog.yes")}</Button>
</Dialog.Actions> </Dialog.Actions>
} }

View file

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

View file

@ -241,6 +241,16 @@
"unknown": "Unknown error, please contact support." "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": { "general": {
"loading": "Loading...", "loading": "Loading...",
"networkError": "Unable to contact servers. Make sure you are connected to Internet." "networkError": "Unable to contact servers. Make sure you are connected to Internet."

View file

@ -242,6 +242,16 @@
"unknown": "Erreur inconnue, merci de contacter le support." "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": { "general": {
"loading": "Chargement...", "loading": "Chargement...",
"networkError": "Impossible de contacter les serveurs. Assurez-vous d'être connecté à internet." "networkError": "Impossible de contacter les serveurs. Assurez-vous d'être connecté à internet."