Files
supabase/apps/studio/data/projects/project-status-query.ts
Joshen Lim 00ca386e24 Chore/add get restore initiated event endpoint (#43485)
## Context

Resolves FE-2709
Dependent on API PR: https://github.com/supabase/platform/pull/30564

While a project is in restoring, we should a "Contact support" CTA in
the footer, but this has led to a high number of tickets coming in
despite the project's status being `ACTIVE_HEALTHY` when we check on our
end.

Will be adjusting the behaviour of this CTA to only show up if the
project's status is RESTORING and it's `updated_at` is at than 30
minutes ago, and update the CTA a bit as well

<img width="765" height="243" alt="image"
src="https://github.com/user-attachments/assets/69fe6fa3-d46f-4268-ad1b-46cffb3cc6ba"
/>

<img width="566" height="273" alt="image"
src="https://github.com/user-attachments/assets/2d5f31c2-6ef2-444b-8aee-fd94139cf713"
/>
2026-03-19 00:49:01 +08:00

42 lines
1.2 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { ResponseError, UseCustomQueryOptions } from 'types'
import { projectKeys } from './keys'
export type ProjectStatusVariables = {
projectRef?: string
}
export async function getProjectStatus(
{ projectRef }: ProjectStatusVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('Project ref is required')
const { data, error } = await get(`/platform/projects/{ref}/status`, {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data as { status: string }
}
export type ProjectStatusData = Awaited<ReturnType<typeof getProjectStatus>>
export type ProjectStatusError = ResponseError
export const useProjectStatusQuery = <TData = ProjectStatusData>(
{ projectRef }: ProjectStatusVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<ProjectStatusData, ProjectStatusError, TData> = {}
) =>
useQuery<ProjectStatusData, ProjectStatusError, TData>({
queryKey: projectKeys.status(projectRef),
queryFn: ({ signal }) => getProjectStatus({ projectRef }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})