mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-09 19:06:51 +08:00
Fix/notion sync (#1258)
This commit is contained in:
@@ -7,7 +7,10 @@ import useSWR from 'swr'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import I18n from '@/context/i18n'
|
||||
import { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations'
|
||||
import { fetchFreeQuotaVerify } from '@/service/common'
|
||||
import {
|
||||
fetchDataSourceNotionBinding,
|
||||
fetchFreeQuotaVerify,
|
||||
} from '@/service/common'
|
||||
import type { ConfirmCommonProps } from '@/app/components/base/confirm/common'
|
||||
import Confirm from '@/app/components/base/confirm/common'
|
||||
|
||||
@@ -92,19 +95,56 @@ export const useCheckFreeQuota = () => {
|
||||
: null
|
||||
}
|
||||
|
||||
export const useCheckNotion = () => {
|
||||
const router = useRouter()
|
||||
const [confirm, setConfirm] = useState<ConfirmType | null>(null)
|
||||
const [canBinding, setCanBinding] = useState(false)
|
||||
const searchParams = useSearchParams()
|
||||
const type = searchParams.get('type')
|
||||
const notionCode = searchParams.get('code')
|
||||
const notionError = searchParams.get('error')
|
||||
const { data } = useSWR(
|
||||
canBinding
|
||||
? `/oauth/data-source/binding/notion?code=${notionCode}`
|
||||
: null,
|
||||
fetchDataSourceNotionBinding,
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (data)
|
||||
router.replace('/', { forceOptimisticNavigation: false })
|
||||
}, [data, router])
|
||||
useEffect(() => {
|
||||
if (type === 'notion') {
|
||||
if (notionError) {
|
||||
setConfirm({
|
||||
type: 'danger',
|
||||
title: notionError,
|
||||
})
|
||||
}
|
||||
else if (notionCode) {
|
||||
setCanBinding(true)
|
||||
}
|
||||
}
|
||||
}, [type, notionCode, notionError])
|
||||
|
||||
return confirm
|
||||
}
|
||||
|
||||
export const CheckModal = () => {
|
||||
const router = useRouter()
|
||||
const { t } = useTranslation()
|
||||
const [showPayStatusModal, setShowPayStatusModal] = useState(true)
|
||||
const anthropicConfirmInfo = useAnthropicCheckPay()
|
||||
const freeQuotaConfirmInfo = useCheckFreeQuota()
|
||||
const notionConfirmInfo = useCheckNotion()
|
||||
|
||||
const handleCancelShowPayStatusModal = useCallback(() => {
|
||||
setShowPayStatusModal(false)
|
||||
router.replace('/', { forceOptimisticNavigation: false })
|
||||
}, [router])
|
||||
|
||||
const confirmInfo = anthropicConfirmInfo || freeQuotaConfirmInfo
|
||||
const confirmInfo = anthropicConfirmInfo || freeQuotaConfirmInfo || notionConfirmInfo
|
||||
|
||||
if (!confirmInfo || !showPayStatusModal)
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user