import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { RAGFlowSelect } from '@/components/ui/select'; import { useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { QWeatherLangOptions, QWeatherTimePeriodOptions, QWeatherTypeOptions, QWeatherUserTypeOptions, } from '../../constant'; import { INextOperatorForm } from '../../interface'; import { DynamicInputVariable } from '../components/next-dynamic-input-variable'; enum FormFieldName { Type = 'type', UserType = 'user_type', } const QWeatherForm = ({ form, node }: INextOperatorForm) => { const { t } = useTranslation(); const typeValue = form.watch(FormFieldName.Type); const qWeatherLangOptions = useMemo(() => { return QWeatherLangOptions.map((x) => ({ value: x, label: t(`flow.qWeatherLangOptions.${x}`), })); }, [t]); const qWeatherTypeOptions = useMemo(() => { return QWeatherTypeOptions.map((x) => ({ value: x, label: t(`flow.qWeatherTypeOptions.${x}`), })); }, [t]); const qWeatherUserTypeOptions = useMemo(() => { return QWeatherUserTypeOptions.map((x) => ({ value: x, label: t(`flow.qWeatherUserTypeOptions.${x}`), })); }, [t]); const getQWeatherTimePeriodOptions = useCallback(() => { let options = QWeatherTimePeriodOptions; const userType = form.getValues(FormFieldName.UserType); if (userType === 'free') { options = options.slice(0, 3); } return options.map((x) => ({ value: x, label: t(`flow.qWeatherTimePeriodOptions.${x}`), })); }, [form, t]); return (
{ e.preventDefault(); }} > ( {t('flow.webApiKey')} )} /> ( {t('flow.lang')} )} /> ( {t('flow.type')} )} /> ( {t('flow.userType')} )} /> {typeValue === 'weather' && ( ( {t('flow.timePeriod')} )} /> )} ); }; export default QWeatherForm;