feishin/src/renderer/features/action-required/components/route-error-boundary.tsx

67 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-01-08 02:08:19 -08:00
import { Center, Stack, Group, Divider, Box } from '@mantine/core';
import { RiArrowLeftSLine, RiErrorWarningLine, RiHome4Line } from 'react-icons/ri';
2023-01-07 23:09:58 -08:00
import { useNavigate, useRouteError } from 'react-router';
2023-01-08 02:08:19 -08:00
import { Button, Text } from '/@/renderer/components';
2023-01-07 23:09:58 -08:00
import { AppRoute } from '/@/renderer/router/routes';
const RouteErrorBoundary = () => {
const navigate = useNavigate();
const error = useRouteError() as any;
console.log('error', error);
const handleReload = () => {
navigate(0);
};
const handleReturn = () => {
navigate(-1);
};
const handleHome = () => {
navigate(AppRoute.HOME);
};
return (
2023-01-08 02:08:19 -08:00
<Box bg="var(--main-bg)">
2023-01-07 23:09:58 -08:00
<Center sx={{ height: '100vh' }}>
<Stack sx={{ maxWidth: '50%' }}>
<Group>
<Button
px={10}
variant="subtle"
onClick={handleReturn}
>
<RiArrowLeftSLine size={20} />
</Button>
<RiErrorWarningLine
color="var(--danger-color)"
size={30}
/>
<Text size="lg">Something went wrong</Text>
</Group>
<Divider my={5} />
<Text size="sm">{error?.message}</Text>
<Group grow>
<Button
2023-01-08 02:08:19 -08:00
leftIcon={<RiHome4Line />}
2023-01-07 23:09:58 -08:00
sx={{ flex: 0.5 }}
variant="default"
onClick={handleHome}
>
Go home
</Button>
<Button
variant="filled"
onClick={handleReload}
>
Reload
</Button>
</Group>
</Stack>
</Center>
2023-01-08 02:08:19 -08:00
</Box>
2023-01-07 23:09:58 -08:00
);
};
export default RouteErrorBoundary;