add more monitoring info
This commit is contained in:
@@ -119,4 +119,35 @@ export async function fetchLastMonitoringCheck() {
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchMonitoringInfo() {
|
||||
const token = await getSessionData('token');
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
version: 1,
|
||||
msg_id: 30027,
|
||||
message_body: {
|
||||
authToken: token
|
||||
}
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const parsed = await response.json();
|
||||
|
||||
if (parsed?.message_body) {
|
||||
return parsed.message_body;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { fetchMonitoringInfo } from '@/app/actions/monitoringActions';
|
||||
|
||||
interface MonitoringCount {
|
||||
day: number;
|
||||
month: number;
|
||||
weekly: number;
|
||||
}
|
||||
|
||||
export const useMonitoringCount = () => {
|
||||
return useQuery({
|
||||
queryKey: ['monitoringCount'],
|
||||
queryFn: () => {
|
||||
return fetchMonitoringInfo()
|
||||
},
|
||||
select: (data: MonitoringCount | null) => {
|
||||
if (!data) {
|
||||
return null
|
||||
}
|
||||
return data;
|
||||
},
|
||||
retry: false
|
||||
});
|
||||
};
|
||||
@@ -4,13 +4,18 @@ import { useTranslations } from 'next-intl';
|
||||
import { useUserFilesInfo } from '@/app/hooks/react-query/useUserFilesInfo';
|
||||
import { IconDocument, IconSearch, IconWarning, IconGraph } from '@/app/ui/icons/icons';
|
||||
import { useViolationStatistic } from '@/app/hooks/react-query/useViolationStatistic';
|
||||
import { useMonitoringStats } from '@/app/hooks/react-query/useMonitoringStats';
|
||||
import { useMonitoringCount } from '@/app/hooks/react-query/useMonitoringCount';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export default function ReportsInfo() {
|
||||
const t = useTranslations("Global");
|
||||
const { data: filesInfo, isLoading, isError, error } = useUserFilesInfo();
|
||||
const { data: violationStatistic } = useViolationStatistic();
|
||||
const { data: monitoringStats } = useMonitoringStats();
|
||||
const { data: monitoringCount } = useMonitoringCount();
|
||||
|
||||
useEffect(() => {
|
||||
console.log(monitoringCount);
|
||||
}, [monitoringCount])
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -42,9 +47,9 @@ export default function ReportsInfo() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-value">
|
||||
{monitoringStats?.total_searches ? monitoringStats?.total_searches : 0}
|
||||
{`${monitoringCount?.day}/${monitoringCount?.weekly}/${monitoringCount?.month}`}
|
||||
</div>
|
||||
<div className="stat-label">{t('monitoring')}</div>
|
||||
<div className="stat-label">{t('monitoring')} {t('every')}: {t('day')}/{t('week')}/{t('month')}</div>
|
||||
</div>
|
||||
|
||||
<div className="stat-card storage" data-icon="">
|
||||
|
||||
Reference in New Issue
Block a user