perf: 支持删除关卡
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Header } from '@/components/layout/header'
|
||||
@@ -20,6 +20,7 @@ export default function WxUsersPage() {
|
||||
const [search, setSearch] = useState('')
|
||||
const [selectedUser, setSelectedUser] = useState<WxUser | null>(null)
|
||||
const [isDialogOpen, setIsDialogOpen] = useState(false)
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const { data, isLoading, error } = useQuery<UsersResponse>({
|
||||
queryKey: ['wx-users', search],
|
||||
@@ -52,6 +53,10 @@ export default function WxUsersPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeleted = () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['wx-users'] })
|
||||
}
|
||||
|
||||
const formatDate = (date: Date | string) => {
|
||||
return new Date(date).toLocaleDateString('zh-CN', {
|
||||
year: 'numeric',
|
||||
@@ -189,6 +194,7 @@ export default function WxUsersPage() {
|
||||
open={isDialogOpen}
|
||||
onOpenChange={handleDialogOpenChange}
|
||||
user={userDetails}
|
||||
onDeleted={handleDeleted}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
45
app/api/wx-users/level-progress/route.ts
Normal file
45
app/api/wx-users/level-progress/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { auth } from '@/lib/auth'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
// DELETE /api/wx-users/level-progress - Batch delete level progress
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
) {
|
||||
try {
|
||||
const session = await auth.api.getSession({
|
||||
headers: request.headers,
|
||||
})
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const { ids } = await request.json()
|
||||
|
||||
if (!Array.isArray(ids) || ids.length === 0 || !ids.every((id) => typeof id === 'string')) {
|
||||
return NextResponse.json(
|
||||
{ error: 'ids must be a non-empty array of strings' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
const result = await prisma.wxUserLevelProgress.deleteMany({
|
||||
where: {
|
||||
id: {
|
||||
in: ids,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json({ deleted: result.count })
|
||||
} catch (error) {
|
||||
console.error('Error deleting level progress:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to delete level progress' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user