1
+ import React , { useEffect , useState } from 'react' ;
2
+
3
+ const STATUS_URL = 'https://status.nextcommerce.com/api/v1/summary' ;
4
+ const STATUS_PAGE_URL = 'https://status.nextcommerce.com/' ;
5
+
6
+ const getStatus = ( data ) => {
7
+ const { ongoing_incidents, in_progress_maintenances, scheduled_maintenances } = data ;
8
+
9
+ if ( ongoing_incidents . length > 0 ) {
10
+ return { text : 'Active incident in progress' , color : '#FFA500' } ; // orange
11
+ }
12
+
13
+ if ( in_progress_maintenances . length > 0 ) {
14
+ return { text : 'Performing scheduled maintenance' , color : '#FFA500' } ; // orange
15
+ }
16
+
17
+ if ( scheduled_maintenances . length > 0 ) {
18
+ return { text : 'Upcoming schedule maintenance' , color : '#007BFF' } ; // blue
19
+ }
20
+
21
+ return { text : 'All systems normal' , color : '#00d97e' } ; // green
22
+ } ;
23
+
24
+ const dotStyle = ( color ) => ( {
25
+ height : '10px' ,
26
+ width : '10px' ,
27
+ backgroundColor : color ,
28
+ borderRadius : '50%' ,
29
+ display : 'inline-block' ,
30
+ marginRight : '0.5em' ,
31
+ boxShadow : `0 0 3px 2px ${ color } ` , // glow effect
32
+ } ) ;
33
+
34
+ const badgeStyle = {
35
+ display : 'inline-flex' ,
36
+ alignItems : 'center' ,
37
+ padding : '0.4em 0.8em' ,
38
+ borderRadius : '9px' ,
39
+ border : '1px solid #e0e0e060' ,
40
+ fontSize : '0.875rem' ,
41
+ fontWeight : 500 ,
42
+ backgroundColor : '#2b2b2b' ,
43
+ textDecoration : 'none' ,
44
+ color : '#fff' ,
45
+ boxShadow : '0 1px 2px rgba(0, 0, 0, 0.05)' ,
46
+ } ;
47
+
48
+ const IncidentStatusBadge = ( ) => {
49
+ const [ status , setStatus ] = useState ( null ) ;
50
+
51
+ useEffect ( ( ) => {
52
+ fetch ( STATUS_URL )
53
+ . then ( ( res ) => res . json ( ) )
54
+ . then ( ( data ) => setStatus ( getStatus ( data ) ) )
55
+ . catch ( ( err ) => console . error ( 'Failed to load status:' , err ) ) ;
56
+ } , [ ] ) ;
57
+
58
+ if ( ! status ) return null ;
59
+
60
+ return (
61
+ < a href = { STATUS_PAGE_URL } target = "_blank" rel = "noopener noreferrer" style = { badgeStyle } >
62
+ < span style = { dotStyle ( status . color ) } > </ span >
63
+ { status . text }
64
+ </ a >
65
+ ) ;
66
+ } ;
67
+
68
+ export default IncidentStatusBadge ;
0 commit comments