shlink-web-client/src/short-urls/helpers/ShortUrlVisitsCount.tsx

62 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-11-14 00:44:26 +03:00
import { useRef } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faInfoCircle as infoIcon } from '@fortawesome/free-solid-svg-icons';
import { UncontrolledTooltip } from 'reactstrap';
import classNames from 'classnames';
import { prettify } from '../../utils/helpers/numbers';
2021-03-20 18:32:12 +03:00
import { ShortUrl } from '../data';
import { SelectedServer } from '../../servers/data';
import ShortUrlDetailLink from './ShortUrlDetailLink';
import './ShortUrlVisitsCount.scss';
2021-03-20 18:32:12 +03:00
interface ShortUrlVisitsCountProps {
shortUrl?: ShortUrl | null;
selectedServer?: SelectedServer;
visitsCount: number;
active?: boolean;
}
2021-02-28 20:57:27 +03:00
const ShortUrlVisitsCount = ({ visitsCount, shortUrl, selectedServer, active = false }: ShortUrlVisitsCountProps) => {
const maxVisits = shortUrl?.meta?.maxVisits;
const visitsLink = (
2021-03-20 18:32:12 +03:00
<ShortUrlDetailLink selectedServer={selectedServer} shortUrl={shortUrl} suffix="visits">
<strong
className={classNames('short-url-visits-count__amount', { 'short-url-visits-count__amount--big': active })}
>
{prettify(visitsCount)}
</strong>
2021-03-20 18:32:12 +03:00
</ShortUrlDetailLink>
);
if (!maxVisits) {
return visitsLink;
}
const prettifiedMaxVisits = prettify(maxVisits);
const tooltipRef = useRef<HTMLElement | null>();
return (
2020-11-14 00:44:26 +03:00
<>
2020-01-12 14:08:26 +03:00
<span className="indivisible">
{visitsLink}
<small
className="short-urls-visits-count__max-visits-control"
ref={(el) => {
tooltipRef.current = el;
}}
>
{' '}/ {prettifiedMaxVisits}{' '}
<sup>
<FontAwesomeIcon icon={infoIcon} />
</sup>
</small>
</span>
<UncontrolledTooltip target={(() => tooltipRef.current) as any} placement="bottom">
This short URL will not accept more than <b>{prettifiedMaxVisits}</b> visits.
</UncontrolledTooltip>
2020-11-14 00:44:26 +03:00
</>
);
};
2021-02-28 20:57:27 +03:00
export default ShortUrlVisitsCount;