2020-04-02 09:52:43 +02:00
|
|
|
// @flow
|
|
|
|
|
2020-04-01 13:01:28 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
import {ActivityIndicator, Button, Dialog, Paragraph, Portal, withTheme} from 'react-native-paper';
|
2020-04-02 10:07:20 +02:00
|
|
|
import ConnectionManager from "../../managers/ConnectionManager";
|
2020-04-01 14:25:25 +02:00
|
|
|
import i18n from 'i18n-js';
|
2020-04-01 13:01:28 +02:00
|
|
|
|
|
|
|
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}>
|
2020-04-01 14:25:25 +02:00
|
|
|
<Dialog.Title>
|
|
|
|
{this.state.loading
|
|
|
|
? i18n.t("dialog.disconnect.titleLoading")
|
|
|
|
: i18n.t("dialog.disconnect.title")}
|
|
|
|
</Dialog.Title>
|
2020-04-01 13:01:28 +02:00
|
|
|
<Dialog.Content>
|
|
|
|
{this.state.loading
|
|
|
|
? <ActivityIndicator
|
|
|
|
animating={true}
|
|
|
|
size={'large'}
|
|
|
|
color={this.colors.primary}/>
|
2020-04-01 14:25:25 +02:00
|
|
|
: <Paragraph>{i18n.t("dialog.disconnect.message")}</Paragraph>
|
2020-04-01 13:01:28 +02:00
|
|
|
}
|
|
|
|
</Dialog.Content>
|
|
|
|
{this.state.loading
|
|
|
|
? null
|
|
|
|
: <Dialog.Actions>
|
2020-04-01 14:25:25 +02:00
|
|
|
<Button onPress={this.onDismiss} style={{marginRight: 10}}>{i18n.t("dialog.cancel")}</Button>
|
|
|
|
<Button onPress={this.onClickAccept}>{i18n.t("dialog.yes")}</Button>
|
2020-04-01 13:01:28 +02:00
|
|
|
</Dialog.Actions>
|
|
|
|
}
|
|
|
|
|
|
|
|
</Dialog>
|
|
|
|
</Portal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withTheme(LogoutDialog);
|