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 GridLayout, { GridRow, GridColumn } from 'components/layout/GridLayout'; 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 PagesTable from 'components/metrics/PagesTable'; import ReferrersTable from 'components/metrics/ReferrersTable'; import BrowsersTable from 'components/metrics/BrowsersTable'; import OSTable from 'components/metrics/OSTable'; import DevicesTable from 'components/metrics/DevicesTable'; import CountriesTable from 'components/metrics/CountriesTable'; import LanguagesTable from 'components/metrics/LanguagesTable'; import EventsTable from 'components/metrics/EventsTable'; import EventsChart from 'components/metrics/EventsChart'; import useFetch from 'hooks/useFetch'; import usePageQuery from 'hooks/usePageQuery'; import { DEFAULT_ANIMATION_DURATION } from 'lib/constants'; import styles from './WebsiteDetails.module.css'; import ScreenTable from 'components/metrics/ScreenTable'; import UTMTable from 'components/metrics/UTMTable'; const views = { url: PagesTable, referrer: ReferrersTable, browser: BrowsersTable, os: OSTable, device: DevicesTable, screen: ScreenTable, country: CountriesTable, language: LanguagesTable, event: EventsTable, utm: UTMTable, }; export default function WebsiteDetails({ websiteId }) { const { data } = useFetch(`/website/${websiteId}`); const [chartLoaded, setChartLoaded] = useState(false); const [countryData, setCountryData] = useState(); const [eventsData, setEventsData] = useState(); const { resolve, 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: 'screen' }), }, { label: , value: resolve({ view: 'browser' }), }, { label: , value: resolve({ view: 'os' }), }, { label: , value: resolve({ view: 'device' }), }, { label: , value: resolve({ view: 'country' }), }, { label: , value: resolve({ view: 'language' }), }, { label: , value: resolve({ view: 'event' }), }, { label: , value: resolve({ view: 'utm' }), }, ]; const tableProps = { websiteId, websiteDomain: data?.domain, limit: 10, }; const DetailsComponent = views[view]; function handleDataLoad() { if (!chartLoaded) { setTimeout(() => setChartLoaded(true), DEFAULT_ANIMATION_DURATION); } } if (!data) { return null; } return (
{!chartLoaded && }
{chartLoaded && !view && ( 0 })}> )} {view && chartLoaded && ( )}
); }