import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import WebsiteChart from 'components/metrics/WebsiteChart'; import WorldMap from 'components/common/WorldMap'; import Page from 'components/layout/Page'; import MenuLayout from 'components/layout/MenuLayout'; import Link from 'components/common/Link'; import Loading from 'components/common/Loading'; import Arrow from 'assets/arrow-right.svg'; import styles from './WebsiteDetails.module.css'; import PagesTable from './metrics/PagesTable'; import ReferrersTable from './metrics/ReferrersTable'; import BrowsersTable from './metrics/BrowsersTable'; import OSTable from './metrics/OSTable'; import DevicesTable from './metrics/DevicesTable'; import CountriesTable from './metrics/CountriesTable'; import EventsTable from './metrics/EventsTable'; import EventsChart from './metrics/EventsChart'; import useFetch from 'hooks/useFetch'; import usePageQuery from 'hooks/usePageQuery'; const views = { url: PagesTable, referrer: ReferrersTable, browser: BrowsersTable, os: OSTable, device: DevicesTable, country: CountriesTable, event: EventsTable, }; export default function WebsiteDetails({ websiteId, token }) { const { data } = useFetch(`/api/website/${websiteId}`, { token }); const [chartLoaded, setChartLoaded] = useState(false); const [countryData, setCountryData] = useState(); const [eventsData, setEventsData] = useState(); const { resolve, router, query: { view }, } = usePageQuery(); const BackButton = () => ( } size="small" > ); const menuOptions = [ { render: BackButton, }, { label: , value: resolve({ view: 'url' }), }, { label: , value: resolve({ view: 'referrer' }), }, { label: , value: resolve({ view: 'browser' }), }, { label: , value: resolve({ view: 'os' }), }, { label: , value: resolve({ view: 'device' }), }, { label: , value: resolve({ view: 'country' }), }, { label: , value: resolve({ view: 'event' }), }, ]; const tableProps = { websiteId, token, websiteDomain: data?.domain, limit: 10, }; const DetailsComponent = views[view]; function handleDataLoad() { if (!chartLoaded) { setTimeout(() => setChartLoaded(true), 300); } } if (!data) { return null; } return (
{!chartLoaded && } {chartLoaded && !view && ( <>
0 })} >
)} {view && ( )}
); }