2020-01-11 21:58:04 +03:00
|
|
|
import React from 'react';
|
2020-01-15 20:31:28 +03:00
|
|
|
import PropTypes from 'prop-types';
|
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-02-08 11:07:55 +03:00
|
|
|
import { serverType } from '../../servers/prop-types';
|
|
|
|
import { shortUrlType } from '../reducers/shortUrlsList';
|
2020-01-12 14:08:26 +03:00
|
|
|
import './ShortUrlVisitsCount.scss';
|
2020-02-08 11:07:55 +03:00
|
|
|
import VisitStatsLink from './VisitStatsLink';
|
2020-01-11 21:58:04 +03:00
|
|
|
|
|
|
|
const propTypes = {
|
2020-01-15 20:31:28 +03:00
|
|
|
visitsCount: PropTypes.number.isRequired,
|
2020-02-08 11:07:55 +03:00
|
|
|
shortUrl: shortUrlType,
|
|
|
|
selectedServer: serverType,
|
2020-01-11 21:58:04 +03:00
|
|
|
};
|
|
|
|
|
2020-02-08 11:07:55 +03:00
|
|
|
const ShortUrlVisitsCount = ({ visitsCount, shortUrl, selectedServer }) => {
|
|
|
|
const maxVisits = shortUrl && shortUrl.meta && shortUrl.meta.maxVisits;
|
|
|
|
const visitsLink = (
|
|
|
|
<VisitStatsLink selectedServer={selectedServer} shortUrl={shortUrl}>
|
|
|
|
<strong>{visitsCount}</strong>
|
|
|
|
</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
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-01-12 14:08:26 +03:00
|
|
|
<span className="indivisible">
|
2020-02-08 11:07:55 +03:00
|
|
|
{visitsLink}
|
2020-01-12 14:08:26 +03:00
|
|
|
<small id="maxVisitsControl" className="short-urls-visits-count__max-visits-control">
|
2020-01-11 21:58:04 +03:00
|
|
|
{' '}/ {maxVisits}{' '}
|
|
|
|
<sup>
|
|
|
|
<FontAwesomeIcon icon={infoIcon} />
|
|
|
|
</sup>
|
|
|
|
</small>
|
|
|
|
</span>
|
|
|
|
<UncontrolledTooltip target="maxVisitsControl" placement="bottom">
|
|
|
|
This short URL will not accept more than <b>{maxVisits}</b> visits.
|
|
|
|
</UncontrolledTooltip>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ShortUrlVisitsCount.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default ShortUrlVisitsCount;
|