2020-04-18 12:03:49 +03:00
|
|
|
import React, { useRef } from 'react';
|
2020-01-11 21:58:04 +03:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { faInfoCircle as infoIcon } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { UncontrolledTooltip } from 'reactstrap';
|
2020-04-18 11:50:01 +03:00
|
|
|
import classNames from 'classnames';
|
2020-04-18 12:03:49 +03:00
|
|
|
import { prettify } from '../../utils/helpers/numbers';
|
2020-08-30 10:59:14 +03:00
|
|
|
import VisitStatsLink, { VisitStatsLinkProps } from './VisitStatsLink';
|
2020-04-18 11:50:01 +03:00
|
|
|
import './ShortUrlVisitsCount.scss';
|
2020-01-11 21:58:04 +03:00
|
|
|
|
2020-08-30 10:59:14 +03:00
|
|
|
export interface ShortUrlVisitsCount extends VisitStatsLinkProps {
|
|
|
|
visitsCount: number;
|
|
|
|
active?: boolean;
|
|
|
|
}
|
2020-01-11 21:58:04 +03:00
|
|
|
|
2020-08-30 10:59:14 +03:00
|
|
|
const ShortUrlVisitsCount = ({ visitsCount, shortUrl, selectedServer, active = false }: ShortUrlVisitsCount) => {
|
|
|
|
const maxVisits = shortUrl?.meta?.maxVisits;
|
2020-02-08 11:07:55 +03:00
|
|
|
const visitsLink = (
|
|
|
|
<VisitStatsLink selectedServer={selectedServer} shortUrl={shortUrl}>
|
2020-04-18 11:50:01 +03:00
|
|
|
<strong
|
|
|
|
className={classNames('short-url-visits-count__amount', { 'short-url-visits-count__amount--big': active })}
|
|
|
|
>
|
2020-04-18 12:03:49 +03:00
|
|
|
{prettify(visitsCount)}
|
2020-04-18 11:50:01 +03:00
|
|
|
</strong>
|
2020-02-08 11:07:55 +03:00
|
|
|
</VisitStatsLink>
|
|
|
|
);
|
2020-01-11 21:58:04 +03:00
|
|
|
|
|
|
|
if (!maxVisits) {
|
2020-02-08 11:07:55 +03:00
|
|
|
return visitsLink;
|
2020-01-11 21:58:04 +03:00
|
|
|
}
|
|
|
|
|
2020-04-18 12:03:49 +03:00
|
|
|
const prettifiedMaxVisits = prettify(maxVisits);
|
2020-08-30 10:59:14 +03:00
|
|
|
const tooltipRef = useRef<HTMLElement | null>();
|
2020-04-18 12:03:49 +03:00
|
|
|
|
2020-01-11 21:58:04 +03:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-01-12 14:08:26 +03:00
|
|
|
<span className="indivisible">
|
2020-02-08 11:07:55 +03:00
|
|
|
{visitsLink}
|
2020-04-18 12:03:49 +03:00
|
|
|
<small
|
|
|
|
className="short-urls-visits-count__max-visits-control"
|
|
|
|
ref={(el) => {
|
|
|
|
tooltipRef.current = el;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{' '}/ {prettifiedMaxVisits}{' '}
|
2020-01-11 21:58:04 +03:00
|
|
|
<sup>
|
|
|
|
<FontAwesomeIcon icon={infoIcon} />
|
|
|
|
</sup>
|
|
|
|
</small>
|
|
|
|
</span>
|
2020-08-30 10:59:14 +03:00
|
|
|
<UncontrolledTooltip target={(() => tooltipRef.current) as any} placement="bottom">
|
2020-04-18 12:03:49 +03:00
|
|
|
This short URL will not accept more than <b>{prettifiedMaxVisits}</b> visits.
|
2020-01-11 21:58:04 +03:00
|
|
|
</UncontrolledTooltip>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShortUrlVisitsCount;
|