2023-07-10 14:46:45 +02:00
|
|
|
import { Flexbox } from 'react-basics';
|
2023-07-10 13:35:19 +02:00
|
|
|
import EventDataTable from 'components/pages/event-data/EventDataTable';
|
2023-07-10 14:46:45 +02:00
|
|
|
import EventDataValueTable from 'components/pages/event-data/EventDataValueTable';
|
2023-07-10 13:35:19 +02:00
|
|
|
import { EventDataMetricsBar } from 'components/pages/event-data/EventDataMetricsBar';
|
|
|
|
import { useDateRange, useApi, usePageQuery } from 'hooks';
|
2023-07-11 10:16:17 +02:00
|
|
|
import styles from './WebsiteEventData.module.css';
|
2023-07-10 13:35:19 +02:00
|
|
|
|
2023-07-23 22:18:01 +02:00
|
|
|
function useData(websiteId, event) {
|
2023-07-10 13:35:19 +02:00
|
|
|
const [dateRange] = useDateRange(websiteId);
|
|
|
|
const { startDate, endDate } = dateRange;
|
|
|
|
const { get, useQuery } = useApi();
|
|
|
|
const { data, error, isLoading } = useQuery(
|
2023-07-23 22:18:01 +02:00
|
|
|
['event-data:events', { websiteId, startDate, endDate, event }],
|
2023-07-10 13:35:19 +02:00
|
|
|
() =>
|
2023-07-23 22:18:01 +02:00
|
|
|
get('/event-data/events', {
|
2023-07-10 13:35:19 +02:00
|
|
|
websiteId,
|
|
|
|
startAt: +startDate,
|
|
|
|
endAt: +endDate,
|
2023-07-14 17:37:14 +02:00
|
|
|
event,
|
2023-07-10 13:35:19 +02:00
|
|
|
}),
|
|
|
|
{ enabled: !!(websiteId && startDate && endDate) },
|
|
|
|
);
|
|
|
|
|
|
|
|
return { data, error, isLoading };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function WebsiteEventData({ websiteId }) {
|
2023-07-10 14:46:45 +02:00
|
|
|
const {
|
2023-07-23 22:18:01 +02:00
|
|
|
query: { event },
|
2023-07-10 14:46:45 +02:00
|
|
|
} = usePageQuery();
|
2023-07-23 22:18:01 +02:00
|
|
|
const { data } = useData(websiteId, event);
|
2023-07-10 13:35:19 +02:00
|
|
|
|
|
|
|
return (
|
2023-07-11 10:16:17 +02:00
|
|
|
<Flexbox className={styles.container} direction="column" gap={20}>
|
2023-07-10 13:35:19 +02:00
|
|
|
<EventDataMetricsBar websiteId={websiteId} />
|
2023-07-23 22:18:01 +02:00
|
|
|
{!event && <EventDataTable data={data} />}
|
|
|
|
{event && <EventDataValueTable event={event} data={data} />}
|
2023-07-10 14:46:45 +02:00
|
|
|
</Flexbox>
|
2023-07-10 13:35:19 +02:00
|
|
|
);
|
|
|
|
}
|