import { FC, useMemo, useRef, useState } from 'react'; import ContainedButton from './ContainedButton'; import FlexBox from './FlexBox'; import GeneralInitForm, { GeneralInitFormForwardRefContent, } from './GeneralInitForm'; import mainAxiosInstance from '../lib/singletons/mainAxiosInstance'; import MessageBox, { Message } from './MessageBox'; import NetworkInitForm, { NetworkInitFormForwardRefContent, } from './NetworkInitForm'; import { Panel, PanelHeader } from './Panels'; import Spinner from './Spinner'; import { HeaderText } from './Text'; const StrikerInitForm: FC = () => { const [submitMessage, setSubmitMessage] = useState(); const [isSubmittingForm, setIsSubmittingForm] = useState(false); const generalInitFormRef = useRef({}); const networkInitFormRef = useRef({}); const buildSubmitSection = useMemo( () => isSubmittingForm ? ( ) : ( { setIsSubmittingForm(true); const requestBody: string = JSON.stringify({ ...(generalInitFormRef.current.get?.call(null) ?? {}), ...(networkInitFormRef.current.get?.call(null) ?? {}), }); mainAxiosInstance .put('/command/initialize-striker', requestBody, { headers: { 'Content-Type': 'application/json' }, }) .then(() => { setIsSubmittingForm(false); }) .catch((reason) => { setSubmitMessage({ children: `Failed to submit; ${reason}`, type: 'error', }); setIsSubmittingForm(false); }); }} > Initialize ), [isSubmittingForm], ); return ( {submitMessage && ( setSubmitMessage(undefined)} /> )} {buildSubmitSection} ); }; export default StrikerInitForm;