Compare commits
2 Commits
db918ba7c7
...
18ca96bfe9
Author | SHA1 | Date | |
---|---|---|---|
18ca96bfe9 | |||
d1d92c63e8 |
@ -28,6 +28,8 @@
|
|||||||
"dry-wash.arm.master.drawer.button.cancel": "Отменить",
|
"dry-wash.arm.master.drawer.button.cancel": "Отменить",
|
||||||
"dry-wash.arm.master.sideBar.title": " Сухой мастер",
|
"dry-wash.arm.master.sideBar.title": " Сухой мастер",
|
||||||
"dry-wash.arm.master.sideBar.title.master": "Мастера",
|
"dry-wash.arm.master.sideBar.title.master": "Мастера",
|
||||||
"dry-wash.arm.master.sideBar.title.orders": "Заказы"
|
"dry-wash.arm.master.sideBar.title.orders": "Заказы",
|
||||||
|
"dry-wash.errorBoundary.title":"Что-то пошло не так",
|
||||||
|
"dry-wash.errorBoundary.description": " Мы уже работаем над исправлением проблемы",
|
||||||
|
"dry-wash.errorBoundary.button.reload": "Перезагрузить страницу"
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,16 @@ import React from 'react';
|
|||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import Routers from './routes';
|
import Routers from './routes';
|
||||||
import { ChakraProvider, theme as chakraTheme } from '@chakra-ui/react';
|
import { ChakraProvider, theme as chakraTheme } from '@chakra-ui/react';
|
||||||
|
import ErrorBoundary from './components/ErrorBoundary';
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
return (
|
return (
|
||||||
<ChakraProvider theme={chakraTheme}>
|
<ChakraProvider theme={chakraTheme}>
|
||||||
<BrowserRouter>
|
<ErrorBoundary>
|
||||||
<Routers></Routers>
|
<BrowserRouter>
|
||||||
</BrowserRouter>
|
<Routers />
|
||||||
|
</BrowserRouter>
|
||||||
|
</ErrorBoundary>
|
||||||
</ChakraProvider>
|
</ChakraProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
64
src/components/ErrorBoundary/ErrorBoundary.tsx
Normal file
64
src/components/ErrorBoundary/ErrorBoundary.tsx
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import React, { Component, ErrorInfo, ReactNode } from 'react';
|
||||||
|
import { Heading, Text, Button, Center, VStack } from '@chakra-ui/react';
|
||||||
|
import i18next from 'i18next';
|
||||||
|
|
||||||
|
interface ErrorBoundaryState {
|
||||||
|
hasError: boolean;
|
||||||
|
error: Error | null;
|
||||||
|
errorInfo: ErrorInfo | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ErrorBoundaryProps {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||||
|
constructor(props: ErrorBoundaryProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
hasError: false,
|
||||||
|
error: null,
|
||||||
|
errorInfo: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDerivedStateFromError(): Partial<ErrorBoundaryState> {
|
||||||
|
return { hasError: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
||||||
|
console.error('Error caught by ErrorBoundary:', error, errorInfo);
|
||||||
|
this.setState({ error, errorInfo });
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { hasError } = this.state;
|
||||||
|
//TODO: добавить анимацию после залива 404 страницы
|
||||||
|
if (hasError) {
|
||||||
|
return (
|
||||||
|
<Center minH='100vh'>
|
||||||
|
<VStack spacing={4} textAlign='center'>
|
||||||
|
<Heading as='h1' size='2xl'>
|
||||||
|
{i18next.t('dry-wash.errorBoundary.title')}
|
||||||
|
</Heading>
|
||||||
|
<Text fontSize='lg'>
|
||||||
|
{i18next.t('dry-wash.errorBoundary.description')}
|
||||||
|
</Text>
|
||||||
|
<Button
|
||||||
|
colorScheme='teal'
|
||||||
|
size='lg'
|
||||||
|
variant='outline'
|
||||||
|
onClick={() => window.location.reload()}
|
||||||
|
>
|
||||||
|
{i18next.t('dry-wash.errorBoundary.button.reload')}
|
||||||
|
</Button>
|
||||||
|
</VStack>
|
||||||
|
</Center>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ErrorBoundary;
|
1
src/components/ErrorBoundary/index.ts
Normal file
1
src/components/ErrorBoundary/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default } from './ErrorBoundary';
|
Loading…
Reference in New Issue
Block a user