umami/src/app/(main)/dashboard/DashboardPage.tsx

72 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-09-29 12:29:22 +00:00
'use client';
2024-02-05 02:03:26 +00:00
import { Icon, Icons, Loading, Text } from 'react-basics';
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';
2024-01-29 22:47:52 +00:00
import WebsiteChartList from '../websites/[websiteId]/WebsiteChartList';
2023-10-03 23:05:17 +00:00
import DashboardSettingsButton from 'app/(main)/dashboard/DashboardSettingsButton';
import DashboardEdit from 'app/(main)/dashboard/DashboardEdit';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
2024-02-05 02:03:26 +00:00
import { useMessages, useLocale, useTeamUrl, useWebsites } from 'components/hooks';
2022-08-04 10:56:30 +00:00
import useDashboard from 'store/dashboard';
2024-02-05 02:03:26 +00:00
import LinkButton from 'components/common/LinkButton';
2022-03-04 03:45:49 +00:00
2024-02-06 07:59:33 +00:00
export function DashboardPage() {
2023-03-22 21:05:55 +00:00
const { formatMessage, labels, messages } = useMessages();
2024-02-05 02:03:26 +00:00
const { teamId, renderTeamUrl } = useTeamUrl();
2023-08-30 22:23:08 +00:00
const { showCharts, editing } = useDashboard();
const { dir } = useLocale();
const pageSize = 10;
2023-12-03 11:07:03 +00:00
2024-02-04 07:19:29 +00:00
const { result, query, params, setParams } = useWebsites({ teamId }, { pageSize });
2024-02-03 05:06:55 +00:00
const { page } = params;
2024-02-04 07:19:29 +00:00
const hasData = !!result?.data?.length;
2023-12-03 11:07:03 +00:00
const handlePageChange = (page: number) => {
setParams({ ...params, page });
};
if (query.isLoading) {
2023-12-06 03:22:14 +00:00
return <Loading />;
2023-09-29 12:29:22 +00:00
}
2022-03-04 03:45:49 +00:00
return (
2024-02-03 05:06:55 +00:00
<section style={{ marginBottom: 60 }}>
<PageHeader title={formatMessage(labels.dashboard)}>
{!editing && hasData && <DashboardSettingsButton />}
2022-03-04 03:45:49 +00:00
</PageHeader>
{!hasData && (
2023-04-10 03:22:28 +00:00
<EmptyPlaceholder message={formatMessage(messages.noWebsitesConfigured)}>
<LinkButton href={renderTeamUrl('/settings')}>
2024-02-05 02:03:26 +00:00
<Icon rotate={dir === 'rtl' ? 180 : 0}>
<Icons.ArrowRight />
</Icon>
<Text>{formatMessage(messages.goToSettings)}</Text>
</LinkButton>
</EmptyPlaceholder>
)}
{hasData && (
<>
2024-02-03 05:06:55 +00:00
{editing && <DashboardEdit teamId={teamId} />}
2023-08-10 20:26:33 +00:00
{!editing && (
2023-08-30 22:23:08 +00:00
<>
2024-02-03 05:06:55 +00:00
<WebsiteChartList
websites={result?.data as any}
showCharts={showCharts}
limit={pageSize}
/>
2023-08-30 22:23:08 +00:00
<Pager
page={page}
pageSize={pageSize}
2024-02-03 05:06:55 +00:00
count={result?.count}
2023-08-30 22:23:08 +00:00
onPageChange={handlePageChange}
/>
</>
)}
</>
2022-03-04 03:45:49 +00:00
)}
2024-02-03 05:06:55 +00:00
</section>
2022-03-04 03:45:49 +00:00
);
}
2023-04-21 15:00:42 +00:00
2024-02-06 07:59:33 +00:00
export default DashboardPage;