'use client' import { useState } from 'react' import { useContext } from 'use-context-selector' import { BookOpenIcon } from '@heroicons/react/24/outline' import { useTranslation } from 'react-i18next' import { ToastContext } from '@/app/components/base/toast' import PermissionsRadio from '../permissions-radio' import IndexMethodRadio from '../index-method-radio' import Button from '@/app/components/base/button' import { useDatasetsContext } from '@/context/datasets-context' import { updateDatasetSetting } from '@/service/datasets' const rowClass = ` flex justify-between py-4 ` const labelClass = ` flex items-center w-[168px] h-9 ` const inputClass = ` w-[480px] px-3 bg-gray-100 text-sm text-gray-800 rounded-lg outline-none appearance-none ` const Form = () => { const { t } = useTranslation() const { notify } = useContext(ToastContext) const { currentDataset, mutateDatasets } = useDatasetsContext() const [loading, setLoading] = useState(false) const [name, setName] = useState(currentDataset?.name) const [description, setDescription] = useState(currentDataset?.description) const [permission, setPermission] = useState(currentDataset?.permission) const [indexMethod, setIndexMethod] = useState(currentDataset?.indexing_technique) const handleSave = async () => { if (loading) return if (!name?.trim()) { notify({ type: 'error', message: t('datasetSettings.form.nameError') }) return } try { setLoading(true) await updateDatasetSetting({ datasetId: currentDataset!.id, body: { name, description, permission, indexing_technique: indexMethod } }) notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) mutateDatasets() } catch (e) { notify({ type: 'error', message: t('common.actionMsg.modificationFailed') }) } finally { setLoading(false) } } return (