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

55 lines
1.7 KiB
JavaScript
Raw Normal View History

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';
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,
shortLink: PropTypes.string,
};
2018-09-05 21:17:46 +03:00
export function VisitsHeader({ shortUrlDetail, shortUrlVisits, shortLink }) {
const { shortUrl, loading } = shortUrlDetail;
2018-09-05 21:17:46 +03:00
const { visits } = shortUrlVisits;
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>
Visit stats for <ExternalLink href={shortLink}>{shortLink}</ExternalLink>
</h2>
<hr />
{shortUrl.dateCreated && (
<div>
Created:
&nbsp;
2018-09-05 21:17:46 +03:00
{renderDate()}
</div>
)}
<div>
Long URL:
&nbsp;
{loading && <small>Loading...</small>}
{!loading && <ExternalLink href={shortUrl.longUrl}>{shortUrl.longUrl}</ExternalLink>}
</div>
</Card>
</header>
);
}
VisitsHeader.propTypes = propTypes;