import { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { useChatWithHistoryContext } from '../context' import Input from './form-input' import { PortalSelect } from '@/app/components/base/select' import { InputVarType } from '@/app/components/workflow/types' import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader' const Form = () => { const { t } = useTranslation() const { appParams, inputsForms, newConversationInputs, newConversationInputsRef, handleNewConversationInputsChange, isMobile, } = useChatWithHistoryContext() const handleFormChange = useCallback((variable: string, value: any) => { handleNewConversationInputsChange({ ...newConversationInputsRef.current, [variable]: value, }) }, [newConversationInputsRef, handleNewConversationInputsChange]) const renderField = (form: any) => { const { label, required, variable, options, } = form if (form.type === 'text-input' || form.type === 'paragraph') { return ( ) } if (form.type === 'number') { return ( handleFormChange(variable, e.target.value)} placeholder={`${label}${!required ? `(${t('appDebug.variableTable.optional')})` : ''}`} /> ) } if (form.type === InputVarType.singleFile) { return ( handleFormChange(variable, files[0])} fileConfig={{ allowed_file_types: form.allowed_file_types, allowed_file_extensions: form.allowed_file_extensions, allowed_file_upload_methods: form.allowed_file_upload_methods, number_limits: 1, fileUploadConfig: (appParams as any).system_parameters, }} /> ) } if (form.type === InputVarType.multiFiles) { return ( handleFormChange(variable, files)} fileConfig={{ allowed_file_types: form.allowed_file_types, allowed_file_extensions: form.allowed_file_extensions, allowed_file_upload_methods: form.allowed_file_upload_methods, number_limits: form.max_length, fileUploadConfig: (appParams as any).system_parameters, }} /> ) } return ( ({ value: option, name: option }))} onSelect={item => handleFormChange(variable, item.value as string)} placeholder={`${label}${!required ? `(${t('appDebug.variableTable.optional')})` : ''}`} /> ) } if (!inputsForms.length) return null return (
{ inputsForms.map(form => (
{form.label}
{renderField(form)}
)) }
) } export default Form