'use client' import type { MouseEventHandler } from 'react' import cn from 'classnames' import { useState } from 'react' import { BookOpenIcon } from '@heroicons/react/24/outline' import { useContext } from 'use-context-selector' import { useTranslation } from 'react-i18next' import Button from '@/app/components/base/button' import Modal from '@/app/components/base/modal' import { ToastContext } from '@/app/components/base/toast' import { XClose } from '@/app/components/base/icons/src/vender/line/general' 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 onConfirm: MouseEventHandler = async () => { if (!name.trim()) { notify({ type: 'error', message: t('datasetSettings.form.nameError') }) return } try { setLoading(true) await updateDatasetSetting({ datasetId: dataset.id, body: { name, description, }, }) 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='block px-3 w-full h-9 bg-gray-100 rounded-lg text-sm text-gray-900 outline-none appearance-none' placeholder={t('datasetSettings.form.namePlaceholder') || ''} />
{t('datasetSettings.form.desc')}