umami/components/pages/WebsiteList.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

import React from 'react';
2020-09-06 02:27:01 +02:00
import { FormattedMessage } from 'react-intl';
2020-08-07 09:24:01 +02:00
import { useRouter } from 'next/router';
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 useFetch from 'hooks/useFetch';
import Arrow from 'assets/arrow-right.svg';
2020-07-30 08:25:52 +02:00
import styles from './WebsiteList.module.css';
2020-09-11 08:55:29 +02:00
export default function WebsiteList({ userId }) {
2020-08-07 09:24:01 +02:00
const router = useRouter();
const { data } = useFetch('/api/websites', { user_id: userId });
if (!data) {
return null;
}
return (
2020-08-06 04:04:02 +02:00
<Page>
{data.map(({ website_id, name }) => (
2020-08-07 11:27:12 +02:00
<div key={website_id} className={styles.website}>
2020-08-31 23:11:30 +02:00
<WebsiteChart websiteId={website_id} title={name} showLink />
2020-08-07 11:27:12 +02:00
</div>
))}
{data.length === 0 && (
2020-09-06 02:27:01 +02:00
<EmptyPlaceholder
msg={
<FormattedMessage
2020-09-17 07:29:40 +02:00
id="message.no-websites-configured"
2020-09-06 02:27:01 +02:00
defaultMessage="You don't have any websites configured."
/>
}
>
<Button icon={<Arrow />} size="medium" onClick={() => router.push('/settings')}>
2020-09-26 07:31:18 +02:00
<FormattedMessage id="message.go-to-settings" defaultMessage="Go to settings" />
</Button>
</EmptyPlaceholder>
)}
2020-08-06 04:04:02 +02:00
</Page>
);
}