2023-02-18 12:40:37 +03:00
|
|
|
import type { 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';
|
2023-09-05 10:08:42 +03:00
|
|
|
import type { FCWithDeps } from '../container/utils';
|
|
|
|
import { componentFactory } from '../container/utils';
|
2022-12-31 18:42:04 +03:00
|
|
|
import { useGoBack, useParsedQuery } from '../utils/helpers/hooks';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ServerData } from './data';
|
|
|
|
import { isServerWithId } from './data';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { ServerForm } from './helpers/ServerForm';
|
2023-09-05 10:08:42 +03:00
|
|
|
import type { WithSelectedServerProps } from './helpers/withSelectedServer';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { withSelectedServer } from './helpers/withSelectedServer';
|
2020-08-29 21:20:45 +03:00
|
|
|
|
2023-09-05 10:08:42 +03:00
|
|
|
type EditServerProps = WithSelectedServerProps & {
|
2020-08-29 21:20:45 +03:00
|
|
|
editServer: (serverId: string, serverData: ServerData) => void;
|
2023-09-05 10:08:42 +03:00
|
|
|
};
|
2020-08-29 21:20:45 +03:00
|
|
|
|
2023-09-05 10:08:42 +03:00
|
|
|
type EditServerDeps = {
|
|
|
|
ServerError: FC;
|
|
|
|
};
|
|
|
|
|
|
|
|
const EditServer: FCWithDeps<EditServerProps, EditServerDeps> = withSelectedServer((
|
2022-12-31 18:42:04 +03:00
|
|
|
{ editServer, selectedServer, selectServer },
|
|
|
|
) => {
|
2022-02-06 22:07:18 +03:00
|
|
|
const goBack = useGoBack();
|
2022-12-31 18:42:04 +03:00
|
|
|
const { reconnect } = useParsedQuery<{ reconnect?: 'true' }>();
|
2022-02-06 22:07:18 +03:00
|
|
|
|
2020-08-29 21:20:45 +03:00
|
|
|
if (!isServerWithId(selectedServer)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleSubmit = (serverData: ServerData) => {
|
|
|
|
editServer(selectedServer.id, serverData);
|
2022-12-31 18:42:04 +03:00
|
|
|
reconnect === 'true' && selectServer(selectedServer.id);
|
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}
|
|
|
|
>
|
2022-03-05 15:26:28 +03:00
|
|
|
<Button outline className="me-2" onClick={goBack}>Cancel</Button>
|
2020-08-29 21:20:45 +03:00
|
|
|
<Button outline color="primary">Save</Button>
|
|
|
|
</ServerForm>
|
|
|
|
</NoMenuLayout>
|
|
|
|
);
|
2023-09-05 10:08:42 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
export const EditServerFactory = componentFactory(EditServer, ['ServerError']);
|