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.3KB

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