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

43 lines
1.3 KiB
TypeScript
Raw Normal View History

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