2023-02-18 12:40:37 +03:00
|
|
|
import type { FC } from 'react';
|
2022-04-24 14:05:33 +03:00
|
|
|
import { DropdownItem } from 'reactstrap';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import { faChartPie as pieChartIcon, faEdit as editIcon } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { useToggle } from '../../utils/helpers/hooks';
|
|
|
|
import { DropdownBtnMenu } from '../../utils/DropdownBtnMenu';
|
|
|
|
import { EditDomainRedirectsModal } from './EditDomainRedirectsModal';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { Domain } from '../data';
|
|
|
|
import type { EditDomainRedirects } from '../reducers/domainRedirects';
|
2022-04-24 14:05:33 +03:00
|
|
|
import { supportsDefaultDomainRedirectsEdition, supportsDomainVisits } from '../../utils/helpers/features';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { SelectedServer } from '../../servers/data';
|
|
|
|
import { getServerId } from '../../servers/data';
|
2022-04-30 10:05:12 +03:00
|
|
|
import { DEFAULT_DOMAIN } from '../../visits/reducers/domainVisits';
|
2022-04-24 14:05:33 +03:00
|
|
|
|
|
|
|
interface DomainDropdownProps {
|
|
|
|
domain: Domain;
|
2022-11-04 19:10:02 +03:00
|
|
|
editDomainRedirects: (redirects: EditDomainRedirects) => Promise<void>;
|
2022-04-24 14:05:33 +03:00
|
|
|
selectedServer: SelectedServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const DomainDropdown: FC<DomainDropdownProps> = ({ domain, editDomainRedirects, selectedServer }) => {
|
|
|
|
const [isOpen, toggle] = useToggle();
|
|
|
|
const [isModalOpen, toggleModal] = useToggle();
|
|
|
|
const { isDefault } = domain;
|
|
|
|
const canBeEdited = !isDefault || supportsDefaultDomainRedirectsEdition(selectedServer);
|
|
|
|
const withVisits = supportsDomainVisits(selectedServer);
|
|
|
|
const serverId = getServerId(selectedServer);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DropdownBtnMenu isOpen={isOpen} toggle={toggle}>
|
|
|
|
{withVisits && (
|
2022-04-24 19:36:25 +03:00
|
|
|
<DropdownItem
|
|
|
|
tag={Link}
|
2022-04-30 10:05:12 +03:00
|
|
|
to={`/server/${serverId}/domain/${domain.domain}${domain.isDefault ? `_${DEFAULT_DOMAIN}` : ''}/visits`}
|
2022-04-24 19:36:25 +03:00
|
|
|
>
|
2022-04-24 14:05:33 +03:00
|
|
|
<FontAwesomeIcon icon={pieChartIcon} fixedWidth /> Visit stats
|
|
|
|
</DropdownItem>
|
|
|
|
)}
|
2022-04-24 19:36:25 +03:00
|
|
|
<DropdownItem disabled={!canBeEdited} onClick={!canBeEdited ? undefined : toggleModal}>
|
|
|
|
<FontAwesomeIcon fixedWidth icon={editIcon} /> Edit redirects
|
|
|
|
</DropdownItem>
|
2022-04-24 14:05:33 +03:00
|
|
|
|
|
|
|
<EditDomainRedirectsModal
|
|
|
|
domain={domain}
|
|
|
|
isOpen={isModalOpen}
|
|
|
|
toggle={toggleModal}
|
|
|
|
editDomainRedirects={editDomainRedirects}
|
|
|
|
/>
|
|
|
|
</DropdownBtnMenu>
|
|
|
|
);
|
|
|
|
};
|