diff --git a/web/src/pages/agent/form-sheet/use-form-config-map.tsx b/web/src/pages/agent/form-sheet/use-form-config-map.tsx index 0cc7b3b61..a2ef2aceb 100644 --- a/web/src/pages/agent/form-sheet/use-form-config-map.tsx +++ b/web/src/pages/agent/form-sheet/use-form-config-map.tsx @@ -186,7 +186,13 @@ export function useFormConfigMap() { [Operator.QWeather]: { component: QWeatherForm, defaultValues: {}, - schema: z.object({}), + schema: z.object({ + web_apikey: z.string(), + lang: z.string(), + type: z.string(), + user_type: z.string(), + time_period: z.string().optional(), + }), }, [Operator.ExeSQL]: { component: ExeSQLForm, diff --git a/web/src/pages/agent/form/qweather-form/index.tsx b/web/src/pages/agent/form/qweather-form/index.tsx index b69939826..bb9be92c8 100644 --- a/web/src/pages/agent/form/qweather-form/index.tsx +++ b/web/src/pages/agent/form/qweather-form/index.tsx @@ -1,86 +1,155 @@ -import { useTranslate } from '@/hooks/common-hooks'; -import { Form, Input, Select } from 'antd'; +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 { IOperatorForm } from '../../interface'; -import DynamicInputVariable from '../components/dynamic-input-variable'; +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 QWeatherForm = ({ onValuesChange, form, node }: IOperatorForm) => { - const { t } = useTranslate('flow'); const qWeatherLangOptions = useMemo(() => { return QWeatherLangOptions.map((x) => ({ value: x, - label: t(`qWeatherLangOptions.${x}`), + label: t(`flow.qWeatherLangOptions.${x}`), })); }, [t]); const qWeatherTypeOptions = useMemo(() => { return QWeatherTypeOptions.map((x) => ({ value: x, - label: t(`qWeatherTypeOptions.${x}`), + label: t(`flow.qWeatherTypeOptions.${x}`), })); }, [t]); const qWeatherUserTypeOptions = useMemo(() => { return QWeatherUserTypeOptions.map((x) => ({ value: x, - label: t(`qWeatherUserTypeOptions.${x}`), + label: t(`flow.qWeatherUserTypeOptions.${x}`), })); }, [t]); - const getQWeatherTimePeriodOptions = useCallback( - (userType: string) => { - let options = QWeatherTimePeriodOptions; - if (userType === 'free') { - options = options.slice(0, 3); - } - return options.map((x) => ({ - value: x, - label: t(`qWeatherTimePeriodOptions.${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 ( -