From a673034c83da6afdbffdbadd11f0be0e35e0f2f1 Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 15 Jan 2024 20:28:33 -0300 Subject: [PATCH] ux(option-form): fix code climate issues --- .../Form/DisciplineOptionForm.tsx | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/web/app/components/AsideSchedulePopUp/Form/DisciplineOptionForm.tsx b/web/app/components/AsideSchedulePopUp/Form/DisciplineOptionForm.tsx index 7e45615..664921a 100644 --- a/web/app/components/AsideSchedulePopUp/Form/DisciplineOptionForm.tsx +++ b/web/app/components/AsideSchedulePopUp/Form/DisciplineOptionForm.tsx @@ -46,31 +46,29 @@ function Form(props: FormPropsType) { function getYearAndPeriod(text: string) { const year = text.split('/')[0] || defaultFormData.year; const period = text.split('/')[1] || defaultFormData.period; - + return { year, period }; } +function handleChangeYearAndPeriod(text: string, currentYearPeriod: string, selectedClasses: any, handleSetYearPeriod: () => void) { + if (currentYearPeriod && selectedClasses && currentYearPeriod != text) { + errorToast('Há disciplinas selecionadas de outro período, não pode haver mistura!'); + } else handleSetYearPeriod(); +} + export default function DisciplineOptionForm(props: DisciplineOptionFormPropsType) { const { selectedClasses, currentYearPeriod, setCurrentYearPeriod } = useSelectedClasses(); const [disableDefault, setDisableDefault] = useState(false); const [formData, setFormData] = useState(defaultFormData); useEffect(() => { - if (disableDefault || formData != defaultFormData) - return; - - if (selectedClasses.size) { + if (!disableDefault && formData == defaultFormData && selectedClasses.size) { const { year, period } = getYearAndPeriod(currentYearPeriod); setFormData({ ...formData, year: year, period: period }); setDisableDefault(true); } }, [disableDefault, currentYearPeriod, formData, selectedClasses]); - function handleChangeYearAndPeriod(text: string, handleSetYearPeriod: () => void) { - if (currentYearPeriod && currentYearPeriod != text && selectedClasses.size) { - errorToast('Há disciplinas selecionadas de outro período, não pode haver mistura!'); - } else handleSetYearPeriod(); - } function handleYearAndPeriodChange(event: ChangeEvent) { const text = event.target.value.trim(); @@ -83,7 +81,7 @@ export default function DisciplineOptionForm(props: DisciplineOptionFormPropsTyp setCurrentYearPeriod(text); setDisableDefault(true); }; - handleChangeYearAndPeriod(text, handleSetYearPeriod); + handleChangeYearAndPeriod(text, currentYearPeriod, selectedClasses.size, handleSetYearPeriod); } }