diff --git a/src/components/Amicale/AuthenticatedScreen.js b/src/components/Amicale/AuthenticatedScreen.js index 8d70a35..4d5ae69 100644 --- a/src/components/Amicale/AuthenticatedScreen.js +++ b/src/components/Amicale/AuthenticatedScreen.js @@ -3,8 +3,7 @@ import * as React from 'react'; import {withTheme} from 'react-native-paper'; import ConnectionManager, {ERROR_TYPE} from "../../managers/ConnectionManager"; -import NetworkErrorComponent from "../Custom/NetworkErrorComponent"; -import i18n from 'i18n-js'; +import ErrorView from "../Custom/ErrorView"; import BasicLoadingScreen from "../Custom/BasicLoadingScreen"; type Props = { @@ -98,32 +97,9 @@ class AuthenticatedScreen extends React.Component { } getErrorRender() { - let message; - let icon; - switch (this.errorCode) { - case ERROR_TYPE.BAD_CREDENTIALS: - message = i18n.t("loginScreen.errors.credentials"); - icon = "account-alert-outline"; - break; - case ERROR_TYPE.BAD_TOKEN: - message = "BAD TOKEN"; // TODO translate - icon = "access-point-network-off"; - break; - case ERROR_TYPE.CONNECTION_ERROR: - message = i18n.t("loginScreen.errors.connection"); - icon = "access-point-network-off"; - break; - default: - message = i18n.t("loginScreen.errors.unknown"); - icon = "alert-circle-outline"; - break; - } - return ( - ); diff --git a/src/components/Custom/NetworkErrorComponent.js b/src/components/Custom/ErrorView.js similarity index 51% rename from src/components/Custom/NetworkErrorComponent.js rename to src/components/Custom/ErrorView.js index ba54d9d..273dfed 100644 --- a/src/components/Custom/NetworkErrorComponent.js +++ b/src/components/Custom/ErrorView.js @@ -5,10 +5,10 @@ import {Button, Subheading, withTheme} from 'react-native-paper'; import {StyleSheet, View} from "react-native"; import {MaterialCommunityIcons} from "@expo/vector-icons"; import i18n from 'i18n-js'; +import {ERROR_TYPE} from "../../managers/ConnectionManager"; type Props = { - message: string, - icon: string, + errorCode: number, onRefresh: Function, } @@ -16,10 +16,13 @@ type State = { refreshing: boolean, } -class NetworkErrorComponent extends React.PureComponent { +class ErrorView extends React.PureComponent { colors: Object; + message: string; + icon: string; + state = { refreshing: false, }; @@ -29,7 +32,45 @@ class NetworkErrorComponent extends React.PureComponent { this.colors = props.theme.colors; } + generateMessage() { + switch (this.props.errorCode) { + case ERROR_TYPE.BAD_CREDENTIALS: + this.message = i18n.t("errors.badCredentials"); + this.icon = "account-alert-outline"; + break; + case ERROR_TYPE.BAD_TOKEN: + this.message = i18n.t("errors.badToken"); + this.icon = "account-alert-outline"; + break; + case ERROR_TYPE.NO_CONSENT: + this.message = i18n.t("errors.noConsent"); + this.icon = "account-remove-outline"; + break; + case ERROR_TYPE.BAD_INPUT: + this.message = i18n.t("errors.badInput"); + this.icon = "alert-circle-outline"; + break; + case ERROR_TYPE.FORBIDDEN: + this.message = i18n.t("errors.forbidden"); + this.icon = "lock"; + break; + case ERROR_TYPE.CONNECTION_ERROR: + this.message = i18n.t("errors.connectionError"); + this.icon = "access-point-network-off"; + break; + case ERROR_TYPE.SERVER_ERROR: + this.message = i18n.t("errors.serverError"); + this.icon = "server-network-off"; + break; + default: + this.message = i18n.t("errors.unknown"); + this.icon = "alert-circle-outline"; + break; + } + } + render() { + this.generateMessage(); return ( { @@ -46,7 +87,7 @@ class NetworkErrorComponent extends React.PureComponent { ...styles.subheading, color: this.colors.textDisabled }}> - {this.props.message} + {this.message}