diff --git a/web/app/contexts/SchedulesContext.tsx b/web/app/contexts/SchedulesContext.tsx index 47ebe9a..00f3a7f 100644 --- a/web/app/contexts/SchedulesContext.tsx +++ b/web/app/contexts/SchedulesContext.tsx @@ -20,6 +20,11 @@ export interface CloudScheduleType { classes: Array; }; +export interface ScheduleAPIType { + schedules: Array; + message: string; +}; + type SchedulesType = Array>; type SchedulesCloudType = Array; diff --git a/web/app/schedules/home/components/GenerateScheduleButton.tsx b/web/app/schedules/home/components/GenerateScheduleButton.tsx index c96dfdc..086e9e3 100644 --- a/web/app/schedules/home/components/GenerateScheduleButton.tsx +++ b/web/app/schedules/home/components/GenerateScheduleButton.tsx @@ -10,7 +10,7 @@ import useUser from '@/app/hooks/useUser'; import Button from '@/app/components/Button'; import Modal from '@/app/components/Modal/Modal'; -import { ScheduleClassType } from '@/app/contexts/SchedulesContext'; +import { ScheduleAPIType, ScheduleClassType } from '@/app/contexts/SchedulesContext'; import generateSchedule, { EachFieldNumber } from '@/app/utils/api/generateSchedule'; import { errorToast } from '@/app/utils/errorToast'; @@ -54,10 +54,11 @@ export default function GenerateScheduleButton() { setLoading(true); generateSchedule(classes_id, [morningPreference, afternoonPreference, nightPreference]).then((response) => { if (response.status === 200) { - const schedules = response.data as Array; + const data = response.data as ScheduleAPIType; + const schedules = data.schedules as Array; - if (!schedules.length) { - errorToast('Nenhuma grade conseguiu ser gerada!'); + if (!schedules.length) { + errorToast(data.message, data.message.split('\n').length == 1); setLoading(false); } else { setLocalSchedules(schedules);