manager-orders-app/src/App.tsx

58 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Routes, Route, useNavigate } from 'react-router-dom';
import { AppShell, Button, Group, Title } from '@mantine/core';
import { modals } from '@mantine/modals';
import { IconLogout } from '@tabler/icons-react';
import OrdersPage from './pages/OrdersPage';
import Login from './pages/Login';
import AnalystDashboard from './pages/AnalystDashboard'; // 👈 Подключаем дашборд
export function App() {
const navigate = useNavigate();
const handleLogout = () => {
modals.openConfirmModal({
title: 'Подтверждение выхода',
children: 'Вы уверены, что хотите выйти? Несохраненные данные могут быть потеряны.',
labels: { confirm: 'Выйти', cancel: 'Отмена' },
confirmProps: { color: 'red' },
onConfirm: () => {
localStorage.clear();
sessionStorage.clear();
navigate('/login');
},
});
};
const token = localStorage.getItem('token');
return (
<AppShell header={{ height: 60 }} padding="md">
<AppShell.Header>
<Group h="100%" px="md" justify="space-between">
<Title order={3}>Управление заказами</Title>
{token && (
<Button
variant="light"
color="red"
rightSection={<IconLogout size={16} />}
onClick={handleLogout}
>
Выйти
</Button>
)}
</Group>
</AppShell.Header>
<AppShell.Main display="flex" style={{ flexDirection: 'column', height: '100vh' }}>
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/analyst" element={<AnalystDashboard />} />
<Route path="/manager/:id" element={<OrdersPage onError={() => navigate('/login')} />} />
<Route path="/" element={<OrdersPage onError={() => navigate('/login')} />} />
</Routes>
</AppShell.Main>
</AppShell>
);
}