Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogoutDialog.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // @flow
  2. import * as React from 'react';
  3. import {ActivityIndicator, Button, Dialog, Paragraph, Portal, withTheme} from 'react-native-paper';
  4. import ConnectionManager from "../../managers/ConnectionManager";
  5. import i18n from 'i18n-js';
  6. type Props = {
  7. navigation: Object,
  8. visible: boolean,
  9. onDismiss: Function,
  10. }
  11. type State = {
  12. loading: boolean,
  13. }
  14. class LogoutDialog extends React.PureComponent<Props, State> {
  15. colors: Object;
  16. state = {
  17. loading: false,
  18. };
  19. constructor(props) {
  20. super(props);
  21. this.colors = props.theme.colors;
  22. }
  23. onClickAccept = () => {
  24. this.setState({loading: true});
  25. ConnectionManager.getInstance().disconnect()
  26. .then(() => {
  27. this.props.onDismiss();
  28. this.setState({loading: false});
  29. this.props.navigation.reset({
  30. index: 0,
  31. routes: [{name: 'Main'}],
  32. });
  33. });
  34. };
  35. onDismiss = () => {
  36. if (!this.state.loading)
  37. this.props.onDismiss();
  38. };
  39. render() {
  40. return (
  41. <Portal>
  42. <Dialog
  43. visible={this.props.visible}
  44. onDismiss={this.onDismiss}>
  45. <Dialog.Title>
  46. {this.state.loading
  47. ? i18n.t("dialog.disconnect.titleLoading")
  48. : i18n.t("dialog.disconnect.title")}
  49. </Dialog.Title>
  50. <Dialog.Content>
  51. {this.state.loading
  52. ? <ActivityIndicator
  53. animating={true}
  54. size={'large'}
  55. color={this.colors.primary}/>
  56. : <Paragraph>{i18n.t("dialog.disconnect.message")}</Paragraph>
  57. }
  58. </Dialog.Content>
  59. {this.state.loading
  60. ? null
  61. : <Dialog.Actions>
  62. <Button onPress={this.onDismiss} style={{marginRight: 10}}>{i18n.t("dialog.cancel")}</Button>
  63. <Button onPress={this.onClickAccept}>{i18n.t("dialog.yes")}</Button>
  64. </Dialog.Actions>
  65. }
  66. </Dialog>
  67. </Portal>
  68. );
  69. }
  70. }
  71. export default withTheme(LogoutDialog);