diff --git a/components/WebsiteDetails.js b/components/WebsiteDetails.js
index 3a933638..e3a7e2c2 100644
--- a/components/WebsiteDetails.js
+++ b/components/WebsiteDetails.js
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
+import { useRouter } from 'next/router';
import classNames from 'classnames';
import WebsiteChart from 'components/metrics/WebsiteChart';
import WorldMap from 'components/common/WorldMap';
@@ -19,12 +20,29 @@ import EventsChart from './metrics/EventsChart';
import useFetch from 'hooks/useFetch';
import Loading from 'components/common/Loading';
-export default function WebsiteDetails({ websiteId }) {
- const { data } = useFetch(`/api/website/${websiteId}`);
+const views = {
+ url: PagesTable,
+ referrer: ReferrersTable,
+ browser: BrowsersTable,
+ os: OSTable,
+ device: DevicesTable,
+ country: CountriesTable,
+ event: EventsTable,
+};
+
+export default function WebsiteDetails({ websiteId, token }) {
+ const router = useRouter();
+ const { data } = useFetch(`/api/website/${websiteId}`, { token });
const [chartLoaded, setChartLoaded] = useState(false);
const [countryData, setCountryData] = useState();
const [eventsData, setEventsData] = useState();
- const [expand, setExpand] = useState();
+ const {
+ query: { id, view },
+ basePath,
+ asPath,
+ } = router;
+
+ const path = `${basePath}/${asPath.split('/')[1]}/${id.join('/')}`;
const BackButton = () => (
}
size="xsmall"
- onClick={() => setExpand(null)}
+ onClick={() => router.push(path)}
>
@@ -46,53 +64,43 @@ export default function WebsiteDetails({ websiteId }) {
},
{
label:
,
- value: 'url',
- component: PagesTable,
+ value: `${path}?view=url`,
},
{
label:
,
- value: 'referrer',
- component: ReferrersTable,
+ value: `${path}?view=referrer`,
},
{
label:
,
- value: 'browser',
- component: BrowsersTable,
+ value: `${path}?view=browser`,
},
{
label:
,
- value: 'os',
- component: OSTable,
+ value: `${path}?view=os`,
},
{
label:
,
- value: 'device',
- component: DevicesTable,
+ value: `${path}?view=device`,
},
{
label:
,
- value: 'country',
- component: CountriesTable,
+ value: `${path}?view=country`,
},
{
label:
,
- value: 'event',
- component: EventsTable,
+ value: `${path}?view=event`,
},
];
const tableProps = {
websiteId,
+ token,
websiteDomain: data?.domain,
limit: 10,
onExpand: handleExpand,
};
- const DetailsComponent = expand?.component;
-
- function getSelectedMenuOption(value) {
- return menuOptions.find(e => e.value === value);
- }
+ const DetailsComponent = views[view];
function handleDataLoad() {
if (!chartLoaded) {
@@ -101,11 +109,7 @@ export default function WebsiteDetails({ websiteId }) {
}
function handleExpand(value) {
- setExpand(getSelectedMenuOption(value));
- }
-
- function handleMenuSelect(value) {
- setExpand(getSelectedMenuOption(value));
+ router.push(`${path}?view=${value}`);
}
if (!data) {
@@ -118,6 +122,7 @@ export default function WebsiteDetails({ websiteId }) {
{!chartLoaded &&
}
- {chartLoaded && !expand && (
+ {chartLoaded && !view && (
<>
@@ -162,19 +167,17 @@ export default function WebsiteDetails({ websiteId }) {
-
+
>
)}
- {expand && (
+ {view && (
diff --git a/components/WebsiteDetails.module.css b/components/WebsiteDetails.module.css
index 9e7352a9..4f117ba1 100644
--- a/components/WebsiteDetails.module.css
+++ b/components/WebsiteDetails.module.css
@@ -2,7 +2,7 @@
margin-bottom: 30px;
}
-.expand {
+.view {
border-top: 1px solid var(--gray300);
}
@@ -10,8 +10,8 @@
font-size: var(--font-size-small);
}
-.menu .option {
- font-size: var(--font-size-small);
+.content {
+ min-height: 600px;
}
.backButton {
diff --git a/components/WebsiteList.js b/components/WebsiteList.js
index 051d523a..b1819748 100644
--- a/components/WebsiteList.js
+++ b/components/WebsiteList.js
@@ -11,7 +11,7 @@ import styles from './WebsiteList.module.css';
export default function WebsiteList({ userId }) {
const router = useRouter();
- const { data } = useFetch('/api/websites', { userId });
+ const { data } = useFetch('/api/websites', { user_id: userId });
if (!data) {
return null;
@@ -28,17 +28,14 @@ export default function WebsiteList({ userId }) {
}
>
} size="medium" onClick={() => router.push('/settings')}>
-
+
diff --git a/components/common/Calendar.js b/components/common/Calendar.js
index 9ad1be88..0414ff7f 100644
--- a/components/common/Calendar.js
+++ b/components/common/Calendar.js
@@ -70,34 +70,36 @@ export default function Calendar({ date, minDate, maxDate, onChange }) {
:
} size="small" />
- {!selectMonth && !selectYear && (
-