diff --git a/api/api/tests/test_schedule_save.py b/api/api/tests/test_schedule_save.py index 51792a6b..f88d69ec 100644 --- a/api/api/tests/test_schedule_save.py +++ b/api/api/tests/test_schedule_save.py @@ -3,7 +3,7 @@ from rest_framework_simplejwt.serializers import TokenObtainPairSerializer -from ..views.save_schedule import SCHEDULES_LIMIT, SCHEDULES_LIMIT_ERROR_MSG +from ..views.save_schedule import SCHEDULES_LIMIT, SCHEDULES_LIMIT_ERROR_MSG, SCHEDULES_INVALID_SCHEDULES_MSG from utils import db_handler as dbh @@ -251,7 +251,7 @@ def test_save_incorrect_schedule_with_compatible_classes(self): response = self.make_post_request(schedule=schedule) - error_msg = 'error while saving schedule, you may have chosen classes that are not compatible' + error_msg = SCHEDULES_INVALID_SCHEDULES_MSG self.assertEqual(response.data.get('errors'), error_msg) self.assertEqual(response.status_code, 400) diff --git a/api/api/views/save_schedule.py b/api/api/views/save_schedule.py index 8c25df72..5d9081f2 100644 --- a/api/api/views/save_schedule.py +++ b/api/api/views/save_schedule.py @@ -13,7 +13,9 @@ from api import serializers SCHEDULES_LIMIT = 10 -SCHEDULES_LIMIT_ERROR_MSG = f"you have reached the limit of {SCHEDULES_LIMIT} schedules" +SCHEDULES_LIMIT_ERROR_MSG = f"Você atingiu o limite de {SCHEDULES_LIMIT} grades na nuvem." +SCHEDULES_INVALID_SCHEDULES_MSG = "Erro ao salvar a grade horária. Você pode ter escolhido matérias com horários incompatíveis." +SCHEDULES_SAVE_ERROR_MSG = "Ocorreu um erro no servidor ao salvar a grade horária. Tente novamente." class SaveSchedule(): @@ -51,13 +53,13 @@ def post(self, request: request.Request, *args, **kwargs) -> response.Response: try: valid_schedule = validate_received_schedule(current_db_classes_ids) except: - error_msg = "error while saving schedule, you may have chosen classes that are not compatible" + error_msg = SCHEDULES_INVALID_SCHEDULES_MSG return handle_400_error(error_msg) user = request.user answer = save_schedule(user, valid_schedule) - return response.Response(status=status.HTTP_201_CREATED) if answer else handle_400_error("error while saving schedule") + return response.Response(status=status.HTTP_201_CREATED) if answer else handle_400_error(SCHEDULES_SAVE_ERROR_MSG) def check_discipline_key_existence(key: str, discipline_key: str, **kwargs): diff --git a/web/app/components/AsideSchedulePopUp/Form/DisciplineOptionForm.tsx b/web/app/components/AsideSchedulePopUp/Form/DisciplineOptionForm.tsx index 9bcffc10..016c614b 100644 --- a/web/app/components/AsideSchedulePopUp/Form/DisciplineOptionForm.tsx +++ b/web/app/components/AsideSchedulePopUp/Form/DisciplineOptionForm.tsx @@ -2,7 +2,7 @@ import { ChangeEvent, Dispatch, SetStateAction, useEffect, useState } from 'reac import useYearPeriod from '@/app/hooks/useYearPeriod'; import useSelectedClasses from '@/app/hooks/useSelectedClasses'; -import { errorToast } from '@/app/utils/errorToast'; +import { errorToast } from '@/app/utils/toast'; import { DisciplineOptionFormPropsType, FormType, defaultFormData } from '../types/types'; import { DisciplineType } from '@/app/utils/api/searchDiscipline'; diff --git a/web/app/components/SchedulePreview/SchedulePreview.tsx b/web/app/components/SchedulePreview/SchedulePreview.tsx index a7bd7aeb..b805258d 100644 --- a/web/app/components/SchedulePreview/SchedulePreview.tsx +++ b/web/app/components/SchedulePreview/SchedulePreview.tsx @@ -18,9 +18,10 @@ import saveSchedule from '@/app/utils/api/saveSchedule'; import getSchedules from '@/app/utils/api/getSchedules'; import { days, months } from '@/app/utils/dates'; import deleteSchedule from '@/app/utils/api/deleteSchedule'; -import { errorToast } from '@/app/utils/errorToast'; +import { errorToast, successToast } from '@/app/utils/toast'; import jsPDF from 'jspdf'; +import { AxiosError } from 'axios'; const commonError = () => errorToast('Houve um erro na atualização das grades!'); @@ -92,21 +93,9 @@ function BottomPart(props: { } }) { const { user } = useUser(); - const { setCloudSchedules } = useSchedules(); const [changeDate, setChangeDate] = useState(''); - async function handleUploadToCloud() { - const saveResponse = await saveSchedule(props.schedules.localSchedule, user.access); - - if (saveResponse.status == 201) { - getSchedules(user.access).then(response => { - props.handleDelete(); - setCloudSchedules(response.data); - }).catch(() => commonError()); - } else errorToast('Não foi possível salvar a grade na nuvem!'); - } - useEffect(() => { if (props.isCloud && props.schedules.cloudSchedule?.created_at) { setChangeDate(handleDate(props.schedules.cloudSchedule.created_at)); @@ -115,18 +104,12 @@ function BottomPart(props: { return (