Added znzt web app
Deploy Manager App / deploy (push) Failing after 17s
Details
Deploy Manager App / deploy (push) Failing after 17s
Details
This commit is contained in:
parent
af3d4fcc10
commit
883f990598
73
src/App.tsx
73
src/App.tsx
|
|
@ -1,23 +1,56 @@
|
|||
import { Routes, Route, Navigate } from 'react-router-dom'
|
||||
import Login from './pages/Login'
|
||||
import OrdersPage from './pages/OrdersPage'
|
||||
import React from "react";
|
||||
import { useState, useEffect } from 'react';
|
||||
import { ErrorScreen } from './components/ErrorScreen';
|
||||
|
||||
function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
||||
const token = localStorage.getItem('token')
|
||||
if (!token) return <Navigate to="/login" replace />
|
||||
return <>{children}</>
|
||||
}
|
||||
export function App() {
|
||||
const [authError, setAuthError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/" element={
|
||||
<ProtectedRoute>
|
||||
<OrdersPage />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
</Routes>
|
||||
)
|
||||
// Функция выхода
|
||||
const handleLogout = () => {
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
window.location.reload(); // Перезагрузка вернет пользователя на экран входа
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Пример запроса за данными (или проверка профиля)
|
||||
fetch('/api/monthly-orders/matrix', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) {
|
||||
const data = await res.json();
|
||||
// Если бэкенд вернул ошибку привязки Telegram
|
||||
if (data && data.error_description) {
|
||||
throw new Error(data.error_description);
|
||||
}
|
||||
throw new Error('Произошла ошибка загрузки данных');
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
setAuthError(err.message);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return <div className="flex justify-center items-center h-screen">Загрузка...</div>;
|
||||
}
|
||||
|
||||
// Если возникла критическая ошибка доступа — показываем экран с кнопкой выхода
|
||||
if (authError) {
|
||||
return <ErrorScreen message={authError} onLogout={handleLogout} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Ваше основное приложение */}
|
||||
<h1>Панель менеджера</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import React from 'react';
|
||||
|
||||
interface ErrorScreenProps {
|
||||
title?: string;
|
||||
message: string;
|
||||
onLogout: () => void;
|
||||
}
|
||||
|
||||
export const ErrorScreen: React.FC<ErrorScreenProps> = ({
|
||||
title = 'Ошибка доступа',
|
||||
message,
|
||||
onLogout,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-screen bg-gray-100 p-4">
|
||||
<div className="max-w-md w-full bg-white rounded-lg shadow-lg p-6 text-center">
|
||||
<div className="w-12 h-12 mx-auto mb-4 text-red-500 bg-red-100 rounded-full flex items-center justify-center text-xl font-bold">
|
||||
!
|
||||
</div>
|
||||
<h2 className="text-xl font-semibold text-gray-800 mb-2">{title}</h2>
|
||||
<p className="text-gray-600 mb-6 bg-gray-50 p-3 rounded border border-gray-200 text-sm">
|
||||
{message}
|
||||
</p>
|
||||
<button
|
||||
onClick={onLogout}
|
||||
className="w-full bg-red-600 hover:bg-red-700 text-white font-medium py-2 px-4 rounded transition-colors duration-200 shadow"
|
||||
>
|
||||
Выйти и войти заново
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -20,7 +20,8 @@
|
|||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue