shlink-web-client/src/visits/ShortUrlVisits.tsx

51 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-11-14 00:44:26 +03:00
import { useEffect } from 'react';
import { RouteComponentProps } from 'react-router';
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
import { ShlinkVisitsParams } from '../utils/services/types';
2020-12-20 21:28:09 +03:00
import { parseQuery } from '../utils/helpers/query';
import { ShortUrlVisits as ShortUrlVisitsState } from './reducers/shortUrlVisits';
import ShortUrlVisitsHeader from './ShortUrlVisitsHeader';
import { ShortUrlDetail } from './reducers/shortUrlDetail';
2020-09-05 09:49:18 +03:00
import VisitsStats from './VisitsStats';
export interface ShortUrlVisitsProps extends RouteComponentProps<{ shortCode: string }> {
getShortUrlVisits: (shortCode: string, query?: ShlinkVisitsParams) => void;
shortUrlVisits: ShortUrlVisitsState;
getShortUrlDetail: Function;
shortUrlDetail: ShortUrlDetail;
2020-09-05 09:49:18 +03:00
cancelGetShortUrlVisits: () => void;
}
const ShortUrlVisits = boundToMercureHub(({
history: { goBack },
2020-12-20 21:28:09 +03:00
match: { params, url },
location: { search },
shortUrlVisits,
shortUrlDetail,
getShortUrlVisits,
getShortUrlDetail,
cancelGetShortUrlVisits,
}: 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 });
useEffect(() => {
getShortUrlDetail(shortCode, domain);
}, []);
return (
2020-12-20 21:28:09 +03:00
<VisitsStats
getVisits={loadVisits}
cancelGetVisits={cancelGetShortUrlVisits}
visitsInfo={shortUrlVisits}
baseUrl={url}
domain={domain}
>
<ShortUrlVisitsHeader shortUrlDetail={shortUrlDetail} shortUrlVisits={shortUrlVisits} goBack={goBack} />
</VisitsStats>
);
}, ({ match }) => `https://shlink.io/new-visit/${match.params.shortCode}`);
export default ShortUrlVisits;