feat(manage): update SuggestionsClient to use admin paginated endpoint
This commit is contained in:
@@ -30,6 +30,13 @@ interface Suggestion {
|
|||||||
|
|
||||||
type ConfirmType = "approve" | "reject"
|
type ConfirmType = "approve" | "reject"
|
||||||
|
|
||||||
|
interface SuggestionsApiResponse {
|
||||||
|
data: Suggestion[]
|
||||||
|
total: number
|
||||||
|
limit: number
|
||||||
|
offset: number
|
||||||
|
}
|
||||||
|
|
||||||
const LIMIT = 50
|
const LIMIT = 50
|
||||||
|
|
||||||
function formatDate(value: string | Date | null | undefined) {
|
function formatDate(value: string | Date | null | undefined) {
|
||||||
@@ -43,6 +50,7 @@ export function SuggestionsClient() {
|
|||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [search, setSearch] = useState("")
|
const [search, setSearch] = useState("")
|
||||||
const [offset, setOffset] = useState(0)
|
const [offset, setOffset] = useState(0)
|
||||||
|
const [total, setTotal] = useState(0)
|
||||||
const [actionLoading, setActionLoading] = useState<Record<string, boolean>>({})
|
const [actionLoading, setActionLoading] = useState<Record<string, boolean>>({})
|
||||||
const [confirmAction, setConfirmAction] = useState<{
|
const [confirmAction, setConfirmAction] = useState<{
|
||||||
type: ConfirmType
|
type: ConfirmType
|
||||||
@@ -60,10 +68,12 @@ export function SuggestionsClient() {
|
|||||||
const fetchSuggestions = useCallback(async () => {
|
const fetchSuggestions = useCallback(async () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/community-suggestions/pending?limit=${LIMIT}`)
|
const res = await fetch(`/api/community-suggestions/admin?limit=${LIMIT}`)
|
||||||
const json = await res.json()
|
if (res.ok) {
|
||||||
const data = Array.isArray(json) ? json : (json.data ?? [])
|
const json = (await res.json()) as SuggestionsApiResponse
|
||||||
setSuggestions(data)
|
setSuggestions(json.data)
|
||||||
|
setTotal(json.total)
|
||||||
|
}
|
||||||
setOffset(0)
|
setOffset(0)
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@@ -94,7 +104,6 @@ export function SuggestionsClient() {
|
|||||||
}, [suggestions, search, activeTab])
|
}, [suggestions, search, activeTab])
|
||||||
|
|
||||||
const paginated = filtered.slice(offset, offset + LIMIT)
|
const paginated = filtered.slice(offset, offset + LIMIT)
|
||||||
const total = filtered.length
|
|
||||||
const hasMore = offset + LIMIT < total
|
const hasMore = offset + LIMIT < total
|
||||||
|
|
||||||
const handlePrev = () => setOffset((prev) => Math.max(0, prev - LIMIT))
|
const handlePrev = () => setOffset((prev) => Math.max(0, prev - LIMIT))
|
||||||
|
|||||||
Reference in New Issue
Block a user