All files / packages/app/components error-message.tsx

100% Statements 3/3
100% Branches 4/4
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                        279x           274x 274x                                                  
import React from "react";
 
import { useTranslation } from "react-i18next";
 
import { Button } from "~components/button";
import { Card } from "~components/card";
import { Icon } from "~components/icons";
import { Text } from "~components/text";
import { View } from "~components/view";
 
type Props = {
	title?: string;
	message: string;
	stack?: string;
	button?: {
		text: string;
		onPress: () => void;
	};
};
 
export const ErrorMessage: React.FC<Props> = ({
	title,
	message,
	stack,
	button,
}) => {
	const { t } = useTranslation("default");
	return (
		<Card
			testID="error-message"
			header={
				<View className="text-danger flex flex-row gap-2">
					<Icon name="warning" className="size-8" />
					<Text variant="h3" className="text-danger">
						{title || t("components.errorMessage.error")}
					</Text>
				</View>
			}
			footerClassName="flex flex-row justify-end"
			footer={
				button ? (
					<Button color="primary" onPress={button.onPress}>
						{button.text}
					</Button>
				) : null
			}
		>
			<Text className="whitespace-pre-wrap">{message}</Text>
			<Text className="text-sm whitespace-pre-wrap">{stack}</Text>
		</Card>
	);
};