From 4fca8b25f57413e3cf1697cca6486b5fc56a4804 Mon Sep 17 00:00:00 2001 From: JoaoBarreto03 <211039519@aluno.unb.br> Date: Sat, 9 Dec 2023 18:43:40 -0300 Subject: [PATCH] Adicionando US53 (Pequeno bug a corrigir) Co-authored-by: Artur --- frontend/src/pages/ViewPlan.tsx | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/frontend/src/pages/ViewPlan.tsx b/frontend/src/pages/ViewPlan.tsx index 1ed784b..a63cab6 100644 --- a/frontend/src/pages/ViewPlan.tsx +++ b/frontend/src/pages/ViewPlan.tsx @@ -10,6 +10,7 @@ import { saveAs } from 'file-saver'; const ViewPlan = () => { const { id } = useParams(); + const { idDrill } = useParams(); const [title, setTitle] = useState(''); const [titleAux, setTitleAux] = useState(''); const [goals, setGoals] = useState(''); @@ -41,6 +42,7 @@ const ViewPlan = () => { userId = ''; } + const [titleDrill, setTitleDrill] = useState(''); const [descriptionDrill, setDescriptionDrill] = useState(''); const [observationsDrill, setObservationsDrill] = useState(''); @@ -53,13 +55,11 @@ const ViewPlan = () => { const [drillUpdated, setDrillUpdated] = useState({ id: '', - title: titleDrill, - description: descriptionDrill, - observations: observationsDrill, - classPlanId: id, + title: '', + description: '', + observations: '', + classPlanId: '', }); - - async function loadData() { if (id != null) { @@ -69,8 +69,8 @@ const ViewPlan = () => { } async function loadDataDrill() { - if (id != null) { - const response = await drill.getById(id); + if (idDrill != null) { + const response = await drill.getById(idDrill); setDrillUpdated(response.data); } } @@ -154,10 +154,10 @@ const ViewPlan = () => { useEffect(() => { loadDataDrill(); - setTitleDrill(titleDrill); - setDescriptionDrill(descriptionDrill); - setObservationsDrill(observationsDrill); - }, [titleDrill, descriptionDrill, observationsDrill]); + setTitleDrill(drillUpdated.title); + setDescriptionDrill(drillUpdated.description); + setObservationsDrill(drillUpdated.observations); + }, [drillUpdated]); @@ -252,11 +252,10 @@ const ViewPlan = () => { goals: planUpdated.goals, observations: planUpdated.observations, }, - drills: drills.map((drill) => ({ - title: drillUpdated.title, - description: drillUpdated.description, - observations: drillUpdated.observations, - + drills: drills.map((Drill) => ({ + title: Drill.title || '', + description: Drill.description || '', + observations: Drill.observations || '', })), };