import intl from 'react-intl-universal'; import React, { useEffect, useState } from 'react'; import { Typography, Input, Form, Button, Select, message } from 'antd'; import { request } from '@/utils/http'; import config from '@/utils/config'; const { Option } = Select; const NotificationSetting = ({ data }: any) => { const [loading, setLoading] = useState(false); const [notificationMode, setNotificationMode] = useState('closed'); const [fields, setFields] = useState([]); const [form] = Form.useForm(); const handleOk = (values: any) => { setLoading(true); const { type } = values; if (type == 'closed') { values.type = ''; } request .put(`${config.apiPrefix}user/notification`, values) .then(({ code, data }) => { if (code === 200) { message.success( values.type ? intl.get('通知发送成功') : intl.get('通知关闭成功'), ); } }) .catch((error: any) => { console.log(error); }) .finally(() => setLoading(false)); }; const notificationModeChange = (value: string) => { setNotificationMode(value); const _fields = (config.notificationModeMap as any)[value]; setFields(_fields || []); }; useEffect(() => { if (data && data.type) { notificationModeChange(data.type); form.setFieldsValue({ ...data }); } }, [data]); return (
{fields.map((x) => ( {x.items ? ( ) : ( )} ))}
); }; export default NotificationSetting;