Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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.

ErrorView.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // @flow
  2. import * as React from 'react';
  3. import {Button, Subheading, withTheme} from 'react-native-paper';
  4. import {StyleSheet, View} from "react-native";
  5. import {MaterialCommunityIcons} from "@expo/vector-icons";
  6. import i18n from 'i18n-js';
  7. import {ERROR_TYPE} from "../../managers/ConnectionManager";
  8. type Props = {
  9. navigation: Object,
  10. errorCode: number,
  11. onRefresh: Function,
  12. }
  13. type State = {
  14. refreshing: boolean,
  15. }
  16. class ErrorView extends React.PureComponent<Props, State> {
  17. colors: Object;
  18. message: string;
  19. icon: string;
  20. showLoginButton: boolean;
  21. state = {
  22. refreshing: false,
  23. };
  24. constructor(props) {
  25. super(props);
  26. this.colors = props.theme.colors;
  27. }
  28. generateMessage() {
  29. this.showLoginButton = false;
  30. switch (this.props.errorCode) {
  31. case ERROR_TYPE.BAD_CREDENTIALS:
  32. this.message = i18n.t("errors.badCredentials");
  33. this.icon = "account-alert-outline";
  34. break;
  35. case ERROR_TYPE.BAD_TOKEN:
  36. this.message = i18n.t("errors.badToken");
  37. this.icon = "account-alert-outline";
  38. this.showLoginButton = true;
  39. break;
  40. case ERROR_TYPE.NO_CONSENT:
  41. this.message = i18n.t("errors.noConsent");
  42. this.icon = "account-remove-outline";
  43. break;
  44. case ERROR_TYPE.BAD_INPUT:
  45. this.message = i18n.t("errors.badInput");
  46. this.icon = "alert-circle-outline";
  47. break;
  48. case ERROR_TYPE.FORBIDDEN:
  49. this.message = i18n.t("errors.forbidden");
  50. this.icon = "lock";
  51. break;
  52. case ERROR_TYPE.CONNECTION_ERROR:
  53. this.message = i18n.t("errors.connectionError");
  54. this.icon = "access-point-network-off";
  55. break;
  56. case ERROR_TYPE.SERVER_ERROR:
  57. this.message = i18n.t("errors.serverError");
  58. this.icon = "server-network-off";
  59. break;
  60. default:
  61. this.message = i18n.t("errors.unknown");
  62. this.icon = "alert-circle-outline";
  63. break;
  64. }
  65. }
  66. getRetryButton() {
  67. return <Button
  68. mode={'contained'}
  69. icon={'refresh'}
  70. onPress={this.props.onRefresh}
  71. style={styles.button}
  72. >
  73. {i18n.t("general.retry")}
  74. </Button>;
  75. }
  76. goToLogin = () => this.props.navigation.navigate("login");
  77. getLoginButton() {
  78. return <Button
  79. mode={'contained'}
  80. icon={'login'}
  81. onPress={this.goToLogin}
  82. style={styles.button}
  83. >
  84. {i18n.t("screens.login")}
  85. </Button>;
  86. }
  87. render() {
  88. this.generateMessage();
  89. return (
  90. <View style={{
  91. ...styles.outer,
  92. backgroundColor: this.colors.background
  93. }}>
  94. <View style={styles.inner}>
  95. <View style={styles.iconContainer}>
  96. <MaterialCommunityIcons
  97. name={this.icon}
  98. size={150}
  99. color={this.colors.textDisabled}/>
  100. </View>
  101. <Subheading style={{
  102. ...styles.subheading,
  103. color: this.colors.textDisabled
  104. }}>
  105. {this.message}
  106. </Subheading>
  107. {this.showLoginButton
  108. ? this.getLoginButton()
  109. : this.getRetryButton()}
  110. </View>
  111. </View>
  112. );
  113. }
  114. }
  115. const styles = StyleSheet.create({
  116. outer: {
  117. height: '100%',
  118. },
  119. inner: {
  120. marginTop: 'auto',
  121. marginBottom: 'auto',
  122. },
  123. iconContainer: {
  124. marginLeft: 'auto',
  125. marginRight: 'auto',
  126. marginBottom: 20
  127. },
  128. subheading: {
  129. textAlign: 'center',
  130. },
  131. button: {
  132. marginTop: 10,
  133. marginLeft: 'auto',
  134. marginRight: 'auto',
  135. }
  136. });
  137. export default withTheme(ErrorView);