import type { FC } from 'react'; import { Button } from 'reactstrap'; import { NoMenuLayout } from '../common/NoMenuLayout'; import type { FCWithDeps } from '../container/utils'; import { componentFactory } from '../container/utils'; import { useGoBack, useParsedQuery } from '../utils/helpers/hooks'; import type { ServerData } from './data'; import { isServerWithId } from './data'; import { ServerForm } from './helpers/ServerForm'; import type { WithSelectedServerProps } from './helpers/withSelectedServer'; import { withSelectedServer } from './helpers/withSelectedServer'; type EditServerProps = WithSelectedServerProps & { editServer: (serverId: string, serverData: ServerData) => void; }; type EditServerDeps = { ServerError: FC; }; const EditServer: FCWithDeps = withSelectedServer(( { editServer, selectedServer, selectServer }, ) => { const goBack = useGoBack(); const { reconnect } = useParsedQuery<{ reconnect?: 'true' }>(); if (!isServerWithId(selectedServer)) { return null; } const handleSubmit = (serverData: ServerData) => { editServer(selectedServer.id, serverData); reconnect === 'true' && selectServer(selectedServer.id); goBack(); }; return ( Edit "{selectedServer.name}"} initialValues={selectedServer} onSubmit={handleSubmit} > ); }); export const EditServerFactory = componentFactory(EditServer, ['ServerError']);