11'use client'
22
3- import { useCallback , useEffect , useState } from 'react'
43import Link from 'next/link'
54import { StatusDotIcon } from '@/components/icons'
6- import type { StatusResponse , StatusType } from '@/app/api/status/types'
7-
8- const POLLING_INTERVAL = 60000
5+ import type { StatusType } from '@/app/api/status/types'
6+ import { useStatus } from '@/hooks/queries/status'
97
108const STATUS_COLORS : Record < StatusType , string > = {
119 operational : 'text-[#10B981] hover:text-[#059669]' ,
@@ -17,45 +15,15 @@ const STATUS_COLORS: Record<StatusType, string> = {
1715}
1816
1917export default function StatusIndicator ( ) {
20- const [ status , setStatus ] = useState < StatusType > ( 'loading' )
21- const [ message , setMessage ] = useState < string > ( 'Checking Status...' )
22- const [ statusUrl , setStatusUrl ] = useState < string > ( 'https://status.sim.ai' )
23-
24- const fetchStatus = useCallback ( async ( ) => {
25- try {
26- const response = await fetch ( '/api/status' )
27-
28- if ( ! response . ok ) {
29- throw new Error ( 'Failed to fetch status' )
30- }
31-
32- const data : StatusResponse = await response . json ( )
33-
34- setStatus ( data . status )
35- setMessage ( data . message )
36- setStatusUrl ( data . url )
37- } catch ( error ) {
38- console . error ( 'Error fetching status:' , error )
39- setStatus ( 'error' )
40- setMessage ( 'Status Unknown' )
41- }
42- } , [ ] )
43-
44- useEffect ( ( ) => {
45- fetchStatus ( )
46-
47- const poll = ( ) => {
48- fetchStatus ( ) . finally ( ( ) => {
49- setTimeout ( poll , POLLING_INTERVAL )
50- } )
51- }
52-
53- const timeoutId = setTimeout ( poll , POLLING_INTERVAL )
54-
55- return ( ) => {
56- clearTimeout ( timeoutId )
57- }
58- } , [ fetchStatus ] )
18+ const { data, isLoading, isError } = useStatus ( )
19+
20+ const status = isLoading ? 'loading' : isError ? 'error' : data ?. status || 'error'
21+ const message = isLoading
22+ ? 'Checking Status...'
23+ : isError
24+ ? 'Status Unknown'
25+ : data ?. message || 'Status Unknown'
26+ const statusUrl = data ?. url || 'https://status.sim.ai'
5927
6028 return (
6129 < Link
0 commit comments