'use client' import type { MouseEventHandler } from 'react' import { useState } from 'react' import { RiCloseLine } from '@remixicon/react' import { useContext } from 'use-context-selector' import { useTranslation } from 'react-i18next' import cn from '@/utils/classnames' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import Textarea from '@/app/components/base/textarea' import Modal from '@/app/components/base/modal' import { ToastContext } from '@/app/components/base/toast' import type { DataSet } from '@/models/datasets' import { updateDatasetSetting } from '@/service/datasets' type RenameDatasetModalProps = { show: boolean dataset: DataSet onSuccess?: () => void onClose: () => void } const RenameDatasetModal = ({ show, dataset, onSuccess, onClose }: RenameDatasetModalProps) => { const { t } = useTranslation() const { notify } = useContext(ToastContext) const [loading, setLoading] = useState(false) const [name, setName] = useState(dataset.name) const [description, setDescription] = useState(dataset.description) const [externalKnowledgeId, setExternalKnowledgeId] = useState(dataset.external_knowledge_info.external_knowledge_id) const [externalKnowledgeApiId, setExternalKnowledgeApiId] = useState(dataset.external_knowledge_info.external_knowledge_api_id) const onConfirm: MouseEventHandler = async () => { if (!name.trim()) { notify({ type: 'error', message: t('datasetSettings.form.nameError') }) return } try { setLoading(true) const body: Partial & { external_knowledge_id?: string; external_knowledge_api_id?: string } = { name, description, } if (externalKnowledgeId && externalKnowledgeApiId) { body.external_knowledge_id = externalKnowledgeId body.external_knowledge_api_id = externalKnowledgeApiId } await updateDatasetSetting({ datasetId: dataset.id, body, }) notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) if (onSuccess) onSuccess() onClose() } catch (e) { notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) } finally { setLoading(false) } } return ( { }} >
{t('datasetSettings.title')}
{t('datasetSettings.form.name')}
setName(e.target.value)} className='h-9' placeholder={t('datasetSettings.form.namePlaceholder') || ''} />
{t('datasetSettings.form.desc')}