update: revision of the left sidebar dropdown for aspects and sub-aspects of the assessments

This commit is contained in:
falendikategar 2024-10-23 15:23:37 +07:00
parent 9ed9529062
commit d4c8e90670

View File

@ -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");
@ -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
}
}
}