2023-09-29 12:29:22 +00:00
|
|
|
'use client';
|
|
|
|
|
import { Button, Icon, Icons, Loading, Text } from 'react-basics';
|
2023-01-28 05:53:13 +00:00
|
|
|
import Link from 'next/link';
|
2022-03-04 03:45:49 +00:00
|
|
|
import PageHeader from 'components/layout/PageHeader';
|
2023-08-30 22:23:08 +00:00
|
|
|
import Pager from 'components/common/Pager';
|
2023-10-03 23:05:17 +00:00
|
|
|
import WebsiteChartList from '../../(main)/websites/[id]/WebsiteChartList';
|
|
|
|
|
import DashboardSettingsButton from 'app/(main)/dashboard/DashboardSettingsButton';
|
|
|
|
|
import DashboardEdit from 'app/(main)/dashboard/DashboardEdit';
|
2023-01-28 05:53:13 +00:00
|
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
2023-08-21 09:06:09 +00:00
|
|
|
import useApi from 'components/hooks/useApi';
|
2022-08-04 10:56:30 +00:00
|
|
|
import useDashboard from 'store/dashboard';
|
2023-08-21 09:06:09 +00:00
|
|
|
import useMessages from 'components/hooks/useMessages';
|
|
|
|
|
import useLocale from 'components/hooks/useLocale';
|
2023-08-30 22:23:08 +00:00
|
|
|
import useApiFilter from 'components/hooks/useApiFilter';
|
2022-03-04 03:45:49 +00:00
|
|
|
|
2023-08-10 20:26:33 +00:00
|
|
|
export function Dashboard() {
|
2023-03-22 21:05:55 +00:00
|
|
|
const { formatMessage, labels, messages } = useMessages();
|
2023-08-30 22:23:08 +00:00
|
|
|
const { showCharts, editing } = useDashboard();
|
|
|
|
|
const { dir } = useLocale();
|
2022-12-28 23:43:22 +00:00
|
|
|
const { get, useQuery } = useApi();
|
2023-08-30 22:23:08 +00:00
|
|
|
const { page, handlePageChange } = useApiFilter();
|
|
|
|
|
const pageSize = 10;
|
2023-09-29 12:29:22 +00:00
|
|
|
const { data: result, isLoading } = useQuery(['websites', page, pageSize], () =>
|
2023-08-30 22:23:08 +00:00
|
|
|
get('/websites', { includeTeams: 1, page, pageSize }),
|
2023-07-27 20:20:22 +00:00
|
|
|
);
|
2023-08-30 22:23:08 +00:00
|
|
|
const { data, count } = result || {};
|
|
|
|
|
const hasData = data && data?.length !== 0;
|
2022-03-04 03:45:49 +00:00
|
|
|
|
2023-09-29 12:29:22 +00:00
|
|
|
if (isLoading) {
|
|
|
|
|
return <Loading size="lg" />;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-04 03:45:49 +00:00
|
|
|
return (
|
2023-09-29 12:29:22 +00:00
|
|
|
<>
|
2023-01-28 05:53:13 +00:00
|
|
|
<PageHeader title={formatMessage(labels.dashboard)}>
|
|
|
|
|
{!editing && hasData && <DashboardSettingsButton />}
|
2022-03-04 03:45:49 +00:00
|
|
|
</PageHeader>
|
2023-01-28 05:53:13 +00:00
|
|
|
{!hasData && (
|
2023-04-10 03:22:28 +00:00
|
|
|
<EmptyPlaceholder message={formatMessage(messages.noWebsitesConfigured)}>
|
2023-01-28 05:53:13 +00:00
|
|
|
<Link href="/settings/websites">
|
|
|
|
|
<Button>
|
2023-04-20 09:41:06 +00:00
|
|
|
<Icon rotate={dir === 'rtl' ? 180 : 0}>
|
2023-01-28 05:53:13 +00:00
|
|
|
<Icons.ArrowRight />
|
|
|
|
|
</Icon>
|
|
|
|
|
<Text>{formatMessage(messages.goToSettings)}</Text>
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</EmptyPlaceholder>
|
|
|
|
|
)}
|
|
|
|
|
{hasData && (
|
|
|
|
|
<>
|
2023-08-30 22:23:08 +00:00
|
|
|
{editing && <DashboardEdit />}
|
2023-08-10 20:26:33 +00:00
|
|
|
{!editing && (
|
2023-08-30 22:23:08 +00:00
|
|
|
<>
|
|
|
|
|
<WebsiteChartList websites={data} showCharts={showCharts} limit={pageSize} />
|
|
|
|
|
<Pager
|
|
|
|
|
page={page}
|
|
|
|
|
pageSize={pageSize}
|
|
|
|
|
count={count}
|
|
|
|
|
onPageChange={handlePageChange}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2023-01-28 05:53:13 +00:00
|
|
|
)}
|
|
|
|
|
</>
|
2022-03-04 03:45:49 +00:00
|
|
|
)}
|
2023-09-29 12:29:22 +00:00
|
|
|
</>
|
2022-03-04 03:45:49 +00:00
|
|
|
);
|
|
|
|
|
}
|
2023-04-21 15:00:42 +00:00
|
|
|
|
|
|
|
|
export default Dashboard;
|