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

52 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-02-18 12:40:37 +03:00
import type { FC } from 'react';
import { Button } from 'reactstrap';
import { NoMenuLayout } from '../common/NoMenuLayout';
2023-09-05 10:08:42 +03:00
import type { FCWithDeps } from '../container/utils';
import { componentFactory } from '../container/utils';
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';
2023-09-05 10:08:42 +03:00
type EditServerProps = WithSelectedServerProps & {
editServer: (serverId: string, serverData: ServerData) => void;
2023-09-05 10:08:42 +03:00
};
2023-09-05 10:08:42 +03:00
type EditServerDeps = {
ServerError: FC;
};
const EditServer: FCWithDeps<EditServerProps, EditServerDeps> = withSelectedServer((
{ 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>
);
2023-09-05 10:08:42 +03:00
});
export const EditServerFactory = componentFactory(EditServer, ['ServerError']);