Skip to content

Commit 28fc901

Browse files
committed
feat: added status indicator component
1 parent 43711d5 commit 28fc901

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.status-container {
2+
display: flex;
3+
align-items: center;
4+
gap: 10px;
5+
}
6+
7+
.status-indicator {
8+
width: 20px;
9+
height: 20px;
10+
border-radius: 50%;
11+
background-color: red; /* Default to red */
12+
}
13+
14+
.status-indicator.green {
15+
background-color: green;
16+
}
17+
18+
.status-indicator.red {
19+
background-color: red;
20+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { useEffect, useState } from 'react';
2+
import './StatusIndicator.css';
3+
4+
const StatusIndicator: React.FC = () => {
5+
const [status, setStatus] = useState<'green' | 'red'>('red');
6+
7+
const checkStatus = async () => {
8+
try {
9+
const response = await fetch('http://localhost:8080/api/v1/status'); // Replace with your endpoint
10+
console.log(response)
11+
if (response.status === 200) {
12+
setStatus('green');
13+
} else {
14+
setStatus('red');
15+
}
16+
} catch (error) {
17+
console.error('Error fetching status:', error);
18+
setStatus('red'); // Set red if the request fails
19+
}
20+
};
21+
22+
useEffect(() => {
23+
// Initial check
24+
checkStatus();
25+
26+
// Poll the API every 5 seconds
27+
const intervalId = setInterval(() => {
28+
checkStatus();
29+
}, 5000); // 5 seconds
30+
31+
// Clean up the interval when the component is unmounted
32+
return () => clearInterval(intervalId);
33+
}, []);
34+
35+
return (
36+
<div className="status-container">
37+
<div className={`status-indicator ${status}`}></div>
38+
<p>Status: {status === 'green' ? 'Operational' : 'Down'}</p>
39+
</div>
40+
);
41+
};
42+
43+
export default StatusIndicator;

0 commit comments

Comments
 (0)