feat: add website overview refresh
This commit is contained in:
parent
440947c9a8
commit
4f4a1cfcef
@ -128,7 +128,7 @@ export function useWorkspaceWebsitePageview(
|
|||||||
startAt: number,
|
startAt: number,
|
||||||
endAt: number
|
endAt: number
|
||||||
) {
|
) {
|
||||||
const { data, isLoading } = useQuery(
|
const { data, isLoading, refetch } = useQuery(
|
||||||
['websitePageview', { workspaceId, websiteId }],
|
['websitePageview', { workspaceId, websiteId }],
|
||||||
() => {
|
() => {
|
||||||
return getWorkspaceWebsitePageview(workspaceId, websiteId, {
|
return getWorkspaceWebsitePageview(workspaceId, websiteId, {
|
||||||
@ -144,5 +144,6 @@ export function useWorkspaceWebsitePageview(
|
|||||||
pageviews: data?.pageviews ?? [],
|
pageviews: data?.pageviews ?? [],
|
||||||
sessions: data?.sessions ?? [],
|
sessions: data?.sessions ?? [],
|
||||||
isLoading,
|
isLoading,
|
||||||
|
refetch,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Button, Tag } from 'antd';
|
import { Button, message, Tag } from 'antd';
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { Column, ColumnConfig } from '@ant-design/charts';
|
import { Column, ColumnConfig } from '@ant-design/charts';
|
||||||
import { ArrowRightOutlined, SyncOutlined } from '@ant-design/icons';
|
import { ArrowRightOutlined, SyncOutlined } from '@ant-design/icons';
|
||||||
@ -17,6 +17,7 @@ import {
|
|||||||
formatDateWithUnit,
|
formatDateWithUnit,
|
||||||
getDateArray,
|
getDateArray,
|
||||||
} from '../utils/date';
|
} from '../utils/date';
|
||||||
|
import { useEvent } from '../hooks/useEvent';
|
||||||
|
|
||||||
interface WebsiteOverviewProps {
|
interface WebsiteOverviewProps {
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
@ -47,13 +48,19 @@ const WebsiteOverviewItem: React.FC<{
|
|||||||
const startDate = dayjs().subtract(1, 'day').add(1, unit).startOf(unit);
|
const startDate = dayjs().subtract(1, 'day').add(1, unit).startOf(unit);
|
||||||
const endDate = dayjs().endOf(unit);
|
const endDate = dayjs().endOf(unit);
|
||||||
|
|
||||||
const { pageviews, sessions, isLoading } = useWorkspaceWebsitePageview(
|
const { pageviews, sessions, isLoading, refetch } =
|
||||||
|
useWorkspaceWebsitePageview(
|
||||||
props.website.workspaceId,
|
props.website.workspaceId,
|
||||||
props.website.id,
|
props.website.id,
|
||||||
startDate.unix() * 1000,
|
startDate.unix() * 1000,
|
||||||
endDate.unix() * 1000
|
endDate.unix() * 1000
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleRefresh = useEvent(async () => {
|
||||||
|
await refetch();
|
||||||
|
message.success('Refreshed');
|
||||||
|
});
|
||||||
|
|
||||||
const chartData = useMemo(() => {
|
const chartData = useMemo(() => {
|
||||||
const pageviewsArr = getDateArray(pageviews, startDate, endDate, unit);
|
const pageviewsArr = getDateArray(pageviews, startDate, endDate, unit);
|
||||||
const sessionsArr = getDateArray(sessions, startDate, endDate, unit);
|
const sessionsArr = getDateArray(sessions, startDate, endDate, unit);
|
||||||
@ -104,7 +111,11 @@ const WebsiteOverviewItem: React.FC<{
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 justify-end w-full lg:w-1/3">
|
<div className="flex items-center gap-2 justify-end w-full lg:w-1/3">
|
||||||
<Button size="large" icon={<SyncOutlined />} />
|
<Button
|
||||||
|
size="large"
|
||||||
|
icon={<SyncOutlined />}
|
||||||
|
onClick={handleRefresh}
|
||||||
|
/>
|
||||||
|
|
||||||
<DateFilter />
|
<DateFilter />
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user