2025-07-31 15:19:03 +08:00
|
|
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
2025-07-30 15:19:10 +08:00
|
|
|
import { get } from '../base'
|
|
|
|
import type { DataSourceNotionWorkspace } from '@/models/common'
|
2025-04-24 21:26:54 +08:00
|
|
|
|
|
|
|
type PreImportNotionPagesParams = {
|
2025-07-30 15:19:10 +08:00
|
|
|
datasetId: string
|
2025-07-31 15:19:03 +08:00
|
|
|
credentialId: string
|
2025-04-24 21:26:54 +08:00
|
|
|
}
|
|
|
|
|
2025-07-31 15:19:03 +08:00
|
|
|
const PRE_IMPORT_NOTION_PAGES_QUERY_KEY = 'notion-pre-import-pages'
|
|
|
|
|
2025-07-30 15:19:10 +08:00
|
|
|
export const usePreImportNotionPages = ({
|
|
|
|
datasetId,
|
2025-07-31 15:19:03 +08:00
|
|
|
credentialId,
|
2025-07-30 15:19:10 +08:00
|
|
|
}: PreImportNotionPagesParams) => {
|
2025-04-24 21:26:54 +08:00
|
|
|
return useQuery({
|
2025-07-31 15:19:03 +08:00
|
|
|
queryKey: [PRE_IMPORT_NOTION_PAGES_QUERY_KEY, datasetId, credentialId],
|
2025-04-24 21:26:54 +08:00
|
|
|
queryFn: async () => {
|
2025-07-30 15:19:10 +08:00
|
|
|
return get<{ notion_info: DataSourceNotionWorkspace[] }>('/notion/pre-import/pages', {
|
|
|
|
params: {
|
|
|
|
dataset_id: datasetId,
|
|
|
|
credential_id: credentialId,
|
|
|
|
},
|
|
|
|
})
|
2025-04-24 21:26:54 +08:00
|
|
|
},
|
2025-07-30 15:19:10 +08:00
|
|
|
retry: 0,
|
2025-04-24 21:26:54 +08:00
|
|
|
})
|
|
|
|
}
|
2025-07-31 15:19:03 +08:00
|
|
|
|
|
|
|
export const useInvalidPreImportNotionPages = () => {
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
return ({
|
|
|
|
datasetId,
|
|
|
|
credentialId,
|
|
|
|
}: PreImportNotionPagesParams) => {
|
|
|
|
queryClient.invalidateQueries(
|
|
|
|
{
|
|
|
|
queryKey: [PRE_IMPORT_NOTION_PAGES_QUERY_KEY, datasetId, credentialId],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|