2022-04-24 19:36:25 +03:00
|
|
|
import { useParams } from 'react-router-dom';
|
2023-07-24 18:30:58 +03:00
|
|
|
import type { ShlinkVisitsParams } from '../api-contract';
|
2023-07-23 11:14:58 +03:00
|
|
|
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
|
|
|
|
import { Topics } from '../mercure/helpers/Topics';
|
2023-07-29 11:43:15 +03:00
|
|
|
import { useGoBack } from '../utils/helpers/hooks';
|
2023-07-27 23:23:46 +03:00
|
|
|
import type { ReportExporter } from '../utils/services/ReportExporter';
|
2023-02-18 13:11:01 +03:00
|
|
|
import type { DomainVisits as DomainVisitsState, LoadDomainVisits } from './reducers/domainVisits';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { NormalizedVisit } from './types';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { toApiParams } from './types/helpers';
|
2022-05-28 12:16:59 +03:00
|
|
|
import { VisitsHeader } from './VisitsHeader';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { VisitsStats } from './VisitsStats';
|
2022-04-24 14:05:33 +03:00
|
|
|
|
2023-07-23 19:30:59 +03:00
|
|
|
export interface DomainVisitsProps {
|
2022-11-12 11:18:37 +03:00
|
|
|
getDomainVisits: (params: LoadDomainVisits) => void;
|
2022-04-24 19:36:25 +03:00
|
|
|
domainVisits: DomainVisitsState;
|
|
|
|
cancelGetDomainVisits: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const DomainVisits = ({ exportVisits }: ReportExporter) => boundToMercureHub(({
|
|
|
|
getDomainVisits,
|
|
|
|
domainVisits,
|
|
|
|
cancelGetDomainVisits,
|
|
|
|
}: DomainVisitsProps) => {
|
|
|
|
const goBack = useGoBack();
|
|
|
|
const { domain = '' } = useParams();
|
|
|
|
const [authority, domainId = authority] = domain.split('_');
|
|
|
|
const loadVisits = (params: ShlinkVisitsParams, doIntervalFallback?: boolean) =>
|
2022-11-12 11:18:37 +03:00
|
|
|
getDomainVisits({ domain: domainId, query: toApiParams(params), doIntervalFallback });
|
2022-04-24 19:36:25 +03:00
|
|
|
const exportCsv = (visits: NormalizedVisit[]) => exportVisits(`domain_${authority}_visits.csv`, visits);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<VisitsStats
|
|
|
|
getVisits={loadVisits}
|
|
|
|
cancelGetVisits={cancelGetDomainVisits}
|
|
|
|
visitsInfo={domainVisits}
|
|
|
|
exportCsv={exportCsv}
|
|
|
|
>
|
|
|
|
<VisitsHeader goBack={goBack} visits={domainVisits.visits} title={`"${authority}" visits`} />
|
|
|
|
</VisitsStats>
|
|
|
|
);
|
|
|
|
}, () => [Topics.visits]);
|