import { useTranslation } from 'react-i18next' import { useChatWithHistoryContext } from '../context' import { PortalSelect } from '@/app/components/base/select' const Form = () => { const { t } = useTranslation() const { inputsForms, newConversationInputs, handleNewConversationInputsChange, isMobile, } = useChatWithHistoryContext() const handleFormChange = (variable: string, value: string) => { handleNewConversationInputsChange({ ...newConversationInputs, [variable]: value, }) } const renderField = (form: any) => { const { label, required, max_length, variable, options, } = form if (form.type === 'text-input') { return ( handleFormChange(variable, e.target.value)} placeholder={`${label}${!required ? `(${t('appDebug.variableTable.optional')})` : ''}`} /> ) } if (form.type === 'paragraph') { return ( handleFormChange(variable, e.target.value)} placeholder={`${label}${!required ? `(${t('appDebug.variableTable.optional')})` : ''}`} /> ) } 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