diff --git a/src/pages/schools.tsx b/src/pages/schools.tsx index 6d5c571..a1b2e21 100644 --- a/src/pages/schools.tsx +++ b/src/pages/schools.tsx @@ -9,23 +9,20 @@ export default function Schools() { const [loading, setLoading] = useState(true); const router = useRouter(); - useEffect(() => { + useEffect(async () => { if (!api.AuthService.isAuthenticated()) { router.push("/"); return; } - api.SchoolService.getSchools() - .then((data) => { - const allSchools = data.data; - - setSchools(allSchools); - setLoading(false); - }) - .catch((error) => { - console.error("Erro ao buscar escolas:", error); - setLoading(false); - }); + try { + const { data } = await api.SchoolService.getSchools() + setSchools(data); + } catch(error) { + console.error("Erro ao buscar escolas:", error); + } finally { + setLoading(false); + } }, [router]); const handleSelectSchool = (schoolId: string) => { diff --git a/src/pages/subject.tsx b/src/pages/subject.tsx index 4c03d48..b43a8e6 100644 --- a/src/pages/subject.tsx +++ b/src/pages/subject.tsx @@ -12,7 +12,7 @@ export default function Subject() { const [loading, setLoading] = useState(true); const [subject, setSubject] = useState<{ id: string; name: string } | null>(null); - useEffect(() => { + useEffect(async () => { if (!api.AuthService.isAuthenticated()) { router.push("/"); return; @@ -24,15 +24,14 @@ export default function Subject() { return; } - api.SubjectService.getSubject(selectedSubject) - .then((data) => { - setSubject(data.data); - setLoading(false); - }) - .catch((error) => { - console.error("Erro ao buscar disciplina:", error); - setLoading(false); - }); + try { + const { data } = await api.SubjectService.getSubject(selectedSubject) + setSubject(data.data); + } catch(error) { + console.error("Erro ao buscar disciplina:", error); + } finally { + setLoading(false); + } }, [router]); return (