From 5a8ae4a2895864694045bd8ef2008b9849b88cc9 Mon Sep 17 00:00:00 2001 From: balibabu Date: Sun, 29 Sep 2024 15:40:20 +0800 Subject: [PATCH] fix: Filter the timePeriod options based on the userType parameter #1739 (#2657) ### What problem does this PR solve? fix: Filter the timePeriod options based on the userType parameter #1739 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): --- web/src/pages/flow/qweather-form/index.tsx | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/web/src/pages/flow/qweather-form/index.tsx b/web/src/pages/flow/qweather-form/index.tsx index b86b0fc43..fbbc51f90 100644 --- a/web/src/pages/flow/qweather-form/index.tsx +++ b/web/src/pages/flow/qweather-form/index.tsx @@ -1,6 +1,6 @@ import { useTranslate } from '@/hooks/common-hooks'; import { Form, Input, Select } from 'antd'; -import { useMemo } from 'react'; +import { useCallback, useMemo } from 'react'; import { QWeatherLangOptions, QWeatherTimePeriodOptions, @@ -32,12 +32,19 @@ const QWeatherForm = ({ onValuesChange, form }: IOperatorForm) => { })); }, [t]); - const qWeatherTimePeriodOptions = useMemo(() => { - return QWeatherTimePeriodOptions.map((x) => ({ - value: x, - label: t(`qWeatherTimePeriodOptions.${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], + ); return (
{ - + {({ getFieldValue }) => getFieldValue('type') === 'weather' && ( - + ) }