mattermost-mobile/app/components/error_text/index.tsx
Daniel Espino García 86658edc30
Refactor errors around the app (#7306)
* Refactor errors around the app

* Fix recursive function

* Fix tests
2023-05-03 13:08:55 +02:00

46 lines
1.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {useIntl} from 'react-intl';
import {type StyleProp, Text, type TextStyle, type ViewStyle} from 'react-native';
import {useTheme} from '@context/theme';
import {getErrorMessage} from '@utils/errors';
import {makeStyleSheetFromTheme} from '@utils/theme';
type ErrorProps = {
error: unknown;
testID?: string;
textStyle?: StyleProp<ViewStyle> | StyleProp<TextStyle>;
}
const ErrorTextComponent = ({error, testID, textStyle}: ErrorProps) => {
const theme = useTheme();
const style = getStyleSheet(theme);
const intl = useIntl();
const message = getErrorMessage(error, intl);
return (
<Text
testID={testID}
style={[style.errorLabel, textStyle]}
>
{message}
</Text>
);
};
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
return {
errorLabel: {
color: (theme?.errorTextColor || '#DA4A4A'),
marginTop: 15,
marginBottom: 15,
fontSize: 12,
textAlign: 'left',
},
};
});
export default ErrorTextComponent;