2023-02-18 13:11:01 +03:00
|
|
|
import { faDotCircle as defaultDomainIcon } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { FC } from 'react';
|
|
|
|
import { useEffect } from 'react';
|
2022-04-24 14:05:33 +03:00
|
|
|
import { UncontrolledTooltip } from 'reactstrap';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ShlinkDomainRedirects } from '../api/types';
|
|
|
|
import type { SelectedServer } from '../servers/data';
|
2023-02-18 13:11:01 +03:00
|
|
|
import type { OptionalString } from '../utils/utils';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { Domain } from './data';
|
2022-04-24 14:05:33 +03:00
|
|
|
import { DomainDropdown } from './helpers/DomainDropdown';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { DomainStatusIcon } from './helpers/DomainStatusIcon';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { EditDomainRedirects } from './reducers/domainRedirects';
|
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;
|
2022-11-04 19:10:02 +03:00
|
|
|
editDomainRedirects: (redirects: EditDomainRedirects) => 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>
|
|
|
|
);
|
|
|
|
};
|