2018-09-01 12:08:27 +03:00
|
|
|
import { Card, UncontrolledTooltip } from 'reactstrap';
|
|
|
|
import Moment from 'react-moment';
|
|
|
|
import React from 'react';
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2018-09-08 10:31:44 +03:00
|
|
|
export function VisitsHeader({ shortUrlDetail, shortUrlVisits }) {
|
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-08 10:31:44 +03:00
|
|
|
const shortLink = shortUrl && shortUrl.shortUrl ? shortUrl.shortUrl : '';
|
|
|
|
const longLink = shortUrl && shortUrl.longUrl ? shortUrl.longUrl : '';
|
|
|
|
|
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-08 10:31:44 +03:00
|
|
|
Visit stats for <ExternalLink href={shortLink} />
|
2018-09-01 12:08:27 +03:00
|
|
|
</h2>
|
|
|
|
<hr />
|
2019-01-13 11:49:02 +03:00
|
|
|
<div>Created: {renderDate()}</div>
|
2018-09-01 12:08:27 +03:00
|
|
|
<div>
|
|
|
|
Long URL:
|
|
|
|
|
|
|
|
{loading && <small>Loading...</small>}
|
2018-09-08 10:31:44 +03:00
|
|
|
{!loading && <ExternalLink href={longLink} />}
|
2018-09-01 12:08:27 +03:00
|
|
|
</div>
|
|
|
|
</Card>
|
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
VisitsHeader.propTypes = propTypes;
|