diff --git a/apps/frontend/src/routes/_assessmentLayout/assessment/index.lazy.tsx b/apps/frontend/src/routes/_assessmentLayout/assessment/index.lazy.tsx index d4d86c7..66ec9d0 100644 --- a/apps/frontend/src/routes/_assessmentLayout/assessment/index.lazy.tsx +++ b/apps/frontend/src/routes/_assessmentLayout/assessment/index.lazy.tsx @@ -82,10 +82,6 @@ export default function AssessmentPage() { getQuestionsAllQueryOptions(page, limit) ); - // const handleFinishClick = () => { - // setModalOpen(true); - // }; - // Fungsi untuk memeriksa pertanyaan yang belum dijawab const checkUnansweredQuestions = () => { // Misalkan data berisi pertanyaan dan jawaban @@ -108,8 +104,6 @@ export default function AssessmentPage() { checkUnansweredQuestions(); }; - - useEffect(() => { const id = getQueryParam("id"); @@ -118,7 +112,7 @@ export default function AssessmentPage() { } else { setAssessmentId(id); } - + // Check if aspectsQuery.data is defined if (aspectsQuery.data?.data && aspectsQuery.data.data.length > 0) { // If no sub-aspect is selected, find a suitable default @@ -133,12 +127,13 @@ export default function AssessmentPage() { setSelectedSubAspectId(firstMatchingSubAspect.id); // Find the parent aspect and set its id as the selectedAspectId - const parentAspect = aspectsQuery.data.data.find(aspect => - aspect.subAspects.some(sub => sub.id === firstMatchingSubAspect.id) + const parentAspect = aspectsQuery.data.data.find((aspect) => + aspect.subAspects.some((sub) => sub.id === firstMatchingSubAspect.id) ); if (parentAspect) { setSelectedAspectId(parentAspect.id); // Use `id` from the parent aspect + setOpenAspects({ [parentAspect.id]: true }); // Open only relevant aspects } } } else { @@ -149,9 +144,11 @@ export default function AssessmentPage() { if (matchingAspect) { setSelectedAspectId(matchingAspect.id); // Use `id` from the matching aspect + setOpenAspects({ [matchingAspect.id]: true }); // Close all other dropdowns and open only the newly selected aspect } else { console.warn("No matching aspect found for selected sub-aspect."); setSelectedAspectId(null); + setOpenAspects({}); // Close all dropdowns if none of them match } } }