2024-08-09 13:40:13 +08:00
|
|
|
import { useTranslate } from '@/hooks/common-hooks';
|
|
|
|
import { Form, Input, Select } from 'antd';
|
2024-09-29 15:40:20 +08:00
|
|
|
import { useCallback, useMemo } from 'react';
|
2024-08-09 13:40:13 +08:00
|
|
|
import {
|
|
|
|
QWeatherLangOptions,
|
|
|
|
QWeatherTimePeriodOptions,
|
|
|
|
QWeatherTypeOptions,
|
|
|
|
QWeatherUserTypeOptions,
|
2024-10-09 19:39:04 +08:00
|
|
|
} from '../../constant';
|
|
|
|
import { IOperatorForm } from '../../interface';
|
2024-11-01 13:31:48 +08:00
|
|
|
import DynamicInputVariable from '../components/dynamic-input-variable';
|
2024-08-09 13:40:13 +08:00
|
|
|
|
2024-11-01 13:31:48 +08:00
|
|
|
const QWeatherForm = ({ onValuesChange, form, node }: IOperatorForm) => {
|
2024-08-09 13:40:13 +08:00
|
|
|
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]);
|
|
|
|
|
2024-09-29 15:40:20 +08:00
|
|
|
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],
|
|
|
|
);
|
2024-08-09 13:40:13 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
name="basic"
|
|
|
|
autoComplete="off"
|
|
|
|
form={form}
|
|
|
|
onValuesChange={onValuesChange}
|
2024-11-01 13:31:48 +08:00
|
|
|
layout={'vertical'}
|
2024-08-09 13:40:13 +08:00
|
|
|
>
|
2024-11-01 13:31:48 +08:00
|
|
|
<DynamicInputVariable nodeId={node?.id}></DynamicInputVariable>
|
2024-08-09 13:40:13 +08:00
|
|
|
<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>
|
2024-09-29 15:40:20 +08:00
|
|
|
<Form.Item noStyle dependencies={['type', 'user_type']}>
|
2024-08-09 13:40:13 +08:00
|
|
|
{({ getFieldValue }) =>
|
|
|
|
getFieldValue('type') === 'weather' && (
|
|
|
|
<Form.Item label={t('timePeriod')} name={'time_period'}>
|
2024-09-29 15:40:20 +08:00
|
|
|
<Select
|
|
|
|
options={getQWeatherTimePeriodOptions(
|
|
|
|
getFieldValue('user_type'),
|
|
|
|
)}
|
|
|
|
></Select>
|
2024-08-09 13:40:13 +08:00
|
|
|
</Form.Item>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default QWeatherForm;
|