2018-09-01 12:08:27 +03:00
|
|
|
import { Card, UncontrolledTooltip } from 'reactstrap';
|
|
|
|
import Moment from 'react-moment';
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ExternalLink from '../utils/ExternalLink';
|
|
|
|
import './VisitsHeader.scss';
|
2018-09-01 12:26:35 +03:00
|
|
|
import { shortUrlDetailType } from './reducers/shortUrlDetail';
|
2018-09-05 21:17:46 +03:00
|
|
|
import { shortUrlVisitsType } from './reducers/shortUrlVisits';
|
2018-09-01 12:08:27 +03:00
|
|
|
|
|
|
|
const propTypes = {
|
2018-09-05 21:17:46 +03:00
|
|
|
shortUrlDetail: shortUrlDetailType.isRequired,
|
|
|
|
shortUrlVisits: shortUrlVisitsType.isRequired,
|
2018-09-01 12:08:27 +03:00
|
|
|
shortLink: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
2018-09-05 21:17:46 +03:00
|
|
|
export function VisitsHeader({ shortUrlDetail, shortUrlVisits, shortLink }) {
|
2018-09-01 12:26:35 +03:00
|
|
|
const { shortUrl, loading } = shortUrlDetail;
|
2018-09-05 21:17:46 +03:00
|
|
|
const { visits } = shortUrlVisits;
|
2018-09-01 12:08:27 +03:00
|
|
|
const renderDate = () => (
|
|
|
|
<span>
|
|
|
|
<b id="created" className="visits-header__created-at"><Moment fromNow>{shortUrl.dateCreated}</Moment></b>
|
|
|
|
<UncontrolledTooltip placement="bottom" target="created">
|
|
|
|
<Moment format="YYYY-MM-DD HH:mm">{shortUrl.dateCreated}</Moment>
|
|
|
|
</UncontrolledTooltip>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<header>
|
|
|
|
<Card className="bg-light" body>
|
|
|
|
<h2>
|
2018-09-05 21:17:46 +03:00
|
|
|
<span className="badge badge-main float-right">Visits: {visits.length}</span>
|
2018-09-01 12:08:27 +03:00
|
|
|
Visit stats for <ExternalLink href={shortLink}>{shortLink}</ExternalLink>
|
|
|
|
</h2>
|
|
|
|
<hr />
|
|
|
|
{shortUrl.dateCreated && (
|
|
|
|
<div>
|
|
|
|
Created:
|
|
|
|
|
2018-09-05 21:17:46 +03:00
|
|
|
{renderDate()}
|
2018-09-01 12:08:27 +03:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div>
|
|
|
|
Long URL:
|
|
|
|
|
|
|
|
{loading && <small>Loading...</small>}
|
|
|
|
{!loading && <ExternalLink href={shortUrl.longUrl}>{shortUrl.longUrl}</ExternalLink>}
|
|
|
|
</div>
|
|
|
|
</Card>
|
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
VisitsHeader.propTypes = propTypes;
|