Refine admin panel workflows
This commit is contained in:
@@ -216,6 +216,20 @@ const emptyAdminSeasonDetail: AdminSeasonDetailResponse = {
|
||||
clipSubmissions: [],
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarantee the array fields exist even if a (possibly older) backend omits them,
|
||||
* so views can safely read `.length`/`.filter` without crashing the render.
|
||||
*/
|
||||
function normalizeSeasonDetail(detail: AdminSeasonDetailResponse): AdminSeasonDetailResponse {
|
||||
return {
|
||||
...detail,
|
||||
categories: detail.categories ?? [],
|
||||
candidates: detail.candidates ?? [],
|
||||
pendingNominations: detail.pendingNominations ?? [],
|
||||
clipSubmissions: detail.clipSubmissions ?? [],
|
||||
}
|
||||
}
|
||||
|
||||
export const useAwardsStore = defineStore('awards', {
|
||||
state: () => ({
|
||||
overview: fallbackOverview as OverviewResponse,
|
||||
@@ -259,7 +273,7 @@ export const useAwardsStore = defineStore('awards', {
|
||||
}
|
||||
|
||||
if (this.adminSelectedSeasonId) {
|
||||
this.adminSeasonDetail = await api.getAdminSeasonDetail(this.adminSelectedSeasonId)
|
||||
this.adminSeasonDetail = normalizeSeasonDetail(await api.getAdminSeasonDetail(this.adminSelectedSeasonId))
|
||||
}
|
||||
this.apiMode = 'api'
|
||||
} catch {
|
||||
@@ -272,7 +286,7 @@ export const useAwardsStore = defineStore('awards', {
|
||||
async loadAdminSeasonDetail(seasonId: number) {
|
||||
try {
|
||||
this.adminSelectedSeasonId = seasonId
|
||||
this.adminSeasonDetail = await api.getAdminSeasonDetail(seasonId)
|
||||
this.adminSeasonDetail = normalizeSeasonDetail(await api.getAdminSeasonDetail(seasonId))
|
||||
this.apiMode = 'api'
|
||||
} catch {
|
||||
this.adminSeasonDetail = emptyAdminSeasonDetail
|
||||
|
||||
Reference in New Issue
Block a user