omnivore/packages/web/lib/networking/useCreateExport.tsx

41 lines
933 B
TypeScript
Raw Permalink Normal View History

2024-11-02 06:48:51 +00:00
import { useQuery, useQueryClient } from '@tanstack/react-query'
2024-10-28 03:15:12 +00:00
import { apiFetcher } from './networkHelpers'
2024-11-02 06:48:51 +00:00
import { TaskState } from './mutations/exportToIntegrationMutation'
type Export = {
id: string
state: TaskState
totalItems?: number
processedItems?: number
2024-11-02 06:48:51 +00:00
createdAt: string
signedUrl: string
}
type ExportsResponse = {
exports: Export[]
}
2024-10-28 03:15:12 +00:00
export const createExport = async (): Promise<boolean> => {
try {
const response = await apiFetcher(`/api/export/`)
2024-11-02 06:48:51 +00:00
console.log('RESPONSE: ', response)
if ('error' in (response as any)) {
return false
}
2024-10-28 03:15:12 +00:00
return true
} catch (error) {
console.log('error scheduling export. ')
return false
}
}
2024-11-02 06:48:51 +00:00
export function useGetExports() {
return useQuery({
queryKey: ['exports'],
queryFn: async () => {
const response = (await apiFetcher(`/api/export/list`)) as ExportsResponse
return response.exports
},
})
}