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