shlink-web-client/src/servers/EditServer.tsx

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-11-14 00:44:26 +03:00
import { FC } from 'react';
import { Button } from 'reactstrap';
import { NoMenuLayout } from '../common/NoMenuLayout';
import { useGoBack, useParsedQuery } from '../utils/helpers/hooks';
import { ServerForm } from './helpers/ServerForm';
import { withSelectedServer } from './helpers/withSelectedServer';
import { isServerWithId, ServerData } from './data';
interface EditServerProps {
editServer: (serverId: string, serverData: ServerData) => void;
}
export const EditServer = (ServerError: FC) => withSelectedServer<EditServerProps>((
{ editServer, selectedServer, selectServer },
) => {
2022-02-06 22:07:18 +03:00
const goBack = useGoBack();
const { reconnect } = useParsedQuery<{ reconnect?: 'true' }>();
2022-02-06 22:07:18 +03:00
if (!isServerWithId(selectedServer)) {
return null;
}
const handleSubmit = (serverData: ServerData) => {
editServer(selectedServer.id, serverData);
reconnect === 'true' && selectServer(selectedServer.id);
2021-10-22 19:53:00 +03:00
goBack();
};
return (
<NoMenuLayout>
2020-12-12 13:43:16 +03:00
<ServerForm
title={<h5 className="mb-0">Edit &quot;{selectedServer.name}&quot;</h5>}
2020-12-12 13:43:16 +03:00
initialValues={selectedServer}
onSubmit={handleSubmit}
>
<Button outline className="me-2" onClick={goBack}>Cancel</Button>
<Button outline color="primary">Save</Button>
</ServerForm>
</NoMenuLayout>
);
}, ServerError);