shlink-web-client/src/visits/VisitsHeader.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

import { Card, UncontrolledTooltip } from 'reactstrap';
import Moment from 'react-moment';
import React from 'react';
import ExternalLink from '../utils/ExternalLink';
import './VisitsHeader.scss';
import { shortUrlDetailType } from './reducers/shortUrlDetail';
2018-09-05 21:17:46 +03:00
import { shortUrlVisitsType } from './reducers/shortUrlVisits';
const propTypes = {
2018-09-05 21:17:46 +03:00
shortUrlDetail: shortUrlDetailType.isRequired,
shortUrlVisits: shortUrlVisitsType.isRequired,
};
2018-09-08 10:31:44 +03:00
export function VisitsHeader({ shortUrlDetail, shortUrlVisits }) {
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 : '';
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} />
</h2>
<hr />
2019-01-13 11:49:02 +03:00
<div>Created: {renderDate()}</div>
<div>
Long URL:
&nbsp;
{loading && <small>Loading...</small>}
2018-09-08 10:31:44 +03:00
{!loading && <ExternalLink href={longLink} />}
</div>
</Card>
</header>
);
}
VisitsHeader.propTypes = propTypes;