Files
supabase/apps/studio/data/platform/incident-status-query.ts
Danny WhiteandCharis Lam f0acececce feat(studio): incident notice on support ticket creation (#41379)
* callout

* progress

* plural issues

* better handle multiple issues

* refactor

* remove fancy copywriting

* return IncidentAdmonition to support form page

* progress

* cleanup

* rabbit

Potential control flow issue: execution continues after handleError when data is undefined. When a non-401 error occurs, handleError(error) is called but execution continues to line 24 where data is accessed. If handleError doesn't throw, this will cause a runtime error accessing (data as any).is_healthy on undefined. Additionally, the as any cast on line 24 violates the coding guidelines. Consider validating the response shape instead.

* animate in

* fix

* reset

* remove unused dayjs

* rabbit

* rabbit

* fixes from code review

* rabbit

* rabbit

---------

Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
2025-12-19 00:28:02 +00:00

39 lines
1.3 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import type { IncidentInfo } from 'lib/api/incident-status'
import { BASE_PATH } from 'lib/constants'
import { UseCustomQueryOptions } from 'types'
import { platformKeys } from './keys'
export async function getIncidentStatus(signal?: AbortSignal): Promise<IncidentInfo[]> {
const response = await fetch(`${BASE_PATH}/api/incident-status`, {
signal,
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
if (!response.ok) {
const errorText = await response.text()
console.error('[getIncidentStatus] Failed:', response.status, errorText)
throw new Error(`Failed to fetch incident status: ${response.statusText}`)
}
const data = await response.json()
return data as IncidentInfo[]
}
export type IncidentStatusData = Awaited<ReturnType<typeof getIncidentStatus>>
export type IncidentStatusError = unknown
export const useIncidentStatusQuery = <TData = IncidentStatusData>(
options: UseCustomQueryOptions<IncidentStatusData, IncidentStatusError, TData> = {}
) =>
useQuery<IncidentStatusData, IncidentStatusError, TData>({
queryKey: platformKeys.incidentStatus(),
queryFn: ({ signal }) => getIncidentStatus(signal),
staleTime: 1000 * 60 * 5, // 5 minutes to match API cache
...options,
})