File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed
react-admin/src/components Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments