Восстановлен потерянный код: календари, мониторинг, refresh, stats на list-страницах.

This commit is contained in:
2026-07-07 22:59:19 +03:00
parent 01ce33f322
commit 3a9ee13999
25 changed files with 977 additions and 80 deletions
+55
View File
@@ -0,0 +1,55 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { calendarsApi } from '../api/calendarsApi';
import { Calendar, CalendarListParams } from '../types/api';
import { message } from 'antd';
import { normalizeData } from '../utils/normalize';
export const useCalendars = (params: CalendarListParams) => {
return useQuery({
queryKey: ['calendars', params],
queryFn: async () => {
const res = await calendarsApi.getCalendars(params);
return { data: normalizeData(res.data), total: res.total };
},
});
};
export const useCalendar = (id: string) => {
return useQuery({
queryKey: ['calendars', id],
queryFn: () => calendarsApi.getCalendar(id),
enabled: !!id && id !== '-',
});
};
export const useUpdateCalendar = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, data }: { id: string; data: Partial<Calendar> }) =>
calendarsApi.updateCalendar(id, data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['calendars'] });
message.success('Календарь обновлён');
},
onError: () => message.error('Ошибка обновления'),
});
};
export const useDeleteCalendar = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (id: string) => calendarsApi.deleteCalendar(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['calendars'] });
message.success('Календарь удалён');
},
onError: () => message.error('Ошибка удаления'),
});
};
export const useCalendarStats = () => {
return useQuery({
queryKey: ['calendar-stats'],
queryFn: async () => normalizeData(await calendarsApi.getCalendarStats()),
});
};
+7
View File
@@ -45,4 +45,11 @@ export const useDeleteEvent = () => {
},
onError: () => message.error('Ошибка удаления'),
});
};
export const useEventStats = () => {
return useQuery({
queryKey: ['event-stats'],
queryFn: async () => normalizeData(await eventsApi.getEventStats()),
});
};
+7
View File
@@ -33,4 +33,11 @@ export const useUpdateReport = () => {
},
onError: () => message.error('Ошибка обновления'),
});
};
export const useReportStats = () => {
return useQuery({
queryKey: ['report-stats'],
queryFn: async () => normalizeData(await reportsApi.getReportStats()),
});
};
+7
View File
@@ -51,4 +51,11 @@ export const useBulkUpdateReviews = () => {
console.error(error);
},
});
};
export const useReviewStats = () => {
return useQuery({
queryKey: ['review-stats'],
queryFn: async () => normalizeData(await reviewsApi.getReviewStats()),
});
};
+7
View File
@@ -45,4 +45,11 @@ export const useDeleteSubscription = () => {
},
onError: () => message.error('Ошибка удаления'),
});
};
export const useSubscriptionStats = () => {
return useQuery({
queryKey: ['subscription-stats'],
queryFn: async () => normalizeData(await subscriptionsApi.getSubscriptionStats()),
});
};
+7
View File
@@ -44,4 +44,11 @@ export const useDeleteUser = () => {
},
onError: () => message.error('Ошибка удаления'),
});
};
export const useUserStats = () => {
return useQuery({
queryKey: ['user-stats'],
queryFn: async () => normalizeData(await usersApi.getUserStats()),
});
};