|
|
@ -1,52 +1,64 @@ |
|
|
|
import { FC, useRef, useState } from 'react'; |
|
|
|
import { FC, useMemo, useRef, useState } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
import ContainedButton from './ContainedButton'; |
|
|
|
import ContainedButton from './ContainedButton'; |
|
|
|
import FlexBox from './FlexBox'; |
|
|
|
import FlexBox from './FlexBox'; |
|
|
|
import GeneralInitForm, { |
|
|
|
import GeneralInitForm, { |
|
|
|
GeneralInitFormForwardRefContent, |
|
|
|
GeneralInitFormForwardRefContent, |
|
|
|
} from './GeneralInitForm'; |
|
|
|
} from './GeneralInitForm'; |
|
|
|
|
|
|
|
import mainAxiosInstance from '../lib/singletons/mainAxiosInstance'; |
|
|
|
import NetworkInitForm, { |
|
|
|
import NetworkInitForm, { |
|
|
|
NetworkInitFormForwardRefContent, |
|
|
|
NetworkInitFormForwardRefContent, |
|
|
|
} from './NetworkInitForm'; |
|
|
|
} from './NetworkInitForm'; |
|
|
|
import { Panel, PanelHeader } from './Panels'; |
|
|
|
import { Panel, PanelHeader } from './Panels'; |
|
|
|
import { BodyText, HeaderText } from './Text'; |
|
|
|
import Spinner from './Spinner'; |
|
|
|
|
|
|
|
import { HeaderText } from './Text'; |
|
|
|
|
|
|
|
|
|
|
|
const StrikerInitForm: FC = () => { |
|
|
|
const StrikerInitForm: FC = () => { |
|
|
|
const [requestBody, setRequestBody] = useState< |
|
|
|
const [isSubmittingForm, setIsSubmittingForm] = useState<boolean>(false); |
|
|
|
Record<string, unknown> | undefined |
|
|
|
|
|
|
|
>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const generalInitFormRef = useRef<GeneralInitFormForwardRefContent>({}); |
|
|
|
const generalInitFormRef = useRef<GeneralInitFormForwardRefContent>({}); |
|
|
|
const networkInitFormRef = useRef<NetworkInitFormForwardRefContent>({}); |
|
|
|
const networkInitFormRef = useRef<NetworkInitFormForwardRefContent>({}); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
const buildSubmitSection = useMemo( |
|
|
|
<Panel> |
|
|
|
() => |
|
|
|
<PanelHeader> |
|
|
|
isSubmittingForm ? ( |
|
|
|
<HeaderText text="Initialize striker" /> |
|
|
|
<Spinner /> |
|
|
|
</PanelHeader> |
|
|
|
) : ( |
|
|
|
<FlexBox> |
|
|
|
|
|
|
|
<GeneralInitForm ref={generalInitFormRef} /> |
|
|
|
|
|
|
|
<NetworkInitForm ref={networkInitFormRef} /> |
|
|
|
|
|
|
|
<FlexBox row sx={{ flexDirection: 'row-reverse' }}> |
|
|
|
<FlexBox row sx={{ flexDirection: 'row-reverse' }}> |
|
|
|
<ContainedButton |
|
|
|
<ContainedButton |
|
|
|
onClick={() => { |
|
|
|
onClick={() => { |
|
|
|
setRequestBody({ |
|
|
|
setIsSubmittingForm(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const requestBody: string = JSON.stringify({ |
|
|
|
...(generalInitFormRef.current.get?.call(null) ?? {}), |
|
|
|
...(generalInitFormRef.current.get?.call(null) ?? {}), |
|
|
|
...(networkInitFormRef.current.get?.call(null) ?? {}), |
|
|
|
...(networkInitFormRef.current.get?.call(null) ?? {}), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mainAxiosInstance |
|
|
|
|
|
|
|
.put('/command/initialize-striker', requestBody, { |
|
|
|
|
|
|
|
headers: { 'Content-Type': 'application/json' }, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
setIsSubmittingForm(false); |
|
|
|
|
|
|
|
}); |
|
|
|
}} |
|
|
|
}} |
|
|
|
> |
|
|
|
> |
|
|
|
Initialize |
|
|
|
Initialize |
|
|
|
</ContainedButton> |
|
|
|
</ContainedButton> |
|
|
|
</FlexBox> |
|
|
|
</FlexBox> |
|
|
|
{requestBody && ( |
|
|
|
), |
|
|
|
<pre> |
|
|
|
[isSubmittingForm], |
|
|
|
<BodyText |
|
|
|
); |
|
|
|
sx={{ fontSize: '.8em' }} |
|
|
|
|
|
|
|
text={JSON.stringify(requestBody, null, 2)} |
|
|
|
return ( |
|
|
|
/> |
|
|
|
<Panel> |
|
|
|
</pre> |
|
|
|
<PanelHeader> |
|
|
|
)} |
|
|
|
<HeaderText text="Initialize striker" /> |
|
|
|
|
|
|
|
</PanelHeader> |
|
|
|
|
|
|
|
<FlexBox> |
|
|
|
|
|
|
|
<GeneralInitForm ref={generalInitFormRef} /> |
|
|
|
|
|
|
|
<NetworkInitForm ref={networkInitFormRef} /> |
|
|
|
|
|
|
|
{buildSubmitSection} |
|
|
|
</FlexBox> |
|
|
|
</FlexBox> |
|
|
|
</Panel> |
|
|
|
</Panel> |
|
|
|
); |
|
|
|
); |
|
|
|