umami/components/WebsiteList.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

import React, { useState, useEffect } from 'react';
2020-08-07 09:24:01 +02:00
import { useRouter } from 'next/router';
import WebsiteHeader from 'components/metrics/WebsiteHeader';
import WebsiteChart from 'components/metrics/WebsiteChart';
2020-08-12 07:24:41 +02:00
import Page from 'components/layout/Page';
import Button from 'components/common/Button';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
import Arrow from 'assets/arrow-right.svg';
2020-08-12 07:24:41 +02:00
import { get } from 'lib/web';
2020-07-30 08:25:52 +02:00
import styles from './WebsiteList.module.css';
export default function WebsiteList() {
const [data, setData] = useState();
2020-08-07 09:24:01 +02:00
const router = useRouter();
async function loadData() {
2020-08-12 07:24:41 +02:00
setData(await get(`/api/websites`));
}
useEffect(() => {
loadData();
}, []);
if (!data) {
return null;
}
return (
2020-08-06 04:04:02 +02:00
<Page>
2020-08-07 11:27:12 +02:00
{data?.map(({ website_id, name }) => (
<div key={website_id} className={styles.website}>
2020-08-18 09:51:32 +02:00
<WebsiteHeader websiteId={website_id} name={name} showLink />
2020-08-07 11:27:12 +02:00
<WebsiteChart key={website_id} title={name} websiteId={website_id} />
</div>
))}
{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 04:04:02 +02:00
</Page>
);
}