4820370b6a
- Add sticky header with book management nav links and logout button - Replace placeholder page components with real feature imports - Add login page route to router - Fix date-time formatting for consistent YYYY-MM-DD HH:mm output
25 lines
646 B
TypeScript
25 lines
646 B
TypeScript
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
|
|
import { getAllMyBorrows, returnBookForMe } from "@/api/borrows"
|
|
import { toast } from "sonner"
|
|
|
|
export function useMyBorrows() {
|
|
return useQuery({
|
|
queryKey: ["myBorrows"],
|
|
queryFn: getAllMyBorrows,
|
|
})
|
|
}
|
|
|
|
export function useReturnBook() {
|
|
const qc = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: returnBookForMe,
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ["myBorrows"] })
|
|
toast.success("归还成功")
|
|
},
|
|
onError: (err) => {
|
|
toast.error(err instanceof Error ? err.message : "归还失败")
|
|
},
|
|
})
|
|
}
|