balibabu commited on
Commit
e26292c
·
1 Parent(s): 3f21a7a

fix: Filter the timePeriod options based on the userType parameter #1739 (#2657)

Browse files

### 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 CHANGED
@@ -1,6 +1,6 @@
1
  import { useTranslate } from '@/hooks/common-hooks';
2
  import { Form, Input, Select } from 'antd';
3
- import { useMemo } from 'react';
4
  import {
5
  QWeatherLangOptions,
6
  QWeatherTimePeriodOptions,
@@ -32,12 +32,19 @@ const QWeatherForm = ({ onValuesChange, form }: IOperatorForm) => {
32
  }));
33
  }, [t]);
34
 
35
- const qWeatherTimePeriodOptions = useMemo(() => {
36
- return QWeatherTimePeriodOptions.map((x) => ({
37
- value: x,
38
- label: t(`qWeatherTimePeriodOptions.${x}`),
39
- }));
40
- }, [t]);
 
 
 
 
 
 
 
41
 
42
  return (
43
  <Form
@@ -60,11 +67,15 @@ const QWeatherForm = ({ onValuesChange, form }: IOperatorForm) => {
60
  <Form.Item label={t('userType')} name={'user_type'}>
61
  <Select options={qWeatherUserTypeOptions}></Select>
62
  </Form.Item>
63
- <Form.Item noStyle dependencies={['type']}>
64
  {({ getFieldValue }) =>
65
  getFieldValue('type') === 'weather' && (
66
  <Form.Item label={t('timePeriod')} name={'time_period'}>
67
- <Select options={qWeatherTimePeriodOptions}></Select>
 
 
 
 
68
  </Form.Item>
69
  )
70
  }
 
1
  import { useTranslate } from '@/hooks/common-hooks';
2
  import { Form, Input, Select } from 'antd';
3
+ import { useCallback, useMemo } from 'react';
4
  import {
5
  QWeatherLangOptions,
6
  QWeatherTimePeriodOptions,
 
32
  }));
33
  }, [t]);
34
 
35
+ const getQWeatherTimePeriodOptions = useCallback(
36
+ (userType: string) => {
37
+ let options = QWeatherTimePeriodOptions;
38
+ if (userType === 'free') {
39
+ options = options.slice(0, 3);
40
+ }
41
+ return options.map((x) => ({
42
+ value: x,
43
+ label: t(`qWeatherTimePeriodOptions.${x}`),
44
+ }));
45
+ },
46
+ [t],
47
+ );
48
 
49
  return (
50
  <Form
 
67
  <Form.Item label={t('userType')} name={'user_type'}>
68
  <Select options={qWeatherUserTypeOptions}></Select>
69
  </Form.Item>
70
+ <Form.Item noStyle dependencies={['type', 'user_type']}>
71
  {({ getFieldValue }) =>
72
  getFieldValue('type') === 'weather' && (
73
  <Form.Item label={t('timePeriod')} name={'time_period'}>
74
+ <Select
75
+ options={getQWeatherTimePeriodOptions(
76
+ getFieldValue('user_type'),
77
+ )}
78
+ ></Select>
79
  </Form.Item>
80
  )
81
  }