fix: Call correct /api/elections/active endpoint and handle array response
The blockchain page was calling /api/elections instead of
/api/elections/active, resulting in 404 Not Found errors.
The API returns an array directly, not wrapped in an object,
so updated response parsing to handle both formats.
This fixes 'Error fetching elections: Impossible de charger
les élections' error on the blockchain dashboard page.
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
38369a7f88
commit
e10a882667
@ -22,7 +22,7 @@ export default function BlockchainPage() {
|
|||||||
try {
|
try {
|
||||||
setElectionsLoading(true)
|
setElectionsLoading(true)
|
||||||
const token = localStorage.getItem("auth_token")
|
const token = localStorage.getItem("auth_token")
|
||||||
const response = await fetch("/api/elections", {
|
const response = await fetch("/api/elections/active", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
@ -33,11 +33,13 @@ export default function BlockchainPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
setElections(data.elections || [])
|
// API returns array directly, not wrapped in .elections
|
||||||
|
const elections = Array.isArray(data) ? data : data.elections || []
|
||||||
|
setElections(elections)
|
||||||
|
|
||||||
// Select first election by default
|
// Select first election by default
|
||||||
if (data.elections && data.elections.length > 0) {
|
if (elections && elections.length > 0) {
|
||||||
setSelectedElection(data.elections[0].id)
|
setSelectedElection(elections[0].id)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error fetching elections:", err)
|
console.error("Error fetching elections:", err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user