feat: Enhance NotionPageSelector and NotionPageSelectorModal with loading states and credential handling

This commit is contained in:
twwu
2025-07-31 15:19:03 +08:00
parent 1b6a925b34
commit 8711a57d92
5 changed files with 110 additions and 48 deletions

View File

@ -1,18 +1,20 @@
import { useQuery } from '@tanstack/react-query'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { get } from '../base'
import type { DataSourceNotionWorkspace } from '@/models/common'
type PreImportNotionPagesParams = {
credentialId: string
datasetId: string
credentialId: string
}
const PRE_IMPORT_NOTION_PAGES_QUERY_KEY = 'notion-pre-import-pages'
export const usePreImportNotionPages = ({
credentialId,
datasetId,
credentialId,
}: PreImportNotionPagesParams) => {
return useQuery({
queryKey: ['notion-pre-import-pages', credentialId, datasetId],
queryKey: [PRE_IMPORT_NOTION_PAGES_QUERY_KEY, datasetId, credentialId],
queryFn: async () => {
return get<{ notion_info: DataSourceNotionWorkspace[] }>('/notion/pre-import/pages', {
params: {
@ -24,3 +26,17 @@ export const usePreImportNotionPages = ({
retry: 0,
})
}
export const useInvalidPreImportNotionPages = () => {
const queryClient = useQueryClient()
return ({
datasetId,
credentialId,
}: PreImportNotionPagesParams) => {
queryClient.invalidateQueries(
{
queryKey: [PRE_IMPORT_NOTION_PAGES_QUERY_KEY, datasetId, credentialId],
},
)
}
}