2020-08-31 00:29:31 +02:00
|
|
|
import React, { useState } from 'react';
|
2020-09-06 02:27:01 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2020-09-17 06:55:32 +02:00
|
|
|
import { useRouter } from 'next/router';
|
2020-08-01 04:05:14 +02:00
|
|
|
import classNames from 'classnames';
|
2020-08-21 22:43:42 +02:00
|
|
|
import WebsiteChart from 'components/metrics/WebsiteChart';
|
2020-08-12 07:24:41 +02:00
|
|
|
import WorldMap from 'components/common/WorldMap';
|
|
|
|
import Page from 'components/layout/Page';
|
|
|
|
import MenuLayout from 'components/layout/MenuLayout';
|
|
|
|
import Button from 'components/common/Button';
|
2020-08-10 00:13:38 +02:00
|
|
|
import Arrow from 'assets/arrow-right.svg';
|
2020-08-01 04:05:14 +02:00
|
|
|
import styles from './WebsiteDetails.module.css';
|
2020-08-23 04:05:07 +02:00
|
|
|
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';
|
2020-08-25 08:49:14 +02:00
|
|
|
import EventsTable from './metrics/EventsTable';
|
2020-08-27 12:42:24 +02:00
|
|
|
import EventsChart from './metrics/EventsChart';
|
2020-08-31 12:53:39 +02:00
|
|
|
import useFetch from 'hooks/useFetch';
|
|
|
|
import Loading from 'components/common/Loading';
|
2020-08-01 04:05:14 +02:00
|
|
|
|
2020-09-17 06:55:32 +02:00
|
|
|
const views = {
|
|
|
|
url: PagesTable,
|
|
|
|
referrer: ReferrersTable,
|
|
|
|
browser: BrowsersTable,
|
|
|
|
os: OSTable,
|
|
|
|
device: DevicesTable,
|
|
|
|
country: CountriesTable,
|
|
|
|
event: EventsTable,
|
|
|
|
};
|
|
|
|
|
2020-08-31 23:11:30 +02:00
|
|
|
export default function WebsiteDetails({ websiteId }) {
|
2020-09-17 06:55:32 +02:00
|
|
|
const router = useRouter();
|
2020-08-31 23:11:30 +02:00
|
|
|
const { data } = useFetch(`/api/website/${websiteId}`);
|
2020-08-04 08:20:35 +02:00
|
|
|
const [chartLoaded, setChartLoaded] = useState(false);
|
2020-08-01 12:34:56 +02:00
|
|
|
const [countryData, setCountryData] = useState();
|
2020-08-28 03:44:20 +02:00
|
|
|
const [eventsData, setEventsData] = useState();
|
2020-09-17 06:55:32 +02:00
|
|
|
const {
|
|
|
|
query: { id, view },
|
|
|
|
} = router;
|
|
|
|
const path = `/website/${id.join('/')}`;
|
|
|
|
|
|
|
|
console.log({ router });
|
2020-08-01 04:05:14 +02:00
|
|
|
|
2020-08-23 04:05:07 +02:00
|
|
|
const BackButton = () => (
|
|
|
|
<Button
|
2020-09-11 08:55:29 +02:00
|
|
|
key="back-button"
|
2020-08-23 04:05:07 +02:00
|
|
|
className={styles.backButton}
|
|
|
|
icon={<Arrow />}
|
|
|
|
size="xsmall"
|
2020-09-17 06:55:32 +02:00
|
|
|
onClick={() => router.push(path)}
|
2020-08-23 04:05:07 +02:00
|
|
|
>
|
2020-09-06 02:27:01 +02:00
|
|
|
<div>
|
|
|
|
<FormattedMessage id="button.back" defaultMessage="Back" />
|
|
|
|
</div>
|
2020-08-23 04:05:07 +02:00
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
|
2020-08-10 00:13:38 +02:00
|
|
|
const menuOptions = [
|
|
|
|
{
|
2020-08-23 04:05:07 +02:00
|
|
|
render: BackButton,
|
2020-08-10 00:13:38 +02:00
|
|
|
},
|
2020-09-08 00:25:09 +02:00
|
|
|
{
|
|
|
|
label: <FormattedMessage id="metrics.pages" defaultMessage="Pages" />,
|
2020-09-17 06:55:32 +02:00
|
|
|
value: `${path}?view=url`,
|
2020-09-08 00:25:09 +02:00
|
|
|
},
|
|
|
|
{
|
2020-09-08 21:13:30 +02:00
|
|
|
label: <FormattedMessage id="metrics.referrers" defaultMessage="Referrers" />,
|
2020-09-17 06:55:32 +02:00
|
|
|
value: `${path}?view=referrer`,
|
2020-09-08 00:25:09 +02:00
|
|
|
},
|
|
|
|
{
|
2020-09-08 21:13:30 +02:00
|
|
|
label: <FormattedMessage id="metrics.browsers" defaultMessage="Browsers" />,
|
2020-09-17 06:55:32 +02:00
|
|
|
value: `${path}?view=browser`,
|
2020-09-08 00:25:09 +02:00
|
|
|
},
|
|
|
|
{
|
2020-09-12 12:22:14 +02:00
|
|
|
label: <FormattedMessage id="metrics.operating-systems" defaultMessage="Operating system" />,
|
2020-09-17 06:55:32 +02:00
|
|
|
value: `${path}?view=os`,
|
2020-09-08 00:25:09 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <FormattedMessage id="metrics.devices" defaultMessage="Devices" />,
|
2020-09-17 06:55:32 +02:00
|
|
|
value: `${path}?view=device`,
|
2020-09-08 00:25:09 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <FormattedMessage id="metrics.countries" defaultMessage="Countries" />,
|
2020-09-17 06:55:32 +02:00
|
|
|
value: `${path}?view=country`,
|
2020-09-08 00:25:09 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <FormattedMessage id="metrics.events" defaultMessage="Events" />,
|
2020-09-17 06:55:32 +02:00
|
|
|
value: `${path}?view=event`,
|
2020-09-08 00:25:09 +02:00
|
|
|
},
|
2020-08-10 00:13:38 +02:00
|
|
|
];
|
|
|
|
|
2020-08-27 12:42:24 +02:00
|
|
|
const tableProps = {
|
2020-08-31 23:11:30 +02:00
|
|
|
websiteId,
|
2020-08-29 06:34:20 +02:00
|
|
|
websiteDomain: data?.domain,
|
2020-08-23 07:01:14 +02:00
|
|
|
limit: 10,
|
|
|
|
onExpand: handleExpand,
|
|
|
|
};
|
|
|
|
|
2020-09-17 06:55:32 +02:00
|
|
|
const DetailsComponent = views[view];
|
2020-08-27 12:42:24 +02:00
|
|
|
|
2020-08-04 08:20:35 +02:00
|
|
|
function handleDataLoad() {
|
2020-08-31 23:11:30 +02:00
|
|
|
if (!chartLoaded) {
|
|
|
|
setTimeout(() => setChartLoaded(true), 300);
|
|
|
|
}
|
2020-08-01 04:05:14 +02:00
|
|
|
}
|
|
|
|
|
2020-08-10 00:13:38 +02:00
|
|
|
function handleExpand(value) {
|
2020-09-17 06:55:32 +02:00
|
|
|
router.push(`${path}?view=${value}`);
|
2020-08-10 00:13:38 +02:00
|
|
|
}
|
|
|
|
|
2020-08-01 04:05:14 +02:00
|
|
|
if (!data) {
|
2020-08-02 08:37:46 +02:00
|
|
|
return null;
|
2020-08-01 04:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-08-06 04:04:02 +02:00
|
|
|
<Page>
|
2020-08-01 04:05:14 +02:00
|
|
|
<div className="row">
|
2020-08-01 06:56:25 +02:00
|
|
|
<div className={classNames(styles.chart, 'col')}>
|
2020-08-04 08:20:35 +02:00
|
|
|
<WebsiteChart
|
2020-08-04 03:12:28 +02:00
|
|
|
websiteId={websiteId}
|
2020-08-31 23:11:30 +02:00
|
|
|
title={data.name}
|
2020-08-04 08:20:35 +02:00
|
|
|
onDataLoad={handleDataLoad}
|
2020-08-31 23:11:30 +02:00
|
|
|
showLink={false}
|
2020-08-04 08:20:35 +02:00
|
|
|
stickyHeader
|
2020-08-04 03:12:28 +02:00
|
|
|
/>
|
2020-08-02 06:20:52 +02:00
|
|
|
</div>
|
2020-08-01 12:34:56 +02:00
|
|
|
</div>
|
2020-08-31 12:53:39 +02:00
|
|
|
{!chartLoaded && <Loading />}
|
2020-09-17 06:55:32 +02:00
|
|
|
{chartLoaded && !view && (
|
2020-08-04 08:20:35 +02:00
|
|
|
<>
|
|
|
|
<div className={classNames(styles.row, 'row')}>
|
2020-08-23 04:05:07 +02:00
|
|
|
<div className="col-md-12 col-lg-6">
|
|
|
|
<PagesTable {...tableProps} />
|
2020-08-04 08:20:35 +02:00
|
|
|
</div>
|
2020-08-23 04:05:07 +02:00
|
|
|
<div className="col-md-12 col-lg-6">
|
|
|
|
<ReferrersTable {...tableProps} />
|
2020-08-04 08:20:35 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={classNames(styles.row, 'row')}>
|
2020-08-23 04:05:07 +02:00
|
|
|
<div className="col-md-12 col-lg-4">
|
|
|
|
<BrowsersTable {...tableProps} />
|
2020-08-04 08:20:35 +02:00
|
|
|
</div>
|
2020-08-23 04:05:07 +02:00
|
|
|
<div className="col-md-12 col-lg-4">
|
|
|
|
<OSTable {...tableProps} />
|
2020-08-04 08:20:35 +02:00
|
|
|
</div>
|
2020-08-23 04:05:07 +02:00
|
|
|
<div className="col-md-12 col-lg-4">
|
|
|
|
<DevicesTable {...tableProps} />
|
2020-08-04 08:20:35 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={classNames(styles.row, 'row')}>
|
|
|
|
<div className="col-12 col-md-12 col-lg-8">
|
|
|
|
<WorldMap data={countryData} />
|
|
|
|
</div>
|
|
|
|
<div className="col-12 col-md-12 col-lg-4">
|
2020-08-28 03:44:20 +02:00
|
|
|
<CountriesTable {...tableProps} onDataLoad={setCountryData} />
|
2020-08-04 08:20:35 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-28 03:44:20 +02:00
|
|
|
<div
|
|
|
|
className={classNames(styles.row, 'row', { [styles.hidden]: !eventsData?.length > 0 })}
|
|
|
|
>
|
2020-08-25 08:49:14 +02:00
|
|
|
<div className="col-12 col-md-12 col-lg-4">
|
2020-08-28 03:44:20 +02:00
|
|
|
<EventsTable {...tableProps} onDataLoad={setEventsData} />
|
2020-08-25 08:49:14 +02:00
|
|
|
</div>
|
2020-08-28 03:44:20 +02:00
|
|
|
<div className="col-12 col-md-12 col-lg-8 pt-5 pb-5">
|
2020-08-31 23:11:30 +02:00
|
|
|
<EventsChart websiteId={websiteId} />
|
2020-08-27 12:42:24 +02:00
|
|
|
</div>
|
2020-08-25 08:49:14 +02:00
|
|
|
</div>
|
2020-08-04 08:20:35 +02:00
|
|
|
</>
|
|
|
|
)}
|
2020-09-17 06:55:32 +02:00
|
|
|
{view && (
|
|
|
|
<MenuLayout className={styles.view} menuClassName={styles.menu} menu={menuOptions}>
|
2020-08-23 07:01:14 +02:00
|
|
|
<DetailsComponent {...tableProps} limit={false} />
|
2020-08-10 00:13:38 +02:00
|
|
|
</MenuLayout>
|
2020-08-09 12:04:48 +02:00
|
|
|
)}
|
2020-08-06 04:04:02 +02:00
|
|
|
</Page>
|
2020-08-01 04:05:14 +02:00
|
|
|
);
|
|
|
|
}
|