2020-11-14 00:44:26 +03:00
|
|
|
import { useEffect } from 'react';
|
2020-09-04 20:05:41 +03:00
|
|
|
import { RouteComponentProps } from 'react-router';
|
2020-09-06 20:41:15 +03:00
|
|
|
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
2020-12-22 11:49:13 +03:00
|
|
|
import { ShlinkVisitsParams } from '../api/types';
|
2020-12-20 21:28:09 +03:00
|
|
|
import { parseQuery } from '../utils/helpers/query';
|
2021-02-28 12:12:30 +03:00
|
|
|
import { Topics } from '../mercure/helpers/Topics';
|
2021-03-05 18:04:02 +03:00
|
|
|
import { ShortUrlDetail } from '../short-urls/reducers/shortUrlDetail';
|
2021-03-06 12:56:49 +03:00
|
|
|
import { Settings } from '../settings/reducers/settings';
|
2020-09-04 20:05:41 +03:00
|
|
|
import { ShortUrlVisits as ShortUrlVisitsState } from './reducers/shortUrlVisits';
|
|
|
|
import ShortUrlVisitsHeader from './ShortUrlVisitsHeader';
|
2020-09-05 09:49:18 +03:00
|
|
|
import VisitsStats from './VisitsStats';
|
2020-09-04 20:05:41 +03:00
|
|
|
|
2020-09-06 20:41:15 +03:00
|
|
|
export interface ShortUrlVisitsProps extends RouteComponentProps<{ shortCode: string }> {
|
2020-09-04 20:05:41 +03:00
|
|
|
getShortUrlVisits: (shortCode: string, query?: ShlinkVisitsParams) => void;
|
|
|
|
shortUrlVisits: ShortUrlVisitsState;
|
|
|
|
getShortUrlDetail: Function;
|
|
|
|
shortUrlDetail: ShortUrlDetail;
|
2020-09-05 09:49:18 +03:00
|
|
|
cancelGetShortUrlVisits: () => void;
|
2021-03-06 12:56:49 +03:00
|
|
|
settings: Settings;
|
2020-09-04 20:05:41 +03:00
|
|
|
}
|
|
|
|
|
2020-09-06 20:41:15 +03:00
|
|
|
const ShortUrlVisits = boundToMercureHub(({
|
2020-09-04 20:05:41 +03:00
|
|
|
history: { goBack },
|
2020-12-20 21:28:09 +03:00
|
|
|
match: { params, url },
|
2020-09-04 20:05:41 +03:00
|
|
|
location: { search },
|
|
|
|
shortUrlVisits,
|
|
|
|
shortUrlDetail,
|
|
|
|
getShortUrlVisits,
|
|
|
|
getShortUrlDetail,
|
|
|
|
cancelGetShortUrlVisits,
|
2021-03-06 12:56:49 +03:00
|
|
|
settings,
|
2020-09-04 20:05:41 +03:00
|
|
|
}: ShortUrlVisitsProps) => {
|
|
|
|
const { shortCode } = params;
|
2020-12-20 21:28:09 +03:00
|
|
|
const { domain } = parseQuery<{ domain?: string }>(search);
|
2020-09-05 09:49:18 +03:00
|
|
|
const loadVisits = (params: Partial<ShlinkVisitsParams>) => getShortUrlVisits(shortCode, { ...params, domain });
|
2020-09-04 20:05:41 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
getShortUrlDetail(shortCode, domain);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2020-12-20 21:28:09 +03:00
|
|
|
<VisitsStats
|
|
|
|
getVisits={loadVisits}
|
|
|
|
cancelGetVisits={cancelGetShortUrlVisits}
|
|
|
|
visitsInfo={shortUrlVisits}
|
|
|
|
baseUrl={url}
|
|
|
|
domain={domain}
|
2021-03-06 12:56:49 +03:00
|
|
|
settings={settings}
|
2020-12-20 21:28:09 +03:00
|
|
|
>
|
2020-09-04 20:05:41 +03:00
|
|
|
<ShortUrlVisitsHeader shortUrlDetail={shortUrlDetail} shortUrlVisits={shortUrlVisits} goBack={goBack} />
|
|
|
|
</VisitsStats>
|
|
|
|
);
|
2021-02-28 12:12:30 +03:00
|
|
|
}, ({ match }) => [ Topics.shortUrlVisits(match.params.shortCode) ]);
|
2020-09-04 20:05:41 +03:00
|
|
|
|
|
|
|
export default ShortUrlVisits;
|