headplane/app/components/Error.tsx

40 lines
1 KiB
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { AlertIcon } from '@primer/octicons-react';
import { isRouteErrorResponse, useRouteError } from 'react-router';
import { cn } from '~/utils/cn';
import Card from './Card';
import Code from './Code';
2024-12-31 10:30:14 +05:30
interface Props {
type?: 'full' | 'embedded';
2024-03-29 16:14:35 -04:00
}
2024-12-31 10:30:14 +05:30
export function ErrorPopup({ type = 'full' }: Props) {
const error = useRouteError();
const routing = isRouteErrorResponse(error);
const message =
error instanceof Error ? error.message : 'An unexpected error occurred';
2024-03-29 16:14:35 -04:00
return (
<div
className={cn(
'flex items-center justify-center',
type === 'embedded'
? 'pointer-events-none mt-24'
2024-12-31 10:30:14 +05:30
: 'fixed inset-0 h-screen w-screen z-50',
)}
>
<Card>
2024-12-31 10:30:14 +05:30
<div className="flex items-center justify-between">
<Card.Title className="text-3xl mb-0">
{routing ? error.status : 'Error'}
</Card.Title>
2024-12-31 10:30:14 +05:30
<AlertIcon className="w-12 h-12 text-red-500" />
</div>
2024-12-31 10:30:14 +05:30
<Card.Text className="mt-4 text-lg">
{routing ? error.statusText : <Code>{message}</Code>}
</Card.Text>
</Card>
</div>
2024-12-31 10:30:14 +05:30
);
2024-03-29 16:14:35 -04:00
}