shlink-web-client/src/shlink-web-component/visits/NonOrphanVisits.tsx

41 lines
1.6 KiB
TypeScript
Raw Normal View History

import type { ReportExporter } from '../../common/services/ReportExporter';
import { useGoBack } from '../../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 { LoadVisits, VisitsInfo } from './reducers/types';
2023-02-18 12:40:37 +03:00
import type { NormalizedVisit, VisitsParams } from './types';
import type { CommonVisitsProps } from './types/CommonVisitsProps';
import { toApiParams } from './types/helpers';
import { VisitsHeader } from './VisitsHeader';
2023-02-18 13:11:01 +03:00
import { VisitsStats } from './VisitsStats';
2022-02-06 22:07:18 +03:00
export interface NonOrphanVisitsProps extends CommonVisitsProps {
getNonOrphanVisits: (params: LoadVisits) => void;
nonOrphanVisits: VisitsInfo;
cancelGetNonOrphanVisits: () => void;
}
2022-03-13 20:56:42 +03:00
export const NonOrphanVisits = ({ exportVisits }: ReportExporter) => boundToMercureHub(({
getNonOrphanVisits,
nonOrphanVisits,
cancelGetNonOrphanVisits,
settings,
}: NonOrphanVisitsProps) => {
2022-02-06 22:07:18 +03:00
const goBack = useGoBack();
const exportCsv = (visits: NormalizedVisit[]) => exportVisits('non_orphan_visits.csv', visits);
const loadVisits = (params: VisitsParams, doIntervalFallback?: boolean) =>
getNonOrphanVisits({ query: toApiParams(params), doIntervalFallback });
return (
<VisitsStats
getVisits={loadVisits}
cancelGetVisits={cancelGetNonOrphanVisits}
visitsInfo={nonOrphanVisits}
settings={settings}
exportCsv={exportCsv}
>
<VisitsHeader title="Non-orphan visits" goBack={goBack} visits={nonOrphanVisits.visits} />
</VisitsStats>
);
2022-03-26 14:17:42 +03:00
}, () => [Topics.visits]);