From fe53a127e97a320803c9feb0e64297525ece1f56 Mon Sep 17 00:00:00 2001 From: Sukma Gladys Date: Thu, 21 Nov 2024 11:48:00 +0700 Subject: [PATCH] fix: add responsive feature to assessment result page --- apps/frontend/src/components/AppHeader.tsx | 2 +- .../assessmentResult/index.lazy.tsx | 214 ++++++++++++------ 2 files changed, 148 insertions(+), 68 deletions(-) diff --git a/apps/frontend/src/components/AppHeader.tsx b/apps/frontend/src/components/AppHeader.tsx index f54b02e..38e9000 100644 --- a/apps/frontend/src/components/AppHeader.tsx +++ b/apps/frontend/src/components/AppHeader.tsx @@ -77,7 +77,7 @@ export default function AppHeader({ toggle, toggleLeftSidebar }: Props) { )} - {(showAssessmentLinks || showVerifyingAssessmentLinks) && ( + {(showAssessmentLinks || showVerifyingAssessmentLinks || showAssessmentResultLinks) && ( )} diff --git a/apps/frontend/src/routes/_dashboardLayout/assessmentResult/index.lazy.tsx b/apps/frontend/src/routes/_dashboardLayout/assessmentResult/index.lazy.tsx index a5b02c0..f4f2b59 100644 --- a/apps/frontend/src/routes/_dashboardLayout/assessmentResult/index.lazy.tsx +++ b/apps/frontend/src/routes/_dashboardLayout/assessmentResult/index.lazy.tsx @@ -19,10 +19,14 @@ import { ChartTooltipContent, } from "@/shadcn/components/ui/chart" import { aspectQueryOptions } from "@/modules/aspectManagement/queries/aspectQueries"; -import { TbChevronDown, TbChevronLeft, TbChevronUp, TbFileTypePdf } from "react-icons/tb"; +import { TbChevronDown, TbChevronLeft, TbChevronRight, TbChevronUp, TbFileTypePdf } from "react-icons/tb"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/shadcn/components/ui/dropdown-menu"; import clsx from "clsx"; import React from "react"; +import AppHeader from "@/components/AppHeader"; +import { LeftSheet, LeftSheetContent } from "@/shadcn/components/ui/leftsheet"; +import { ScrollArea } from "@mantine/core"; +import data from "node_modules/backend/src/appEnv"; const getQueryParam = (param: string) => { const urlParams = new URLSearchParams(window.location.search); @@ -37,6 +41,21 @@ export default function AssessmentResultPage() { const { user } = useAuth(); const isSuperAdmin = user?.role === "super-admin"; + 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 toggle = () => { + setOpenNavbar((prevState) => !prevState); + }; + + // Adjust layout on screen resize + window.addEventListener('resize', () => { + setIsMobile(window.innerWidth <= 768); + }); + + const toggleLeftSidebar = () => setIsLeftSidebarOpen(!isLeftSidebarOpen); + const [assessmentId, setAssessmentId] = useState(undefined); useEffect(() => { @@ -168,26 +187,6 @@ export default function AssessmentResultPage() { return config; }, {} as ChartConfig) || {}; - // Mengatur tampilan label sumbu X - const customizedAxisTick = (props: any) => { - const { x, y, payload } = props; - return ( - - - {payload.value} - - - ); - }; - // Dropdown State const [isOpen, setIsOpen] = useState(false); const [selectedItem, setSelectedItem] = useState('Hasil Assessment'); @@ -206,11 +205,11 @@ export default function AssessmentResultPage() { // Pie Chart Component function PieChartComponent({ chartData, totalScore, chartConfig }: { chartData: { aspectName: string, score: number, fill: string }[], totalScore: number, chartConfig: ChartConfig }) { return ( -
+
{chartData[index]?.score || ""} @@ -255,7 +254,7 @@ export default function AssessmentResultPage() { {totalScore.toLocaleString()} @@ -270,7 +269,7 @@ export default function AssessmentResultPage() {
{/* Legend */} -
+
{chartData.slice(0, 3).map((entry, index) => (
@@ -297,13 +296,32 @@ export default function AssessmentResultPage() {
); } + // Mengatur tampilan label sumbu X + const customizedAxisTick = (props: any) => { + const { x, y, payload } = props; + return ( + + + {payload.value.slice(0, 3)} + + + ); + }; // Bar Chart Component function BarChartComponent({ barChartData, barChartConfig }: { barChartData: { subAspectName: string, score: number, fill: string, aspectId: string, aspectName: string }[], barChartConfig: ChartConfig }) { return (
- + - value.toFixed(1)} - ticks={[0, 0,5, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]} - /> + { @@ -355,7 +372,7 @@ export default function AssessmentResultPage() { html2canvas: { scale: 2, width: 1510, - height: pdfContainer.scrollHeight, + height: pdfContainer.scrollHeight, }, jsPDF: { unit: 'pt', @@ -391,9 +408,78 @@ export default function AssessmentResultPage() { return ( -
-

Tingkatan Level Maturitas

+ + {isMobile && ( + setIsLeftSidebarOpen(open)}> + + + +
+
+

Tingkatan Level Maturitas

+ {[ + { level: 5, colorVar: '--levelFive-color', title: 'Implementasi Optimal', details: ['Otomatisasi', 'Terintegrasi', 'Membudaya'], textColor: 'white' }, + { level: 4, colorVar: '--levelFour-color', title: 'Implementasi Terkelola', details: ['Terorganisir', 'Review Berkala', 'Berkelanjutan'], textColor: 'white' }, + { level: 3, colorVar: '--levelThree-color', title: 'Implementasi Terdefinisi', details: ['Terorganisir', 'Konsisten', 'Review Berkala'], textColor: 'white' }, + { level: 2, colorVar: '--levelTwo-color', title: 'Implementasi Berulang', details: ['Terorganisir', 'Tidak Konsisten', 'Berulang'], textColor: 'white' }, + { level: 1, colorVar: '--levelOne-color', title: 'Implementasi Awal', details: ['Tidak Terukur', 'Tidak Konsisten', 'Risiko Tinggi'], textColor: 'white' } + ].map(({ level, colorVar, title, details }) => ( +
+
+

Level {level}

+
+
+

{title}

+ {details.map((detail) => ( +

{detail}

+ ))} +
+
+ ))} +
+ + {/* Total verified score */} +
+ {selectedItem === 'Hasil Assessment' ? ( + <> +
+

Nilai Maturitas

+ {totalScore} +
+
+

Level Maturitas

+ {getScoreStyleClass(Number(totalScore), true).descLevel} +
+ + ) : ( + <> +
+

Nilai Maturitas

+ {totalVerifiedScore} +
+
+

Level Maturitas

+ {getScoreStyleClass(Number(totalVerifiedScore), true).descLevel} +
+ + )} +
+
+
+
+
+ )} + +
+

Tingkatan Level Maturitas

{[ { level: 5, colorVar: '--levelFive-color', title: 'Implementasi Optimal', details: ['Otomatisasi', 'Terintegrasi', 'Membudaya'], textColor: 'white' }, { level: 4, colorVar: '--levelFour-color', title: 'Implementasi Terkelola', details: ['Terorganisir', 'Review Berkala', 'Berkelanjutan'], textColor: 'white' }, @@ -433,7 +519,7 @@ export default function AssessmentResultPage() { ) : ( <> -
+

Nilai Maturitas

{totalVerifiedScore}
@@ -446,8 +532,8 @@ export default function AssessmentResultPage() {
- -
+ +
{/* Konten Header */}
{isSuperAdmin ? ( @@ -459,17 +545,17 @@ export default function AssessmentResultPage() { Kembali -

Detail Hasil Asesmen

+

Detail Hasil Asesmen

Kelola dan Pantau Semua Permohonan Asesmen Dengan Mudah

) : (
-

Dasboard Hasil Tingkat Kematangan Keamanan Cyber

+

Dasboard Hasil Tingkat Kematangan Keamanan Cyber

Kelola dan Pantau Semua Permohonan Asesmen Dengan Mudah

)} -
+
-
+

Nama Responden

@@ -578,8 +664,8 @@ export default function AssessmentResultPage() { {selectedItem === 'Hasil Assessment' ? ( <> {/* Score Table */} -

Tabel Nilai Hasil Assessment

- + +

Tabel Nilai Hasil Assessment

@@ -587,13 +673,13 @@ export default function AssessmentResultPage() { {/* Sub-aspect Score Column (No Left Border and w-fit for flexible width) */} - @@ -628,8 +714,8 @@ export default function AssessmentResultPage() { ) : ( <> {/* Verified Result Table */} -

Tabel Nilai Hasil Assessment Terverifikasi

- + +

Tabel Nilai Hasil Assessment Terverifikasi

-

{aspect.name}

+

{aspect.name}

@@ -610,11 +696,11 @@ export default function AssessmentResultPage() { {aspectsData?.data?.map((aspect) => ( {/* Sub-aspect Name Column (No Right Border) */} -
+ {aspect.subAspects[rowIndex]?.name || ""} + {aspect.subAspects[rowIndex] ? formatScore(getSubAspectScore(aspect.subAspects[rowIndex].id)) : ""}
@@ -637,13 +723,13 @@ export default function AssessmentResultPage() { {/* Sub-aspect Score Column (No Left Border and w-fit for flexible width) */} - @@ -677,13 +763,13 @@ export default function AssessmentResultPage() { )} - + {/* Bar Chart */} {selectedItem === 'Hasil Assessment' ? ( <> - Diagram Nilai Hasil Assessment + Diagram Nilai Hasil Assessment @@ -694,7 +780,7 @@ export default function AssessmentResultPage() { <> - Diagram Nilai Hasil Assessment Terverifikasi + Diagram Nilai Hasil Assessment Terverifikasi @@ -705,10 +791,7 @@ export default function AssessmentResultPage() { {/* Pie Chart */} {selectedItem === 'Hasil Assessment' ? ( - - - Diagram Lingkaran - + ) : ( - - - Diagram Lingkaran Terverifikasi - +
-

{aspect.name}

+

{aspect.name}

@@ -660,11 +746,11 @@ export default function AssessmentResultPage() { {aspectsData?.data?.map((aspect) => ( {/* Sub-aspect Name Column (No Right Border) */} -
+ {aspect.subAspects[rowIndex]?.name || ""} + {aspect.subAspects[rowIndex] ? formatScore(getVerifiedSubAspectScore(aspect.subAspects[rowIndex].id)) : ""}