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