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