import React, { useMemo } from 'react'; import classNames from 'classnames'; import PageviewsChart from './PageviewsChart'; import MetricsBar from './MetricsBar'; import WebsiteHeader from './WebsiteHeader'; import DateFilter from 'components/common/DateFilter'; import StickyHeader from 'components/helpers/StickyHeader'; import Button from 'components/common/Button'; import useFetch from 'hooks/useFetch'; import useDateRange from 'hooks/useDateRange'; import useTimezone from 'hooks/useTimezone'; import usePageQuery from 'hooks/usePageQuery'; import { getDateArray, getDateLength } from 'lib/date'; import Times from 'assets/times.svg'; import styles from './WebsiteChart.module.css'; import ErrorMessage from '../common/ErrorMessage'; export default function WebsiteChart({ websiteId, token, title, stickyHeader = false, showLink = false, onDataLoad = () => {}, }) { const [dateRange, setDateRange] = useDateRange(websiteId); const { startDate, endDate, unit, value, modified } = dateRange; const [timezone] = useTimezone(); const { router, resolve, query: { url }, } = usePageQuery(); const { data, loading, error } = useFetch( `/api/website/${websiteId}/pageviews`, { params: { start_at: +startDate, end_at: +endDate, unit, tz: timezone, url, token, }, onDataLoad, }, [modified], ); const chartData = useMemo(() => { if (data) { return { pageviews: getDateArray(data.pageviews, startDate, endDate, unit), sessions: getDateArray(data.sessions, startDate, endDate, unit), }; } return { pageviews: [], sessions: [] }; }, [data]); function handleCloseFilter() { router.push(resolve({ url: undefined })); } return (