2023-02-18 12:40:37 +03:00
|
|
|
import type { FC } from 'react';
|
|
|
|
import { useRef } from 'react';
|
2022-02-06 22:07:18 +03:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ServerWithId } from './data';
|
2018-07-20 23:14:17 +03:00
|
|
|
|
2020-08-29 10:19:15 +03:00
|
|
|
export interface DeleteServerModalProps {
|
|
|
|
server: ServerWithId;
|
|
|
|
toggle: () => void;
|
|
|
|
isOpen: boolean;
|
2021-10-17 20:13:06 +03:00
|
|
|
redirectHome?: boolean;
|
2020-08-29 10:19:15 +03:00
|
|
|
}
|
|
|
|
|
2022-02-06 22:07:18 +03:00
|
|
|
interface DeleteServerModalConnectProps extends DeleteServerModalProps {
|
2020-08-29 10:19:15 +03:00
|
|
|
deleteServer: (server: ServerWithId) => void;
|
|
|
|
}
|
2018-08-24 13:36:14 +03:00
|
|
|
|
2022-05-28 11:47:39 +03:00
|
|
|
export const DeleteServerModal: FC<DeleteServerModalConnectProps> = (
|
2022-02-06 22:07:18 +03:00
|
|
|
{ server, toggle, isOpen, deleteServer, redirectHome = true },
|
2021-10-17 20:13:06 +03:00
|
|
|
) => {
|
2022-02-06 22:07:18 +03:00
|
|
|
const navigate = useNavigate();
|
2022-11-22 22:08:08 +03:00
|
|
|
const doDelete = useRef<boolean>(false);
|
|
|
|
const toggleAndDelete = () => {
|
|
|
|
doDelete.current = true;
|
2018-07-20 23:14:17 +03:00
|
|
|
toggle();
|
2022-11-22 22:08:08 +03:00
|
|
|
};
|
|
|
|
const onClosed = () => {
|
|
|
|
if (!doDelete.current) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteServer(server);
|
2022-02-06 22:07:18 +03:00
|
|
|
redirectHome && navigate('/');
|
2018-07-20 23:14:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-11-22 22:08:08 +03:00
|
|
|
<Modal isOpen={isOpen} toggle={toggle} centered onClosed={onClosed}>
|
2022-05-29 21:45:19 +03:00
|
|
|
<ModalHeader toggle={toggle} className="text-danger">Remove server</ModalHeader>
|
2018-07-20 23:30:54 +03:00
|
|
|
<ModalBody>
|
2020-03-05 12:18:33 +03:00
|
|
|
<p>Are you sure you want to remove <b>{server ? server.name : ''}</b>?</p>
|
2018-08-12 09:45:48 +03:00
|
|
|
<p>
|
2020-03-05 12:18:33 +03:00
|
|
|
<i>
|
2020-12-06 20:32:24 +03:00
|
|
|
No data will be deleted, only the access to this server will be removed from this device.
|
2020-03-05 12:18:33 +03:00
|
|
|
You can create it again at any moment.
|
|
|
|
</i>
|
2018-08-12 09:45:48 +03:00
|
|
|
</p>
|
2018-07-20 23:30:54 +03:00
|
|
|
</ModalBody>
|
2018-07-20 23:14:17 +03:00
|
|
|
<ModalFooter>
|
2022-03-26 14:17:42 +03:00
|
|
|
<Button color="link" onClick={toggle}>Cancel</Button>
|
2022-11-22 22:08:08 +03:00
|
|
|
<Button color="danger" onClick={toggleAndDelete}>Delete</Button>
|
2018-07-20 23:14:17 +03:00
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|