feat(ui): add navigation header and wire up real page routes
- 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
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
|
||||
import { getAllBooks } from "@/api/books"
|
||||
import { borrowBookForMe } from "@/api/borrows"
|
||||
import { toast } from "sonner"
|
||||
|
||||
export function useBooks() {
|
||||
return useQuery({
|
||||
queryKey: ["books"],
|
||||
queryFn: getAllBooks,
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function useBorrowBook() {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: borrowBookForMe,
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ["books"] })
|
||||
qc.invalidateQueries({ queryKey: ["myBorrows"] })
|
||||
toast.success("借阅成功")
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : "借阅失败")
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user