From 68be434d765ab6be2a683b9a828a3156abb94ea7 Mon Sep 17 00:00:00 2001 From: abiyasa05 Date: Fri, 15 Nov 2024 10:11:08 +0700 Subject: [PATCH] update: change verifying page to responsive --- .../_verifyingLayout/verifying/index.lazy.tsx | 400 ++++++++++++++---- 1 file changed, 319 insertions(+), 81 deletions(-) diff --git a/apps/frontend/src/routes/_verifyingLayout/verifying/index.lazy.tsx b/apps/frontend/src/routes/_verifyingLayout/verifying/index.lazy.tsx index b9cae42..7a4a73b 100644 --- a/apps/frontend/src/routes/_verifyingLayout/verifying/index.lazy.tsx +++ b/apps/frontend/src/routes/_verifyingLayout/verifying/index.lazy.tsx @@ -21,6 +21,15 @@ import { ScrollArea } from "@/shadcn/components/ui/scroll-area"; import { Pagination, } from "@/shadcn/components/ui/pagination-assessment"; +import { + Sheet, + SheetContent, + SheetTitle, +} from "@/shadcn/components/ui/sheet"; +import { + LeftSheet, + LeftSheetContent, +} from "@/shadcn/components/ui/leftsheet"; import { useQuery, useMutation } from "@tanstack/react-query"; import { submitAssessmentMutationOptions, @@ -38,11 +47,12 @@ import { import { getAllVerifiedAspectsAverageScore, } from "@/modules/assessmentResult/queries/assessmentResultQueries"; -import { TbFlagFilled, TbUpload, TbChevronRight, TbChevronDown } from "react-icons/tb"; +import { TbLayoutSidebarLeftCollapseFilled, TbChevronRight, TbChevronDown } from "react-icons/tb"; import FinishAssessmentModal from "@/modules/assessmentManagement/modals/ConfirmModal"; import ValidationModal from "@/modules/assessmentManagement/modals/ValidationModal"; import FileSizeValidationModal from "@/modules/assessmentManagement/modals/FileSizeValidationModal"; import { useState, useRef, useEffect } from "react"; +import AppHeader from "@/components/AppHeader"; const getQueryParam = (param: string) => { const urlParams = new URLSearchParams(window.location.search); @@ -98,6 +108,21 @@ export default function AssessmentPage() { const [currentPagePerSubAspect, setCurrentPagePerSubAspect] = useState<{ [subAspectId: string]: number }>({}); const currentPage = currentPagePerSubAspect[selectedSubAspectId || ""] || 1; const questionsPerPage = 10; + const [isMobile, setIsMobile] = useState(window.innerWidth <= 768); // Check for mobile screen + const [isSidebarOpen, setIsSidebarOpen] = useState(false); + const [openNavbar, setOpenNavbar] = useState(false); + const [isLeftSidebarOpen, setIsLeftSidebarOpen] = useState(false); + + const toggleLeftSidebar = () => setIsLeftSidebarOpen(!isLeftSidebarOpen); + + const toggle = () => { + setOpenNavbar((prevState) => !prevState); + }; + + // Adjust layout on screen resize + window.addEventListener('resize', () => { + setIsMobile(window.innerWidth <= 768); + }); // Fetch aspects and sub-aspects const aspectsQuery = useQuery({ @@ -587,62 +612,123 @@ console.log("unanswered questions:", unanswered.length); {/* LEFT-SIDE */} {/* Aspek dan Sub-Aspek */} -
- -
- {/* Aspek */} - {aspectsQuery.data?.data - .filter((aspect) => - aspect.subAspects.some((subAspect) => - data?.data.some((question) => question.subAspectId === subAspect.id) - ) - ) - .map((aspect) => ( -
-
toggleAspect(aspect.id)} - > -
{aspect.name}
-
- {openAspects[aspect.id] ? ( - - ) : ( - + + + {/* Sidebar for Mobile */} + {isMobile && ( + setIsLeftSidebarOpen(open)}> + + + +
+ {/* Aspek */} + {aspectsQuery.data?.data + .filter((aspect) => + aspect.subAspects.some((subAspect) => + data?.data.some((question) => question.subAspectId === subAspect.id) + ) + ) + .map((aspect) => ( +
+
toggleAspect(aspect.id)} + > +
{aspect.name}
+
+ {openAspects[aspect.id] ? ( + + ) : ( + + )} +
+
+ + {/* Sub-Aspek */} + {openAspects[aspect.id] && ( +
+ {aspect.subAspects + .filter((subAspect) => + data?.data.some((question) => question.subAspectId === subAspect.id) + ) + .map((subAspect) => ( +
setSelectedSubAspectId(subAspect.id)} + > +
{subAspect.name}
+
+ ))} +
)}
-
+ ))} +
+ + + + )} - {/* Sub-Aspek */} - {openAspects[aspect.id] && ( -
- {aspect.subAspects - .filter((subAspect) => - data?.data.some((question) => question.subAspectId === subAspect.id) - ) - .map((subAspect) => ( -
setSelectedSubAspectId(subAspect.id)} - > -
{subAspect.name}
-
- ))} + {/* Sidebar for Desktop (Always Visible) */} +
+ + +
+ {/* Aspek */} + {aspectsQuery.data?.data + .filter((aspect) => + aspect.subAspects.some((subAspect) => + data?.data.some((question) => question.subAspectId === subAspect.id) + ) + ) + .map((aspect) => ( +
+
toggleAspect(aspect.id)} + > +
{aspect.name}
+
+ {openAspects[aspect.id] ? ( + + ) : ( + + )} +
- )} -
- ))} -
-
-
+ + {/* Sub-Aspek */} + {openAspects[aspect.id] && ( +
+ {aspect.subAspects + .filter((subAspect) => + data?.data.some((question) => question.subAspectId === subAspect.id) + ) + .map((subAspect) => ( +
setSelectedSubAspectId(subAspect.id)} + > +
{subAspect.name}
+
+ ))} +
+ )} +
+ ))} +
+ +
{/* MIDDLE */} {/* Pertanyaan */} -
+
Harap menjawab semua pertanyaan yang tersedia @@ -664,39 +750,35 @@ console.log("unanswered questions:", unanswered.length); className="space-y-4" > - - {/* Question */} - {startIndex + index + 1}. -
- - {question.questionText} - -
-
+
+ {/* Question Number */} + {startIndex + index + 1}. - {/* Opsi Radio Button */} + {/* Question Text */} + {question.questionText} +
+ + {/* Radio Button Options */} {question.options?.length > 0 ? (
- handleAnswerChange(questionId, value)} + value={answers[question.questionId] || ""} + onValueChange={(value) => handleAnswerChange(question.questionId, value)} className="flex flex-col gap-2" > {question.options.map((option: any) => (
handleAnswerChange(questionId, option.optionId)} + className={`cursor-pointer transition-transform transform hover:scale-105 shadow-md hover:shadow-lg flex items-center border-4 rounded-lg p-3 text-sm ${answers[question.questionId] === option.optionId + ? "bg-[--primary-color] text-white border-[--primary-color]" + : "bg-gray-200 text-black border-gray-200" + }`} + onClick={() => handleAnswerChange(question.questionId, option.optionId)} >