1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00
unleash.unleash/frontend/src/component/layout/Error/Error.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

60 lines
1.9 KiB
TypeScript

import { useEffect, VFC } from 'react';
import { useNavigate } from 'react-router-dom';
import { Box } from '@mui/material';
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
interface IErrorProps {
error: Error;
}
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
export const Error: VFC<IErrorProps> = ({ error }) => {
const navigate = useNavigate();
const { trackEvent } = usePlausibleTracker();
useEffect(() => {
const { message, stack = 'unknown' } = error;
trackEvent('unknown_ui_error', {
props: {
location: window?.location?.href || 'unknown',
message,
stack,
},
});
}, []);
return (
<Box sx={{ backgroundColor: 'neutral.light', height: '100%', p: 4 }}>
<Dialogue
open={true}
title='Something went wrong'
primaryButtonText='Go back'
onClick={() => {
navigate('/');
window?.location?.reload();
}}
secondaryButtonText='Reload this page'
onClose={() => {
window?.location?.reload();
}}
maxWidth='xl'
>
<Box component='pre' sx={{ color: 'error.main' }}>
{error.message}
</Box>
<ConditionallyRender
condition={Boolean(error.stack)}
show={
<Box component='pre' sx={{ color: 'error.main' }}>
{error.stack}
</Box>
}
/>
</Dialogue>
</Box>
);
};