shlink-web-client/shlink-web-component/visits/OrphanVisits.tsx

41 lines
1.5 KiB
TypeScript
Raw Normal View History

import type { ReportExporter } from '../../src/common/services/ReportExporter';
import { useGoBack } from '../../src/utils/helpers/hooks';
import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
import { Topics } from '../mercure/helpers/Topics';
2023-02-18 13:11:01 +03:00
import type { LoadOrphanVisits } from './reducers/orphanVisits';
import type { VisitsInfo } from './reducers/types';
2023-02-18 12:40:37 +03:00
import type { NormalizedVisit, VisitsParams } from './types';
import { toApiParams } from './types/helpers';
import { VisitsHeader } from './VisitsHeader';
2023-02-18 13:11:01 +03:00
import { VisitsStats } from './VisitsStats';
export interface OrphanVisitsProps {
getOrphanVisits: (params: LoadOrphanVisits) => void;
2021-02-28 12:36:56 +03:00
orphanVisits: VisitsInfo;
cancelGetOrphanVisits: () => void;
}
2022-03-13 20:56:42 +03:00
export const OrphanVisits = ({ exportVisits }: ReportExporter) => boundToMercureHub(({
getOrphanVisits,
orphanVisits,
cancelGetOrphanVisits,
2021-03-14 14:49:12 +03:00
}: OrphanVisitsProps) => {
2022-02-06 22:07:18 +03:00
const goBack = useGoBack();
2021-03-14 14:49:12 +03:00
const exportCsv = (visits: NormalizedVisit[]) => exportVisits('orphan_visits.csv', visits);
const loadVisits = (params: VisitsParams, doIntervalFallback?: boolean) => getOrphanVisits(
{ query: toApiParams(params), orphanVisitsType: params.filter?.orphanVisitsType, doIntervalFallback },
);
2021-03-14 14:49:12 +03:00
return (
<VisitsStats
getVisits={loadVisits}
2021-03-14 14:49:12 +03:00
cancelGetVisits={cancelGetOrphanVisits}
visitsInfo={orphanVisits}
exportCsv={exportCsv}
isOrphanVisits
2021-03-14 14:49:12 +03:00
>
<VisitsHeader title="Orphan visits" goBack={goBack} visits={orphanVisits.visits} />
2021-03-14 14:49:12 +03:00
</VisitsStats>
);
2022-03-26 14:17:42 +03:00
}, () => [Topics.orphanVisits]);