2023-02-18 11:11:01 +01:00
|
|
|
import { faCircle as toggleOnIcon } from '@fortawesome/free-regular-svg-icons';
|
2021-10-22 20:26:11 +02:00
|
|
|
import {
|
|
|
|
faBan as toggleOffIcon,
|
|
|
|
faEdit as editIcon,
|
|
|
|
faMinusCircle as deleteIcon,
|
|
|
|
faPlug as connectIcon,
|
|
|
|
} from '@fortawesome/free-solid-svg-icons';
|
2023-02-18 11:11:01 +01:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2023-08-04 22:59:33 +02:00
|
|
|
import { RowDropdownBtn, useToggle } from '@shlinkio/shlink-frontend-kit';
|
2023-02-18 11:11:01 +01:00
|
|
|
import type { FC } from 'react';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import { DropdownItem } from 'reactstrap';
|
2023-09-05 09:08:42 +02:00
|
|
|
import type { FCWithDeps } from '../container/utils';
|
|
|
|
import { componentFactory, useDependencies } from '../container/utils';
|
2023-02-18 10:40:37 +01:00
|
|
|
import type { ServerWithId } from './data';
|
2023-02-18 11:11:01 +01:00
|
|
|
import type { DeleteServerModalProps } from './DeleteServerModal';
|
2021-10-22 20:26:11 +02:00
|
|
|
|
2023-09-05 09:08:42 +02:00
|
|
|
export type ManageServersRowDropdownProps = {
|
2021-10-22 20:26:11 +02:00
|
|
|
server: ServerWithId;
|
2023-09-05 09:08:42 +02:00
|
|
|
};
|
2021-10-22 20:26:11 +02:00
|
|
|
|
2023-09-05 09:08:42 +02:00
|
|
|
type ManageServersRowDropdownConnectProps = ManageServersRowDropdownProps & {
|
2021-10-22 20:26:11 +02:00
|
|
|
setAutoConnect: (server: ServerWithId, autoConnect: boolean) => void;
|
2023-09-05 09:08:42 +02:00
|
|
|
};
|
2021-10-22 20:26:11 +02:00
|
|
|
|
2023-09-05 09:08:42 +02:00
|
|
|
type ManageServersRowDropdownDeps = {
|
|
|
|
DeleteServerModal: FC<DeleteServerModalProps>
|
|
|
|
};
|
|
|
|
|
|
|
|
const ManageServersRowDropdown: FCWithDeps<ManageServersRowDropdownConnectProps, ManageServersRowDropdownDeps> = (
|
|
|
|
{ server, setAutoConnect },
|
|
|
|
) => {
|
|
|
|
const { DeleteServerModal } = useDependencies(ManageServersRowDropdown);
|
2022-03-26 12:17:42 +01:00
|
|
|
const [isModalOpen,, showModal, hideModal] = useToggle();
|
2021-10-22 20:26:11 +02:00
|
|
|
const serverUrl = `/server/${server.id}`;
|
|
|
|
const { autoConnect: isAutoConnect } = server;
|
|
|
|
const autoConnectIcon = isAutoConnect ? toggleOffIcon : toggleOnIcon;
|
|
|
|
|
|
|
|
return (
|
2024-03-17 12:11:43 +01:00
|
|
|
<RowDropdownBtn minWidth={isAutoConnect ? 210 : 170}>
|
2021-10-22 20:26:11 +02:00
|
|
|
<DropdownItem tag={Link} to={serverUrl}>
|
|
|
|
<FontAwesomeIcon icon={connectIcon} fixedWidth /> Connect
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem tag={Link} to={`${serverUrl}/edit`}>
|
|
|
|
<FontAwesomeIcon icon={editIcon} fixedWidth /> Edit server
|
|
|
|
</DropdownItem>
|
2022-06-04 10:20:24 +02:00
|
|
|
<DropdownItem onClick={() => setAutoConnect(server, !isAutoConnect)}>
|
2021-10-22 20:26:11 +02:00
|
|
|
<FontAwesomeIcon icon={autoConnectIcon} fixedWidth /> {isAutoConnect ? 'Do not a' : 'A'}uto-connect
|
|
|
|
</DropdownItem>
|
2023-09-30 10:45:52 +02:00
|
|
|
<DropdownItem divider tag="hr" />
|
2021-10-22 20:26:11 +02:00
|
|
|
<DropdownItem className="dropdown-item--danger" onClick={showModal}>
|
|
|
|
<FontAwesomeIcon icon={deleteIcon} fixedWidth /> Remove server
|
|
|
|
</DropdownItem>
|
|
|
|
|
|
|
|
<DeleteServerModal redirectHome={false} server={server} isOpen={isModalOpen} toggle={hideModal} />
|
2023-05-27 10:36:52 +02:00
|
|
|
</RowDropdownBtn>
|
2021-10-22 20:26:11 +02:00
|
|
|
);
|
|
|
|
};
|
2023-09-05 09:08:42 +02:00
|
|
|
|
|
|
|
export const ManageServersRowDropdownFactory = componentFactory(ManageServersRowDropdown, ['DeleteServerModal']);
|