import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form'; import { LoadingButton } from '@/components/ui/loading-button'; import { MultiSelect } from '@/components/ui/multi-select'; import { useSelectKnowledgeOptions } from '@/hooks/knowledge-hooks'; import { IModalProps } from '@/interfaces/common'; import { zodResolver } from '@hookform/resolvers/zod'; import { Link2 } from 'lucide-react'; import { useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { z } from 'zod'; import { UseHandleConnectToKnowledgeReturnType } from './hooks'; const FormId = 'LinkToDatasetForm'; const FormSchema = z.object({ knowledgeIds: z.array(z.string()).min(0, { message: 'Username must be at least 1 characters.', }), }); function LinkToDatasetForm({ initialConnectedIds, onConnectToKnowledgeOk, }: Pick< UseHandleConnectToKnowledgeReturnType, 'initialConnectedIds' | 'onConnectToKnowledgeOk' >) { const { t } = useTranslation(); const form = useForm>({ resolver: zodResolver(FormSchema), defaultValues: { knowledgeIds: initialConnectedIds, }, }); const options = useSelectKnowledgeOptions(); function onSubmit(data: z.infer) { onConnectToKnowledgeOk(data.knowledgeIds); } // useEffect(() => { // form.setValue('knowledgeIds', initialConnectedIds); // this is invalid // }, [form, initialConnectedIds]); return (
( Name )} /> ); } export function LinkToDatasetDialog({ hideModal, initialConnectedIds, onConnectToKnowledgeOk, loading, }: IModalProps & Pick< UseHandleConnectToKnowledgeReturnType, 'initialConnectedIds' | 'onConnectToKnowledgeOk' >) { const { t } = useTranslation(); return ( {t('fileManager.addToKnowledge')}
Save
); }