From 883f9905985dd1c4ba1473dce2c5d7e47a1b4d4e Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Tue, 25 Aug 2026 13:03:14 +0300 Subject: [PATCH] Added znzt web app --- src/App.tsx | 73 ++++++++++++++++++++++++---------- src/components/ErrorScreen.tsx | 33 +++++++++++++++ tsconfig.app.json | 3 +- 3 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 src/components/ErrorScreen.tsx diff --git a/src/App.tsx b/src/App.tsx index c57d672..04eae88 100644 --- a/src/App.tsx +++ b/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 - return <>{children} -} +export function App() { + const [authError, setAuthError] = useState(null); + const [loading, setLoading] = useState(true); -export default function App() { - return ( - - } /> - - - - } /> - - ) + // Функция выхода + 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
Загрузка...
; + } + + // Если возникла критическая ошибка доступа — показываем экран с кнопкой выхода + if (authError) { + return ; + } + + return ( +
+ {/* Ваше основное приложение */} +

Панель менеджера

+
+ ); } \ No newline at end of file diff --git a/src/components/ErrorScreen.tsx b/src/components/ErrorScreen.tsx new file mode 100644 index 0000000..e780a26 --- /dev/null +++ b/src/components/ErrorScreen.tsx @@ -0,0 +1,33 @@ +import React from 'react'; + +interface ErrorScreenProps { + title?: string; + message: string; + onLogout: () => void; +} + +export const ErrorScreen: React.FC = ({ + title = 'Ошибка доступа', + message, + onLogout, + }) => { + return ( +
+
+
+ ! +
+

{title}

+

+ {message} +

+ +
+
+ ); +}; \ No newline at end of file diff --git a/tsconfig.app.json b/tsconfig.app.json index 6830b6f..9a00dd4 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -20,7 +20,8 @@ "noUnusedLocals": true, "noUnusedParameters": true, "erasableSyntaxOnly": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "allowSyntheticDefaultImports": true }, "include": ["src"] }