mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {
3 StyleSheet,
4 TouchableOpacity,
5 StyleProp,
6 View,
7 ViewStyle,
8} from 'react-native'
9import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
10import {Text} from '../text/Text'
11import {useTheme} from '../../../lib/ThemeContext'
12import {usePalette} from '../../../lib/hooks/usePalette'
13
14export function ErrorMessage({
15 message,
16 numberOfLines,
17 style,
18 onPressTryAgain,
19}: {
20 message: string
21 numberOfLines?: number
22 style?: StyleProp<ViewStyle>
23 onPressTryAgain?: () => void
24}) {
25 const theme = useTheme()
26 const pal = usePalette('error')
27 return (
28 <View testID="errorMessageView" style={[styles.outer, pal.view, style]}>
29 <View
30 style={[styles.errorIcon, {backgroundColor: theme.palette.error.icon}]}>
31 <FontAwesomeIcon icon="exclamation" style={pal.text} size={16} />
32 </View>
33 <Text
34 type="body2"
35 style={[styles.message, pal.text]}
36 numberOfLines={numberOfLines}>
37 {message}
38 </Text>
39 {onPressTryAgain && (
40 <TouchableOpacity
41 testID="errorMessageTryAgainButton"
42 style={styles.btn}
43 onPress={onPressTryAgain}>
44 <FontAwesomeIcon
45 icon="arrows-rotate"
46 style={{color: theme.palette.error.icon}}
47 size={18}
48 />
49 </TouchableOpacity>
50 )}
51 </View>
52 )
53}
54
55const styles = StyleSheet.create({
56 outer: {
57 flexDirection: 'row',
58 alignItems: 'center',
59 paddingVertical: 8,
60 paddingHorizontal: 8,
61 },
62 errorIcon: {
63 borderRadius: 12,
64 width: 24,
65 height: 24,
66 alignItems: 'center',
67 justifyContent: 'center',
68 marginRight: 8,
69 },
70 message: {
71 flex: 1,
72 paddingRight: 10,
73 },
74 btn: {
75 paddingHorizontal: 4,
76 paddingVertical: 4,
77 },
78})