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

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);
}
@ -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

@ -241,6 +241,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

@ -242,6 +242,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."