2021-12-26 15:53:17 +03:00
|
|
|
import { FC, useEffect } from 'react';
|
2021-08-21 18:53:06 +03:00
|
|
|
import { Button, UncontrolledTooltip } from 'reactstrap';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import {
|
|
|
|
faBan as forbiddenIcon,
|
2021-12-26 15:53:17 +03:00
|
|
|
faDotCircle as defaultDomainIcon,
|
2021-08-21 18:53:06 +03:00
|
|
|
faEdit as editIcon,
|
|
|
|
} from '@fortawesome/free-solid-svg-icons';
|
2021-12-26 15:53:17 +03:00
|
|
|
import { ShlinkDomainRedirects } from '../api/types';
|
2021-08-21 18:53:06 +03:00
|
|
|
import { useToggle } from '../utils/helpers/hooks';
|
|
|
|
import { OptionalString } from '../utils/utils';
|
2021-12-09 15:44:29 +03:00
|
|
|
import { SelectedServer } from '../servers/data';
|
|
|
|
import { supportsDefaultDomainRedirectsEdition } from '../utils/helpers/features';
|
2021-08-21 18:53:06 +03:00
|
|
|
import { EditDomainRedirectsModal } from './helpers/EditDomainRedirectsModal';
|
2021-12-28 00:27:13 +03:00
|
|
|
import { Domain } from './data';
|
|
|
|
import { DomainStatusIcon } from './helpers/DomainStatusIcon';
|
2021-08-21 18:53:06 +03:00
|
|
|
|
|
|
|
interface DomainRowProps {
|
2021-12-26 15:53:17 +03:00
|
|
|
domain: Domain;
|
2021-08-21 18:53:06 +03:00
|
|
|
defaultRedirects?: ShlinkDomainRedirects;
|
|
|
|
editDomainRedirects: (domain: string, redirects: Partial<ShlinkDomainRedirects>) => Promise<void>;
|
2021-12-26 15:53:17 +03:00
|
|
|
checkDomainHealth: (domain: string) => void;
|
2021-12-09 15:44:29 +03:00
|
|
|
selectedServer: SelectedServer;
|
2021-08-21 18:53:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const Nr: FC<{ fallback: OptionalString }> = ({ fallback }) => (
|
|
|
|
<span className="text-muted">
|
|
|
|
{!fallback && <small>No redirect</small>}
|
|
|
|
{fallback && <>{fallback} <small>(as fallback)</small></>}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
const DefaultDomain: FC = () => (
|
|
|
|
<>
|
2021-12-07 22:24:59 +03:00
|
|
|
<FontAwesomeIcon fixedWidth icon={defaultDomainIcon} className="text-primary" id="defaultDomainIcon" />
|
2021-08-21 18:53:06 +03:00
|
|
|
<UncontrolledTooltip target="defaultDomainIcon" placement="right">Default domain</UncontrolledTooltip>
|
|
|
|
</>
|
|
|
|
);
|
2021-12-26 15:53:17 +03:00
|
|
|
|
|
|
|
export const DomainRow: FC<DomainRowProps> = (
|
|
|
|
{ domain, editDomainRedirects, checkDomainHealth, defaultRedirects, selectedServer },
|
|
|
|
) => {
|
2021-08-21 18:53:06 +03:00
|
|
|
const [ isOpen, toggle ] = useToggle();
|
2021-12-26 15:53:17 +03:00
|
|
|
const { domain: authority, isDefault, redirects, status } = domain;
|
2021-12-09 15:44:29 +03:00
|
|
|
const canEditDomain = !isDefault || supportsDefaultDomainRedirectsEdition(selectedServer);
|
2021-08-21 18:53:06 +03:00
|
|
|
|
2021-12-26 15:53:17 +03:00
|
|
|
useEffect(() => {
|
|
|
|
checkDomainHealth(domain.domain);
|
|
|
|
}, []);
|
|
|
|
|
2021-08-21 18:53:06 +03:00
|
|
|
return (
|
2021-08-22 11:46:47 +03:00
|
|
|
<tr className="responsive-table__row">
|
2021-12-28 00:27:13 +03:00
|
|
|
<td className="responsive-table__cell" data-th="Is default domain">{isDefault && <DefaultDomain />}</td>
|
2021-08-22 11:46:47 +03:00
|
|
|
<th className="responsive-table__cell" data-th="Domain">{authority}</th>
|
|
|
|
<td className="responsive-table__cell" data-th="Base path redirect">
|
|
|
|
{redirects?.baseUrlRedirect ?? <Nr fallback={defaultRedirects?.baseUrlRedirect} />}
|
|
|
|
</td>
|
|
|
|
<td className="responsive-table__cell" data-th="Regular 404 redirect">
|
|
|
|
{redirects?.regular404Redirect ?? <Nr fallback={defaultRedirects?.regular404Redirect} />}
|
|
|
|
</td>
|
|
|
|
<td className="responsive-table__cell" data-th="Invalid short URL redirect">
|
2021-08-22 10:00:58 +03:00
|
|
|
{redirects?.invalidShortUrlRedirect ?? <Nr fallback={defaultRedirects?.invalidShortUrlRedirect} />}
|
2021-08-21 18:53:06 +03:00
|
|
|
</td>
|
2021-12-26 15:53:17 +03:00
|
|
|
<td className="responsive-table__cell text-lg-center" data-th="Status">
|
2021-12-28 00:27:13 +03:00
|
|
|
<DomainStatusIcon status={status} />
|
2021-12-26 15:53:17 +03:00
|
|
|
</td>
|
2021-08-22 11:46:47 +03:00
|
|
|
<td className="responsive-table__cell text-right">
|
2021-12-09 15:44:29 +03:00
|
|
|
<span id={!canEditDomain ? 'defaultDomainBtn' : undefined}>
|
|
|
|
<Button outline size="sm" disabled={!canEditDomain} onClick={!canEditDomain ? undefined : toggle}>
|
|
|
|
<FontAwesomeIcon fixedWidth icon={!canEditDomain ? forbiddenIcon : editIcon} />
|
2021-08-21 18:53:06 +03:00
|
|
|
</Button>
|
|
|
|
</span>
|
2021-12-09 15:44:29 +03:00
|
|
|
{!canEditDomain && (
|
2021-12-07 22:41:07 +03:00
|
|
|
<UncontrolledTooltip target="defaultDomainBtn" placement="left">
|
2021-08-21 18:53:06 +03:00
|
|
|
Redirects for default domain cannot be edited here.
|
|
|
|
<br />
|
2021-08-22 10:34:56 +03:00
|
|
|
Use config options or env vars directly on the server.
|
2021-08-21 18:53:06 +03:00
|
|
|
</UncontrolledTooltip>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
<EditDomainRedirectsModal
|
|
|
|
domain={domain}
|
|
|
|
isOpen={isOpen}
|
|
|
|
toggle={toggle}
|
|
|
|
editDomainRedirects={editDomainRedirects}
|
|
|
|
/>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
};
|