Added znzt web app
Deploy Manager App / deploy (push) Failing after 16s
Details
Deploy Manager App / deploy (push) Failing after 16s
Details
This commit is contained in:
parent
d74493215d
commit
3278ceb76f
57
src/App.tsx
57
src/App.tsx
|
|
@ -1,11 +1,13 @@
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { ErrorScreen } from './components/ErrorScreen';
|
import { ErrorScreen } from './components/ErrorScreen';
|
||||||
|
import apiClient from './api/client';
|
||||||
|
import OrdersPage from './OrdersPage'; // Убедитесь, что путь к вашему компоненту страницы заказов корректен
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
const [authError, setAuthError] = useState<string | null>(null);
|
const [authError, setAuthError] = useState<string | null>(null);
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
|
||||||
// Функция выхода
|
// Функция выхода (очищает сессию и возвращает на корень)
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
|
|
@ -13,25 +15,16 @@ export function App() {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Пример запроса за данными (или проверка профиля)
|
// Используем настроенный apiClient вместо обычного fetch
|
||||||
fetch('/api/monthly-orders/matrix', {
|
apiClient.get('/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) => {
|
.catch((err) => {
|
||||||
setAuthError(err.message);
|
// Axios перехватывает ошибки ответа сервера (включая статус 500)
|
||||||
|
const errorDescription =
|
||||||
|
err.response?.data?.error_description ||
|
||||||
|
err.response?.data?.message ||
|
||||||
|
'Произошла ошибка загрузки данных';
|
||||||
|
|
||||||
|
setAuthError(errorDescription);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
@ -42,14 +35,14 @@ export function App() {
|
||||||
return <div className="flex justify-center items-center h-screen">Загрузка...</div>;
|
return <div className="flex justify-center items-center h-screen">Загрузка...</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Если возникла критическая ошибка доступа — показываем экран с кнопкой выхода
|
// Если возникла критическая ошибка доступа (например, нет привязки к Telegram)
|
||||||
if (authError) {
|
if (authError) {
|
||||||
return <ErrorScreen message={authError} onLogout={handleLogout} />;
|
return <ErrorScreen message={authError} onLogout={handleLogout} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Основное приложение с постоянной кнопкой выхода в правом верхнем углу
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen bg-gray-100">
|
<div className="relative min-h-screen bg-gray-100">
|
||||||
{/* Всегда доступная кнопка выхода в правом верхнем углу */}
|
|
||||||
<div className="absolute top-4 right-4 z-50">
|
<div className="absolute top-4 right-4 z-50">
|
||||||
<button
|
<button
|
||||||
onClick={handleLogout}
|
onClick={handleLogout}
|
||||||
|
|
@ -59,24 +52,10 @@ export function App() {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{authError ? (
|
{/* Рендерим основную страницу заказов */}
|
||||||
<div className="flex flex-col items-center justify-center min-h-screen p-4">
|
<main>
|
||||||
<div className="max-w-md w-full bg-white rounded-lg shadow-lg p-6 text-center">
|
<OrdersPage />
|
||||||
<h2 className="text-xl font-semibold text-gray-800 mb-2">Ошибка доступа</h2>
|
</main>
|
||||||
<p className="text-gray-600 mb-6 bg-gray-50 p-3 rounded border border-gray-200 text-sm">
|
|
||||||
{authError}
|
|
||||||
</p>
|
|
||||||
<button
|
|
||||||
onClick={handleLogout}
|
|
||||||
className="w-full bg-red-600 hover:bg-red-700 text-white font-medium py-2 px-4 rounded transition-colors"
|
|
||||||
>
|
|
||||||
Выйти и войти заново
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div>{/* Здесь ваше обычное приложение */}</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue