forked from BETAIL-BOYS/TradeFlow-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDegradedPerformanceBanner.tsx
More file actions
100 lines (87 loc) · 3.2 KB
/
Copy pathDegradedPerformanceBanner.tsx
File metadata and controls
100 lines (87 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"use client";
import React from 'react';
import { AlertTriangle, RefreshCw, X, Wifi, WifiOff } from 'lucide-react';
import { useBackendHealth } from '../contexts/BackendHealthContext';
import Icon from './ui/Icon';
export default function DegradedPerformanceBanner() {
const { healthState, resetHealth, isDegraded, isOffline } = useBackendHealth();
// Don't show banner when backend is healthy
if (!isDegraded && !isOffline) {
return null;
}
const handleRetry = () => {
resetHealth();
// Trigger a health check by making a simple API call
fetch('/api/health')
.then(() => {
// Success will be reported through the health context
})
.catch(() => {
// Error will be reported through the health context
});
};
const getBannerContent = () => {
if (isOffline) {
return {
icon: <Icon icon={WifiOff} />,
bgColor: 'bg-red-500/10',
borderColor: 'border-red-500/30',
iconColor: 'text-red-400',
title: 'Backend Offline',
message: 'Our servers are temporarily unavailable. Some features may be limited.',
actionText: 'Retry Connection',
actionBg: 'bg-red-600 hover:bg-red-700',
};
}
return {
icon: <Icon icon={AlertTriangle} />,
bgColor: 'bg-yellow-500/10',
borderColor: 'border-yellow-500/30',
iconColor: 'text-yellow-400',
title: 'Degraded Performance',
message: 'Some services are experiencing issues. Blockchain operations remain available.',
actionText: 'Check Status',
actionBg: 'bg-yellow-600 hover:bg-yellow-700',
};
};
const content = getBannerContent();
return (
<div className={`fixed top-0 left-0 right-0 z-50 ${content.bgColor} border-b ${content.borderColor} backdrop-blur-sm`}>
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between py-3">
<div className="flex items-center gap-3">
<div className={`flex items-center justify-center w-10 h-10 rounded-full ${content.bgColor} ${content.iconColor}`}>
{content.icon}
</div>
<div className="flex-1 min-w-0">
<p className={`font-medium ${content.iconColor}`}>
{content.title}
</p>
<p className="text-sm text-slate-300">
{content.message}
</p>
</div>
</div>
<div className="flex items-center gap-2">
<button
onClick={handleRetry}
className={`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium text-white ${content.actionBg} transition-colors`}
>
<Icon icon={RefreshCw} dense />
{content.actionText}
</button>
<button
onClick={() => resetHealth()}
className="p-2 rounded-lg text-slate-400 hover:text-white hover:bg-slate-700/50 transition-colors"
title="Dismiss"
>
<Icon icon={X} dense />
</button>
</div>
</div>
</div>
</div>
);
}
// Inconsequential change for repo health
// Maintenance: minor update