2023-01-10 11:33:56 +01:00
|
|
|
import { useEffect, VFC } from 'react';
|
2022-10-10 12:18:37 +02:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
2022-11-30 10:52:13 +01:00
|
|
|
import { Box } from '@mui/material';
|
2022-10-10 12:18:37 +02:00
|
|
|
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2023-01-10 11:33:56 +01:00
|
|
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
2022-10-10 12:18:37 +02:00
|
|
|
|
|
|
|
interface IErrorProps {
|
|
|
|
error: Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Error: VFC<IErrorProps> = ({ error }) => {
|
|
|
|
const navigate = useNavigate();
|
2023-01-10 11:33:56 +01:00
|
|
|
const { trackEvent } = usePlausibleTracker();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const { message, stack = 'unknown' } = error;
|
|
|
|
|
|
|
|
trackEvent('unknown_ui_error', {
|
|
|
|
props: {
|
|
|
|
location: window?.location?.href || 'unknown',
|
|
|
|
message,
|
|
|
|
stack,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
2022-10-10 12:18:37 +02:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
};
|