File size: 2,594 Bytes
			
			| 42dbb1f e26292c 42dbb1f cd85d9e a2c2382 42dbb1f a2c2382 42dbb1f e26292c 42dbb1f a2c2382 42dbb1f 2bdad3e 42dbb1f e26292c 42dbb1f e26292c 42dbb1f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | import { useTranslate } from '@/hooks/common-hooks';
import { Form, Input, Select } from 'antd';
import { useCallback, useMemo } from 'react';
import {
  QWeatherLangOptions,
  QWeatherTimePeriodOptions,
  QWeatherTypeOptions,
  QWeatherUserTypeOptions,
} from '../../constant';
import { IOperatorForm } from '../../interface';
import DynamicInputVariable from '../components/dynamic-input-variable';
const QWeatherForm = ({ onValuesChange, form, node }: IOperatorForm) => {
  const { t } = useTranslate('flow');
  const qWeatherLangOptions = useMemo(() => {
    return QWeatherLangOptions.map((x) => ({
      value: x,
      label: t(`qWeatherLangOptions.${x}`),
    }));
  }, [t]);
  const qWeatherTypeOptions = useMemo(() => {
    return QWeatherTypeOptions.map((x) => ({
      value: x,
      label: t(`qWeatherTypeOptions.${x}`),
    }));
  }, [t]);
  const qWeatherUserTypeOptions = useMemo(() => {
    return QWeatherUserTypeOptions.map((x) => ({
      value: x,
      label: t(`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],
  );
  return (
    <Form
      name="basic"
      autoComplete="off"
      form={form}
      onValuesChange={onValuesChange}
      layout={'vertical'}
    >
      <DynamicInputVariable node={node}></DynamicInputVariable>
      <Form.Item label={t('webApiKey')} name={'web_apikey'}>
        <Input></Input>
      </Form.Item>
      <Form.Item label={t('lang')} name={'lang'}>
        <Select options={qWeatherLangOptions}></Select>
      </Form.Item>
      <Form.Item label={t('type')} name={'type'}>
        <Select options={qWeatherTypeOptions}></Select>
      </Form.Item>
      <Form.Item label={t('userType')} name={'user_type'}>
        <Select options={qWeatherUserTypeOptions}></Select>
      </Form.Item>
      <Form.Item noStyle dependencies={['type', 'user_type']}>
        {({ getFieldValue }) =>
          getFieldValue('type') === 'weather' && (
            <Form.Item label={t('timePeriod')} name={'time_period'}>
              <Select
                options={getQWeatherTimePeriodOptions(
                  getFieldValue('user_type'),
                )}
              ></Select>
            </Form.Item>
          )
        }
      </Form.Item>
    </Form>
  );
};
export default QWeatherForm;
 |