Files
supabase/apps/studio/data/database/backups-query.ts
T
Joshen Lim a95fc1bff2 Joshen/fe 2441 backup restore dialog shows incorrect utc timestamp (#42307)
## Context

Clicking "Restore" on a scheduled backup shows the confirmation modal,
in which the backup date does not align with what's shown on the back up
row (the latter is the correct one)

<img width="1812" height="292" alt="image"
src="https://github.com/user-attachments/assets/7ec159af-5826-4364-8066-2de6840243dc"
/>

<img width="400" height="586" alt="image"
src="https://github.com/user-attachments/assets/12c6f2d1-1dfb-4c90-9a79-5fa1a99dd688"
/>

Am opting to use the same `TimestampInfo` component in the confirmation
modal - which will align the values shown in both UI

<img width="578" height="350" alt="image"
src="https://github.com/user-attachments/assets/54ad8b76-c535-403e-b976-41b9b1fc05bd"
/>
2026-01-30 17:03:19 +08:00

44 lines
1.5 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import type { components } from 'data/api'
import { get, handleError } from 'data/fetchers'
import { useIsOrioleDbInAws } from 'hooks/misc/useSelectedProject'
import type { ResponseError, UseCustomQueryOptions } from 'types'
import { databaseKeys } from './keys'
export type BackupsVariables = {
projectRef?: string
}
export type DatabaseBackup = components['schemas']['BackupsResponse']['backups'][number]
export async function getBackups({ projectRef }: BackupsVariables, signal?: AbortSignal) {
if (!projectRef) throw new Error('Project ref is required')
const { data, error } = await get(`/platform/database/{ref}/backups`, {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type BackupsData = Awaited<ReturnType<typeof getBackups>>
export type BackupsError = ResponseError
export const useBackupsQuery = <TData = BackupsData>(
{ projectRef }: BackupsVariables,
{ enabled = true, ...options }: UseCustomQueryOptions<BackupsData, BackupsError, TData> = {}
) => {
// [Joshen] Check for specifically false to account for project not loaded yet
const isOrioleDbInAws = useIsOrioleDbInAws()
return useQuery<BackupsData, BackupsError, TData>({
queryKey: databaseKeys.backups(projectRef),
queryFn: ({ signal }) => getBackups({ projectRef }, signal),
enabled: enabled && !isOrioleDbInAws && typeof projectRef !== 'undefined',
...options,
})
}