import React, { useEffect, useRef, useState } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { Button, Form, Grid, Input, Link, Message, Select, Typography, } from '@arco-design/web-react'; import { FormInstance } from '@arco-design/web-react/es/Form'; import axios from 'axios'; import { ReducerState } from '../../redux'; import { UPDATE_FORM, GO_PREV, GO_NEXT } from './redux/actionTypes'; import useLocale from '../../utils/useLocale'; import styles from './style/index.module.less'; function Service() { const locale = useLocale(); const state = useSelector((state: ReducerState) => state.stepForm); const dispatch = useDispatch(); const { data } = state; const formRef = useRef(); const [loading, setLoading] = useState(false); const submit = () => { setLoading(true); const formData = formRef.current.getFieldsValue(); axios .post('/api/domainApply', { data: { ...data, ...formData, }, }) .finally(() => { setLoading(false); }) .then(() => { dispatch({ type: GO_NEXT }); }) .catch((error) => { Message.error(error.message); }); }; const onSubmitClick = () => { formRef.current.validate().then(() => { submit(); }); }; useEffect(() => { formRef.current.setFieldsValue(data); }, [data]); useEffect(() => { return () => { const formData = formRef.current?.getFieldsValue() || {}; dispatch({ type: UPDATE_FORM, payload: { data: formData } }); }; }, []); return (
{locale['stepForm.form.title.upstream']} {locale['stepForm.link.psmDefine']} {locale['stepForm.link.selectStrategy']}
); } export default Service;