2021-12-26 15:53:17 +03:00
|
|
|
import { FC, useEffect } from 'react';
|
2022-04-24 14:05:33 +03:00
|
|
|
import { UncontrolledTooltip } from 'reactstrap';
|
2021-08-21 18:53:06 +03:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2022-04-24 14:05:33 +03:00
|
|
|
import { faDotCircle as defaultDomainIcon } 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 { OptionalString } from '../utils/utils';
|
2021-12-09 15:44:29 +03:00
|
|
|
import { SelectedServer } from '../servers/data';
|
2021-12-28 00:27:13 +03:00
|
|
|
import { Domain } from './data';
|
|
|
|
import { DomainStatusIcon } from './helpers/DomainStatusIcon';
|
2022-04-24 14:05:33 +03:00
|
|
|
import { DomainDropdown } from './helpers/DomainDropdown';
|
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 },
|
|
|
|
) => {
|
|
|
|
const { domain: authority, isDefault, redirects, status } = domain;
|
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>
|
2022-03-05 15:26:28 +03:00
|
|
|
<td className="responsive-table__cell text-end">
|
2022-04-24 14:05:33 +03:00
|
|
|
<DomainDropdown domain={domain} editDomainRedirects={editDomainRedirects} selectedServer={selectedServer} />
|
2021-08-21 18:53:06 +03:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
};
|