Compare commits
10 Commits
b769a2719b
...
5d208b1fc5
Author | SHA1 | Date | |
---|---|---|---|
5d208b1fc5 | |||
1839136c9f | |||
a6ec94785a | |||
18ca96bfe9 | |||
db918ba7c7 | |||
d1d92c63e8 | |||
dedc7e1608 | |||
1c8348dee5 | |||
04e4d011ff | |||
116e883e91 |
@ -31,6 +31,8 @@
|
||||
"dry-wash.arm.master.sideBar.title.orders": "Заказы",
|
||||
"dry-wash.notFound.title": "Страница не найдена",
|
||||
"dry-wash.notFound.description": "К сожалению, запрашиваемая вами страница не существует.",
|
||||
"dry-wash.notFound.button.back": " Вернуться на главную"
|
||||
|
||||
"dry-wash.notFound.button.back": " Вернуться на главную",
|
||||
"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 Routers from './routes';
|
||||
import { ChakraProvider, theme as chakraTheme } from '@chakra-ui/react';
|
||||
import ErrorBoundary from './components/ErrorBoundary';
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<ChakraProvider theme={chakraTheme}>
|
||||
<BrowserRouter>
|
||||
<Routers></Routers>
|
||||
</BrowserRouter>
|
||||
<ErrorBoundary>
|
||||
<BrowserRouter>
|
||||
<Routers />
|
||||
</BrowserRouter>
|
||||
</ErrorBoundary>
|
||||
</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';
|
@ -3,13 +3,19 @@ import Sidebar from '../Sidebar';
|
||||
import Orders from '../Orders';
|
||||
import Masters from '../Masters';
|
||||
import React from 'react';
|
||||
import { Navigate, Route, Routes } from 'react-router-dom';
|
||||
|
||||
const LayoutArm = ({ currentPage, onSelectPage }) => (
|
||||
const LayoutArm = () => (
|
||||
<Flex h='100vh'>
|
||||
<Sidebar onSelectPage={onSelectPage} />
|
||||
<Sidebar />
|
||||
<Box flex='1' bg='gray.50'>
|
||||
{currentPage === 'orders' && <Orders />}
|
||||
{currentPage === 'masters' && <Masters />}
|
||||
<Routes>
|
||||
<Route>
|
||||
<Route index element={<Navigate to='orders' replace />} />
|
||||
<Route path='orders' element={<Orders />} />
|
||||
<Route path='masters' element={<Masters />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
</Box>
|
||||
</Flex>
|
||||
);
|
||||
|
@ -2,7 +2,9 @@ import { Box, Button, Heading, VStack } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
import { Divider } from '@chakra-ui/react';
|
||||
import i18next from 'i18next';
|
||||
const Sidebar = ({ onSelectPage }) => (
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
const Sidebar = () => (
|
||||
<Box
|
||||
borderRight='1px solid black'
|
||||
bg='gray.50'
|
||||
@ -18,7 +20,8 @@ const Sidebar = ({ onSelectPage }) => (
|
||||
<VStack align='start' spacing='4'>
|
||||
<Divider />
|
||||
<Button
|
||||
onClick={() => onSelectPage('orders')}
|
||||
as={Link}
|
||||
to='orders'
|
||||
w='100%'
|
||||
colorScheme='green'
|
||||
variant='ghost'
|
||||
@ -27,7 +30,8 @@ const Sidebar = ({ onSelectPage }) => (
|
||||
</Button>
|
||||
<Divider />
|
||||
<Button
|
||||
onClick={() => onSelectPage('masters')}
|
||||
as={Link}
|
||||
to='masters'
|
||||
w='100%'
|
||||
colorScheme='green'
|
||||
variant='ghost'
|
||||
|
@ -2,9 +2,7 @@ import React, { useState } from 'react';
|
||||
import LayoutArm from '../../components/LayoutArm';
|
||||
|
||||
const Page = () => {
|
||||
const [currentPage, setCurrentPage] = useState('orders');
|
||||
|
||||
return <LayoutArm currentPage={currentPage} onSelectPage={setCurrentPage} />;
|
||||
return <LayoutArm />;
|
||||
};
|
||||
|
||||
export default Page;
|
||||
|
@ -17,7 +17,7 @@ const Routers = () => {
|
||||
<Route path='order-form' element={<OrderForm />} />
|
||||
<Route path='order-view' element={<OrderView />} />
|
||||
</Route>
|
||||
<Route path='/dry-wash/arm' element={<Arm />}></Route>
|
||||
<Route path='/dry-wash/arm/*' element={<Arm />}></Route>
|
||||
<Route path='*' element={<NotFound />} />
|
||||
</Routes>
|
||||
</Suspense>
|
||||
|
Loading…
Reference in New Issue
Block a user