'use client'; import { api } from '@/trpc/client'; import { AspectContainer } from '../aspect-container'; import { ReportChartEmpty } from '../common/empty'; import { ReportChartError } from '../common/error'; import { ReportChartLoading } from '../common/loading'; import { useReportChartContext } from '../context'; import { Chart } from './chart'; import CohortTable from './table'; export function ReportRetentionChart() { const { report: { events, range, projectId, startDate, endDate, criteria, interval, }, isLazyLoading, } = useReportChartContext(); const firstEvent = (events[0]?.filters[0]?.value ?? []).map(String); const secondEvent = (events[1]?.filters[0]?.value ?? []).map(String); const isEnabled = firstEvent.length > 0 && secondEvent.length > 0 && !isLazyLoading; const res = api.chart.cohort.useQuery( { firstEvent, secondEvent, projectId, range, startDate, endDate, criteria, interval, }, { keepPreviousData: true, staleTime: 1000 * 60 * 1, enabled: isEnabled, }, ); if (!isEnabled) { return ; } if (isLazyLoading || res.isLoading) { return ; } if (res.isError) { return ; } if (res.data.length === 0) { return ; } return (
); } function Loading() { return ( ); } function Error() { return ( ); } function Empty() { return ( ); } function Disabled() { return ( We need two events to determine the retention rate. ); }