fix: handle wrapped calendar api responses

This commit is contained in:
2026-04-04 10:44:51 +00:00
parent 8208b3b27b
commit a431711ff0

View File

@@ -26,6 +26,12 @@ interface TimeSlotResponse {
updated_at: string | null updated_at: string | null
} }
interface DayViewResponse {
date: string
user_id: number
slots: TimeSlotResponse[]
}
interface SchedulePlanResponse { interface SchedulePlanResponse {
id: number id: number
slot_type: SlotType slot_type: SlotType
@@ -41,6 +47,10 @@ interface SchedulePlanResponse {
updated_at: string | null updated_at: string | null
} }
interface PlanListResponse {
plans: SchedulePlanResponse[]
}
interface WorkloadWarning { interface WorkloadWarning {
period: string period: string
slot_type: string slot_type: string
@@ -111,8 +121,8 @@ export default function CalendarPage() {
setLoading(true) setLoading(true)
setError('') setError('')
try { try {
const { data } = await api.get<TimeSlotResponse[]>(`/calendar/day?date=${date}`) const { data } = await api.get<DayViewResponse>(`/calendar/day?date=${date}`)
setSlots(data) setSlots(Array.isArray(data?.slots) ? data.slots : [])
} catch (err: any) { } catch (err: any) {
setError(err.response?.data?.detail || 'Failed to load calendar') setError(err.response?.data?.detail || 'Failed to load calendar')
setSlots([]) setSlots([])
@@ -123,8 +133,8 @@ export default function CalendarPage() {
const fetchPlans = async () => { const fetchPlans = async () => {
try { try {
const { data } = await api.get<SchedulePlanResponse[]>('/calendar/plans') const { data } = await api.get<PlanListResponse>('/calendar/plans')
setPlans(data) setPlans(Array.isArray(data?.plans) ? data.plans : [])
} catch (err: any) { } catch (err: any) {
console.error('Failed to load plans:', err) console.error('Failed to load plans:', err)
} }