1
|
|
|
import { UncontrolledTooltip } from 'reactstrap'; |
2
|
|
|
import Moment from 'react-moment'; |
3
|
|
|
import React from 'react'; |
4
|
|
|
import PropTypes from 'prop-types'; |
5
|
|
|
import { ExternalLink } from 'react-external-link'; |
6
|
|
|
import { shortUrlDetailType } from './reducers/shortUrlDetail'; |
7
|
|
|
import { shortUrlVisitsType } from './reducers/shortUrlVisits'; |
8
|
|
|
import VisitsHeader from './VisitsHeader'; |
9
|
|
|
import './ShortUrlVisitsHeader.scss'; |
10
|
|
|
|
11
|
2 |
|
const propTypes = { |
12
|
|
|
shortUrlDetail: shortUrlDetailType.isRequired, |
13
|
|
|
shortUrlVisits: shortUrlVisitsType.isRequired, |
14
|
|
|
goBack: PropTypes.func.isRequired, |
15
|
|
|
}; |
16
|
|
|
|
17
|
2 |
|
const ShortUrlVisitsHeader = ({ shortUrlDetail, shortUrlVisits, goBack }) => { |
18
|
2 |
|
const { shortUrl, loading } = shortUrlDetail; |
19
|
2 |
|
const { visits } = shortUrlVisits; |
20
|
4 |
|
const shortLink = shortUrl && shortUrl.shortUrl ? shortUrl.shortUrl : ''; |
21
|
4 |
|
const longLink = shortUrl && shortUrl.longUrl ? shortUrl.longUrl : ''; |
22
|
|
|
|
23
|
2 |
|
const renderDate = () => ( |
24
|
2 |
|
<span> |
25
|
|
|
<b id="created" className="short-url-visits-header__created-at"> |
26
|
|
|
<Moment fromNow>{shortUrl.dateCreated}</Moment> |
27
|
|
|
</b> |
28
|
|
|
<UncontrolledTooltip placement="bottom" target="created"> |
29
|
|
|
<Moment format="YYYY-MM-DD HH:mm">{shortUrl.dateCreated}</Moment> |
30
|
|
|
</UncontrolledTooltip> |
31
|
|
|
</span> |
32
|
|
|
); |
33
|
|
|
const visitsStatsTitle = ( |
34
|
2 |
|
<React.Fragment> |
35
|
|
|
Visits for <ExternalLink href={shortLink} /> |
36
|
|
|
</React.Fragment> |
37
|
|
|
); |
38
|
|
|
|
39
|
2 |
|
return ( |
40
|
|
|
<VisitsHeader title={visitsStatsTitle} goBack={goBack} visits={visits} shortUrl={shortUrl}> |
41
|
|
|
<hr /> |
42
|
|
|
<div>Created: {renderDate()}</div> |
43
|
|
|
<div> |
44
|
|
|
Long URL:{' '} |
45
|
|
|
{loading && <small>Loading...</small>} |
46
|
|
|
{!loading && <ExternalLink href={longLink} />} |
47
|
|
|
</div> |
48
|
|
|
</VisitsHeader> |
49
|
|
|
); |
50
|
|
|
}; |
51
|
|
|
|
52
|
2 |
|
ShortUrlVisitsHeader.propTypes = propTypes; |
53
|
|
|
|
54
|
|
|
export default ShortUrlVisitsHeader; |
55
|
|
|
|