mirror of
https://github.com/complexcaresolutions/dak.c2s.git
synced 2026-03-17 21:53:41 +00:00
refactor: migrate DisclosuresPage to TanStack Query
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4b4af6b42d
commit
1de2f7274d
2 changed files with 29 additions and 24 deletions
21
frontend/src/hooks/useDisclosures.ts
Normal file
21
frontend/src/hooks/useDisclosures.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { getDisclosureRequests, reviewDisclosure } from '@/services/disclosureService'
|
||||
|
||||
export function useDisclosures(status: string = 'pending') {
|
||||
return useQuery({
|
||||
queryKey: ['disclosures', status],
|
||||
queryFn: () => getDisclosureRequests(status),
|
||||
})
|
||||
}
|
||||
|
||||
export function useReviewDisclosure() {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ id, status }: { id: number; status: 'approved' | 'rejected' }) =>
|
||||
reviewDisclosure(id, status),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['disclosures'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['notifications'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
@ -1,41 +1,23 @@
|
|||
import { useState, useEffect } from 'react'
|
||||
import { Check, X } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import type { DisclosureRequest } from '@/types'
|
||||
import { getDisclosureRequests, reviewDisclosure } from '@/services/disclosureService'
|
||||
import { useDisclosures, useReviewDisclosure } from '@/hooks/useDisclosures'
|
||||
|
||||
export function DisclosuresPage() {
|
||||
const [requests, setRequests] = useState<DisclosureRequest[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const { data: requests = [], isLoading } = useDisclosures('pending')
|
||||
const reviewMutation = useReviewDisclosure()
|
||||
|
||||
const load = () => {
|
||||
setLoading(true)
|
||||
getDisclosureRequests('pending')
|
||||
.then(setRequests)
|
||||
.catch(() => setRequests([]))
|
||||
.finally(() => setLoading(false))
|
||||
}
|
||||
|
||||
useEffect(() => { load() }, [])
|
||||
|
||||
const handleReview = async (id: number, status: 'approved' | 'rejected') => {
|
||||
try {
|
||||
await reviewDisclosure(id, status)
|
||||
load()
|
||||
} catch {
|
||||
// Silently reload on error
|
||||
load()
|
||||
}
|
||||
const handleReview = (id: number, status: 'approved' | 'rejected') => {
|
||||
reviewMutation.mutate({ id, status })
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<h1 className="text-2xl font-bold">Freigabe-Anfragen</h1>
|
||||
|
||||
{loading ? (
|
||||
{isLoading ? (
|
||||
<div className="space-y-2">
|
||||
{[1, 2, 3].map((i) => (
|
||||
<Skeleton key={i} className="h-24 w-full" />
|
||||
|
|
@ -70,6 +52,7 @@ export function DisclosuresPage() {
|
|||
<div className="flex gap-2 pt-1">
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={reviewMutation.isPending}
|
||||
onClick={() => handleReview(dr.id, 'approved')}
|
||||
>
|
||||
<Check className="size-4 mr-1" />
|
||||
|
|
@ -78,6 +61,7 @@ export function DisclosuresPage() {
|
|||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
disabled={reviewMutation.isPending}
|
||||
onClick={() => handleReview(dr.id, 'rejected')}
|
||||
>
|
||||
<X className="size-4 mr-1" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue