From cf1ea873e0d3bd1a4392e51f4662ae5f7b8ab221 Mon Sep 17 00:00:00 2001 From: WangDL Date: Sun, 24 May 2026 16:22:47 +0800 Subject: [PATCH] refactor: replace any with proper types in admin page api calls - Add CacheStats, NotificationTemplate, NotificationLog, ReviewCardItem to types/api.ts - Use PaginatedResult for ReviewAdmin pagination - All queryFn now declare explicit Promise return type Co-Authored-By: Claude Opus 4.7 --- src/pages/CacheAdmin.tsx | 3 ++- src/pages/NotificationAdmin.tsx | 7 ++++-- src/pages/ReviewAdmin.tsx | 5 ++-- src/types/api.ts | 42 +++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/pages/CacheAdmin.tsx b/src/pages/CacheAdmin.tsx index c33e83f..10d6b28 100644 --- a/src/pages/CacheAdmin.tsx +++ b/src/pages/CacheAdmin.tsx @@ -2,6 +2,7 @@ import { Card, Button, Statistic, Row, Col, Space, Typography, message } from 'a import { ClearOutlined, ReloadOutlined, DeleteOutlined } from '@ant-design/icons' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { api } from '@/services/http-client' +import type { CacheStats } from '@/types/api' const { Title } = Typography @@ -10,7 +11,7 @@ export default function CacheAdmin() { const { data: stats, isLoading } = useQuery({ queryKey: ['admin', 'cache-stats'], - queryFn: () => api.get('/admin-api/cache/stats'), + queryFn: (): Promise => api.get('/admin-api/cache/stats'), refetchInterval: 10_000, }) diff --git a/src/pages/NotificationAdmin.tsx b/src/pages/NotificationAdmin.tsx index 3369dd9..1bb8a1b 100644 --- a/src/pages/NotificationAdmin.tsx +++ b/src/pages/NotificationAdmin.tsx @@ -3,6 +3,7 @@ import { Card, Table, Button, Modal, Form, Input, Select, Tag, Space, Typography import { PlusOutlined, DeleteOutlined, EditOutlined } from '@ant-design/icons' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { api } from '@/services/http-client' +import type { NotificationTemplate, NotificationLog } from '@/types/api' const { Title } = Typography @@ -18,12 +19,14 @@ export default function NotificationAdmin() { const { data: templates, isLoading } = useQuery({ queryKey: ['admin', 'notification-templates'], - queryFn: () => api.get('/admin-api/notifications/templates').then(d => d ?? []), + queryFn: (): Promise => + api.get('/admin-api/notifications/templates').then((d: NotificationTemplate[]) => d ?? []), }) const { data: sendLogs } = useQuery({ queryKey: ['admin', 'notification-logs'], - queryFn: () => api.get('/admin-api/notifications/send-log?limit=50').then(d => d ?? []), + queryFn: (): Promise => + api.get('/admin-api/notifications/send-log?limit=50').then((d: NotificationLog[]) => d ?? []), }) const saveMutation = useMutation({ diff --git a/src/pages/ReviewAdmin.tsx b/src/pages/ReviewAdmin.tsx index a3b5e80..861435a 100644 --- a/src/pages/ReviewAdmin.tsx +++ b/src/pages/ReviewAdmin.tsx @@ -3,6 +3,7 @@ import { Table, Tag, Space, Input, Select, Typography } from 'antd' import { SearchOutlined } from '@ant-design/icons' import { useQuery } from '@tanstack/react-query' import { api } from '@/services/http-client' +import type { ReviewCardItem, PaginatedResult } from '@/types/api' const { Title } = Typography @@ -16,11 +17,11 @@ export default function ReviewAdmin() { const { data, isLoading } = useQuery({ queryKey: ['admin', 'reviews', search, statusFilter], - queryFn: () => { + queryFn: (): Promise> => { const params = new URLSearchParams() if (search) params.set('search', search) if (statusFilter) params.set('status', statusFilter) - return api.get(`/admin-api/reviews?${params.toString()}`) + return api.get(`/admin-api/reviews?${params.toString()}`) }, refetchInterval: 30_000, }) diff --git a/src/types/api.ts b/src/types/api.ts index 9460d71..59039de 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -12,3 +12,45 @@ export interface PaginationParams { sortBy?: string sortOrder?: 'asc' | 'desc' } + +export interface CacheStats { + hits: number + misses: number + hitRate: number + available: boolean +} + +export interface NotificationTemplate { + id: string + name: string + type: string + title: string + content: string + channel: string + enabled: boolean + createdBy?: string + createdAt: string + updatedAt: string +} + +export interface NotificationLog { + id: string + userId: string + type: string + title: string + readAt: string | null + createdAt: string +} + +export interface ReviewCardItem { + id: string + userId: string + frontText: string + difficulty: string | null + status: string + scheduleState: string | null + intervalDays: number + repetitionCount: number + lapseCount: number + nextReviewAt: string | null +}