'use client' import React, { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { useBoolean } from 'ahooks' import { useContext } from 'use-context-selector' import { useRouter } from 'next/navigation' import DatasetDetailContext from '@/context/dataset-detail' import type { CrawlOptions, CustomFile, FullDocumentDetail } from '@/models/datasets' import type { MetadataType } from '@/service/datasets' import { fetchDocumentDetail } from '@/service/datasets' import Loading from '@/app/components/base/loading' import StepTwo from '@/app/components/datasets/create/step-two' import AccountSetting from '@/app/components/header/account-setting' import AppUnavailable from '@/app/components/base/app-unavailable' import { useDefaultModel } from '@/app/components/header/account-setting/model-provider-page/hooks' import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import type { NotionPage } from '@/models/common' type DocumentSettingsProps = { datasetId: string documentId: string } const DocumentSettings = ({ datasetId, documentId }: DocumentSettingsProps) => { const { t } = useTranslation() const router = useRouter() const [isShowSetAPIKey, { setTrue: showSetAPIKey, setFalse: hideSetAPIkey }] = useBoolean() const [hasError, setHasError] = useState(false) const { indexingTechnique, dataset } = useContext(DatasetDetailContext) const { data: embeddingsDefaultModel } = useDefaultModel(ModelTypeEnum.textEmbedding) const saveHandler = () => router.push(`/datasets/${datasetId}/documents/${documentId}`) const cancelHandler = () => router.back() const [documentDetail, setDocumentDetail] = useState(null) const currentPage = useMemo(() => { return { workspace_id: documentDetail?.data_source_info.notion_workspace_id, page_id: documentDetail?.data_source_info.notion_page_id, page_name: documentDetail?.name, page_icon: documentDetail?.data_source_info.notion_page_icon, type: documentDetail?.data_source_type, } }, [documentDetail]) useEffect(() => { (async () => { try { const detail = await fetchDocumentDetail({ datasetId, documentId, params: { metadata: 'without' as MetadataType }, }) setDocumentDetail(detail) } catch (e) { setHasError(true) } })() }, [datasetId, documentId]) if (hasError) return return (
{!documentDetail && } {dataset && documentDetail && ( )}
{isShowSetAPIKey && { hideSetAPIkey() }} />}
) } export default DocumentSettings