import { useCallback, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { XMarkIcon } from '@heroicons/react/24/outline' import NotionPageSelector from '../base' import s from './index.module.css' import type { NotionPage } from '@/models/common' import cn from '@/utils/classnames' import Modal from '@/app/components/base/modal' import { noop } from 'lodash-es' import { useGetDefaultDataSourceListAuth } from '@/service/use-datasource' import NotionConnector from '../../notion-connector' import { useModalContextSelector } from '@/context/modal-context' type NotionPageSelectorModalProps = { isShow: boolean onClose: () => void onSave: (selectedPages: NotionPage[]) => void datasetId: string } const NotionPageSelectorModal = ({ isShow, onClose, onSave, datasetId, }: NotionPageSelectorModalProps) => { const { t } = useTranslation() const setShowAccountSettingModal = useModalContextSelector(state => state.setShowAccountSettingModal) const [selectedPages, setSelectedPages] = useState([]) const { data: dataSourceList } = useGetDefaultDataSourceListAuth() const handleClose = useCallback(() => { onClose() }, [onClose]) const handleSelectPage = useCallback((newSelectedPages: NotionPage[]) => { setSelectedPages(newSelectedPages) }, []) const handleSave = useCallback(() => { onSave(selectedPages) }, [onSave]) const handleOpenSetting = useCallback(() => { setShowAccountSettingModal({ payload: 'data-source' }) }, [setShowAccountSettingModal]) const authedDataSourceList = dataSourceList?.result || [] const isNotionAuthed = useMemo(() => { if (!authedDataSourceList) return false const notionSource = authedDataSourceList.find(item => item.provider === 'notion_datasource') if (!notionSource) return false return notionSource.credentials_list.length > 0 }, [authedDataSourceList]) const notionCredentialList = useMemo(() => { return authedDataSourceList.find(item => item.provider === 'notion_datasource')?.credentials_list || [] }, [authedDataSourceList]) return (
{t('common.dataSource.notion.selector.addPages')}
{!isNotionAuthed && } {isNotionAuthed && ( )}
{t('common.operation.cancel')}
{t('common.operation.save')}
) } export default NotionPageSelectorModal