Skip to content

Commit

Permalink
front(generator): update API generator response
Browse files Browse the repository at this point in the history
  • Loading branch information
caio-felipee committed Jan 7, 2024
1 parent 891b17b commit 1f727a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions web/app/contexts/SchedulesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface CloudScheduleType {
classes: Array<ScheduleClassType>;
};

export interface ScheduleAPIType {
schedules: Array<ScheduleClassType>;
message: string;
};

type SchedulesType = Array<Array<ScheduleClassType>>;
type SchedulesCloudType = Array<CloudScheduleType>;

Expand Down
9 changes: 5 additions & 4 deletions web/app/schedules/home/components/GenerateScheduleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<ScheduleClassType>;
const data = response.data as ScheduleAPIType;
const schedules = data.schedules as Array<ScheduleClassType>;

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);
Expand Down

0 comments on commit 1f727a3

Please sign in to comment.