1
|
|
|
import React, { useEffect } from 'react'; |
2
|
|
|
import PropTypes from 'prop-types'; |
3
|
|
|
import qs from 'qs'; |
4
|
|
|
import { MercureInfoType } from '../mercure/reducers/mercureInfo'; |
5
|
|
|
import { bindToMercureTopic } from '../mercure/helpers'; |
6
|
|
|
import { SettingsType } from '../settings/reducers/settings'; |
7
|
|
|
import { shortUrlVisitsType } from './reducers/shortUrlVisits'; |
8
|
|
|
import ShortUrlVisitsHeader from './ShortUrlVisitsHeader'; |
9
|
|
|
import { shortUrlDetailType } from './reducers/shortUrlDetail'; |
10
|
|
|
|
11
|
1 |
|
const propTypes = { |
12
|
|
|
history: PropTypes.shape({ |
13
|
|
|
goBack: PropTypes.func, |
14
|
|
|
}), |
15
|
|
|
match: PropTypes.shape({ |
16
|
|
|
params: PropTypes.object, |
17
|
|
|
}), |
18
|
|
|
location: PropTypes.shape({ |
19
|
|
|
search: PropTypes.string, |
20
|
|
|
}), |
21
|
|
|
getShortUrlVisits: PropTypes.func, |
22
|
|
|
shortUrlVisits: shortUrlVisitsType, |
23
|
|
|
getShortUrlDetail: PropTypes.func, |
24
|
|
|
shortUrlDetail: shortUrlDetailType, |
25
|
|
|
cancelGetShortUrlVisits: PropTypes.func, |
26
|
|
|
createNewVisit: PropTypes.func, |
27
|
|
|
loadMercureInfo: PropTypes.func, |
28
|
|
|
mercureInfo: MercureInfoType, |
29
|
|
|
settings: SettingsType, |
30
|
|
|
}; |
31
|
|
|
|
32
|
1 |
|
const ShortUrlVisits = (VisitsStats) => { |
33
|
1 |
|
const ShortUrlVisitsComp = ({ |
34
|
|
|
history, |
35
|
|
|
match, |
36
|
|
|
location, |
37
|
|
|
shortUrlVisits, |
38
|
|
|
shortUrlDetail, |
39
|
|
|
getShortUrlVisits, |
40
|
|
|
getShortUrlDetail, |
41
|
|
|
cancelGetShortUrlVisits, |
42
|
|
|
createNewVisit, |
43
|
|
|
loadMercureInfo, |
44
|
|
|
mercureInfo, |
45
|
|
|
settings: { realTimeUpdates }, |
46
|
|
|
}) => { |
47
|
1 |
|
const { params } = match; |
48
|
1 |
|
const { shortCode } = params; |
49
|
1 |
|
const { search } = location; |
50
|
1 |
|
const { domain } = qs.parse(search, { ignoreQueryPrefix: true }); |
51
|
|
|
|
52
|
1 |
|
const loadVisits = (dates) => getShortUrlVisits(shortCode, { ...dates, domain }); |
53
|
|
|
|
54
|
1 |
|
useEffect(() => { |
55
|
|
|
getShortUrlDetail(shortCode, domain); |
56
|
|
|
}, []); |
57
|
1 |
|
useEffect( |
58
|
|
|
bindToMercureTopic( |
59
|
|
|
mercureInfo, |
60
|
|
|
realTimeUpdates, |
61
|
|
|
`https://shlink.io/new-visit/${shortCode}`, |
62
|
|
|
createNewVisit, |
63
|
|
|
loadMercureInfo |
64
|
|
|
), |
65
|
|
|
[ mercureInfo ], |
66
|
|
|
); |
67
|
|
|
|
68
|
1 |
|
return ( |
69
|
|
|
<VisitsStats getVisits={loadVisits} cancelGetVisits={cancelGetShortUrlVisits} visitsInfo={shortUrlVisits}> |
70
|
|
|
<ShortUrlVisitsHeader shortUrlDetail={shortUrlDetail} shortUrlVisits={shortUrlVisits} goBack={history.goBack} /> |
71
|
|
|
</VisitsStats> |
72
|
|
|
); |
73
|
|
|
}; |
74
|
|
|
|
75
|
1 |
|
ShortUrlVisitsComp.propTypes = propTypes; |
76
|
|
|
|
77
|
1 |
|
return ShortUrlVisitsComp; |
78
|
|
|
}; |
79
|
|
|
|
80
|
|
|
export default ShortUrlVisits; |
81
|
|
|
|