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

61 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-02-18 11:11:01 +01:00
import { faCircle as toggleOnIcon } from '@fortawesome/free-regular-svg-icons';
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';
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';
2023-09-05 09:08:42 +02:00
export type ManageServersRowDropdownProps = {
server: ServerWithId;
2023-09-05 09:08:42 +02:00
};
2023-09-05 09:08:42 +02:00
type ManageServersRowDropdownConnectProps = ManageServersRowDropdownProps & {
setAutoConnect: (server: ServerWithId, autoConnect: boolean) => void;
2023-09-05 09:08:42 +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();
const serverUrl = `/server/${server.id}`;
const { autoConnect: isAutoConnect } = server;
const autoConnectIcon = isAutoConnect ? toggleOffIcon : toggleOnIcon;
return (
<RowDropdownBtn minWidth={isAutoConnect ? 210 : 170}>
<DropdownItem tag={Link} to={serverUrl}>
<FontAwesomeIcon icon={connectIcon} fixedWidth /> Connect
</DropdownItem>
<DropdownItem tag={Link} to={`${serverUrl}/edit`}>
<FontAwesomeIcon icon={editIcon} fixedWidth /> Edit server
</DropdownItem>
<DropdownItem onClick={() => setAutoConnect(server, !isAutoConnect)}>
<FontAwesomeIcon icon={autoConnectIcon} fixedWidth /> {isAutoConnect ? 'Do not a' : 'A'}uto-connect
</DropdownItem>
2023-09-30 10:45:52 +02:00
<DropdownItem divider tag="hr" />
<DropdownItem className="dropdown-item--danger" onClick={showModal}>
<FontAwesomeIcon icon={deleteIcon} fixedWidth /> Remove server
</DropdownItem>
<DeleteServerModal redirectHome={false} server={server} isOpen={isModalOpen} toggle={hideModal} />
</RowDropdownBtn>
);
};
2023-09-05 09:08:42 +02:00
export const ManageServersRowDropdownFactory = componentFactory(ManageServersRowDropdown, ['DeleteServerModal']);