2020-07-28 08:17:45 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2020-08-07 07:24:01 +00:00
|
|
|
import { useRouter } from 'next/router';
|
2020-08-21 20:43:42 +00:00
|
|
|
import WebsiteHeader from 'components/metrics/WebsiteHeader';
|
|
|
|
|
import WebsiteChart from 'components/metrics/WebsiteChart';
|
2020-08-12 05:24:41 +00:00
|
|
|
import Page from 'components/layout/Page';
|
|
|
|
|
import Button from 'components/common/Button';
|
|
|
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
2020-08-04 06:20:35 +00:00
|
|
|
import Arrow from 'assets/arrow-right.svg';
|
2020-08-12 05:24:41 +00:00
|
|
|
import { get } from 'lib/web';
|
2020-07-30 06:25:52 +00:00
|
|
|
import styles from './WebsiteList.module.css';
|
2020-07-28 08:17:45 +00:00
|
|
|
|
|
|
|
|
export default function WebsiteList() {
|
|
|
|
|
const [data, setData] = useState();
|
2020-08-07 07:24:01 +00:00
|
|
|
const router = useRouter();
|
2020-07-28 08:17:45 +00:00
|
|
|
|
|
|
|
|
async function loadData() {
|
2020-08-12 05:24:41 +00:00
|
|
|
setData(await get(`/api/websites`));
|
2020-07-28 08:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
loadData();
|
|
|
|
|
}, []);
|
|
|
|
|
|
2020-08-11 02:54:03 +00:00
|
|
|
if (!data) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 08:17:45 +00:00
|
|
|
return (
|
2020-08-06 02:04:02 +00:00
|
|
|
<Page>
|
2020-08-07 09:27:12 +00:00
|
|
|
{data?.map(({ website_id, name }) => (
|
|
|
|
|
<div key={website_id} className={styles.website}>
|
2020-08-18 07:51:32 +00:00
|
|
|
<WebsiteHeader websiteId={website_id} name={name} showLink />
|
2020-08-07 09:27:12 +00:00
|
|
|
<WebsiteChart key={website_id} title={name} websiteId={website_id} />
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2020-08-11 02:54:03 +00:00
|
|
|
{data.length === 0 && (
|
|
|
|
|
<EmptyPlaceholder msg={"You don't have any websites configured."}>
|
|
|
|
|
<Button icon={<Arrow />} size="medium" onClick={() => router.push('/settings')}>
|
|
|
|
|
<div>Go to settings</div>
|
|
|
|
|
</Button>
|
|
|
|
|
</EmptyPlaceholder>
|
|
|
|
|
)}
|
2020-08-06 02:04:02 +00:00
|
|
|
</Page>
|
2020-07-28 08:17:45 +00:00
|
|
|
);
|
|
|
|
|
}
|