umami/components/pages/realtime/RealtimeHome.js

28 lines
953 B
JavaScript
Raw Normal View History

2023-02-15 11:27:18 +01:00
import { useEffect } from 'react';
import { useRouter } from 'next/router';
import Page from 'components/layout/Page';
import PageHeader from 'components/layout/PageHeader';
import useApi from 'hooks/useApi';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
2023-03-22 22:05:55 +01:00
import useMessages from 'hooks/useMessages';
2023-02-15 11:27:18 +01:00
export default function RealtimeHome() {
2023-03-22 22:05:55 +01:00
const { formatMessage, labels, messages } = useMessages();
2023-02-15 11:27:18 +01:00
const { get, useQuery } = useApi();
const router = useRouter();
const { data, isLoading, error } = useQuery(['websites:me'], () => get('/me/websites'));
useEffect(() => {
if (data?.length) {
router.push(`realtime/${data[0].id}`);
}
2023-02-24 11:41:02 +01:00
}, [data, router]);
2023-02-15 11:27:18 +01:00
return (
2023-02-24 11:41:02 +01:00
<Page loading={isLoading || data?.length > 0} error={error}>
2023-02-15 11:27:18 +01:00
<PageHeader title={formatMessage(labels.realtime)} />
{data?.length === 0 && <EmptyPlaceholder message={formatMessage(messages.noWebsites)} />}
</Page>
);
}