2021-04-28 10:52:06 +02:00
|
|
|
import React, { useState } from 'react';
|
2020-09-06 02:27:01 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2020-10-02 02:32:49 +02:00
|
|
|
import Link from 'components/common/Link';
|
2020-08-21 22:43:42 +02:00
|
|
|
import WebsiteChart from 'components/metrics/WebsiteChart';
|
2020-08-12 07:24:41 +02:00
|
|
|
import Page from 'components/layout/Page';
|
|
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
2021-04-28 10:52:06 +02:00
|
|
|
import Button from 'components/common/Button';
|
2020-08-31 00:29:31 +02:00
|
|
|
import useFetch from 'hooks/useFetch';
|
2020-08-04 08:20:35 +02:00
|
|
|
import Arrow from 'assets/arrow-right.svg';
|
2021-04-28 10:52:06 +02:00
|
|
|
import Chart from 'assets/chart-bar.svg';
|
2020-07-30 08:25:52 +02:00
|
|
|
import styles from './WebsiteList.module.css';
|
2020-07-28 10:17:45 +02:00
|
|
|
|
2020-09-11 08:55:29 +02:00
|
|
|
export default function WebsiteList({ userId }) {
|
2020-10-09 21:39:03 +02:00
|
|
|
const { data } = useFetch('/api/websites', { params: { user_id: userId } });
|
2022-01-14 09:04:07 +01:00
|
|
|
const [showCharts, setShowCharts] = useState(true);
|
2020-07-28 10:17:45 +02:00
|
|
|
|
2020-08-11 04:54:03 +02:00
|
|
|
if (!data) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-04-28 10:52:06 +02:00
|
|
|
if (data.length === 0) {
|
|
|
|
return (
|
|
|
|
<Page>
|
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."
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2020-10-02 02:32:49 +02:00
|
|
|
<Link href="/settings" icon={<Arrow />} iconRight>
|
2020-09-26 07:31:18 +02:00
|
|
|
<FormattedMessage id="message.go-to-settings" defaultMessage="Go to settings" />
|
2020-10-02 02:32:49 +02:00
|
|
|
</Link>
|
2020-08-11 04:54:03 +02:00
|
|
|
</EmptyPlaceholder>
|
2021-04-28 10:52:06 +02:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<div className={styles.menubar}>
|
2021-11-19 08:07:12 +01:00
|
|
|
<Button
|
2021-11-21 02:02:24 +01:00
|
|
|
tooltip={<FormattedMessage id="message.toggle-charts" defaultMessage="Toggle charts" />}
|
2021-11-19 08:07:12 +01:00
|
|
|
icon={<Chart />}
|
2022-01-14 09:04:07 +01:00
|
|
|
onClick={() => setShowCharts(!showCharts)}
|
2021-11-19 08:07:12 +01:00
|
|
|
/>
|
2021-04-28 10:52:06 +02:00
|
|
|
</div>
|
|
|
|
{data.map(({ website_id, name, domain }) => (
|
|
|
|
<div key={website_id} className={styles.website}>
|
|
|
|
<WebsiteChart
|
|
|
|
websiteId={website_id}
|
|
|
|
title={name}
|
|
|
|
domain={domain}
|
2022-01-14 09:04:07 +01:00
|
|
|
showChart={showCharts}
|
2021-04-28 10:52:06 +02:00
|
|
|
showLink
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
))}
|
2020-08-06 04:04:02 +02:00
|
|
|
</Page>
|
2020-07-28 10:17:45 +02:00
|
|
|
);
|
|
|
|
}
|