From 97e7bf8eecaead1d5f493b4ad067a2cc7a00be2f Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Fri, 14 Mar 2025 11:14:47 +0700 Subject: [PATCH] fix: enhance findLastEducation utility to support dynamic key retrieval and update DocumentBiodata component for improved education level display --- components/ui/DocumentBiodata.tsx | 10 +++++++--- utils/findLastEducation.ts | 25 +++++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/components/ui/DocumentBiodata.tsx b/components/ui/DocumentBiodata.tsx index 2572181..cde8bff 100644 --- a/components/ui/DocumentBiodata.tsx +++ b/components/ui/DocumentBiodata.tsx @@ -13,6 +13,7 @@ import { import get from "lodash.get"; import { dayDate } from "@/lib/utils/date"; import { getNumber } from "@/lib/utils/getNumber"; +import { findLastEducation } from "@/lib/utils/findLastEducation"; Font.register({ family: "zen", src: `${process.env.NEXT_PUBLIC_BASE_URL}/zen.ttf`, @@ -739,7 +740,7 @@ export const DocumentBiodata: FC = ({ data, onRender }) => { borderColor: "black", }} > - {} + {findLastEducation(level, data?.educations, "graduate_year")} = ({ data, onRender }) => { borderColor: "black", }} > - {level} + {findLastEducation(level, data?.educations, "school_name") || + level} = ({ data, onRender }) => { borderRight: 1, borderColor: "black", }} - > + > + {findLastEducation(level, data?.educations, "major")} + { +import get from "lodash.get"; +export const findLastEducation = ( + searchTerm: string, + userEducation: any[], + keys?: string +) => { if (!Array.isArray(userEducation) || userEducation.length === 0) { return null; // Jika array kosong, kembalikan null } const educationMapping: Record = { - SD: "10 - Junior High School", - SLTP: "9 - Senior High School", - SLTA: "3 - Bachelor", + SD: "8 - Elementary School", + "SD 小学": "8 - Elementary School", + SLTP: "10 - Junior High School", + "SLTP 中学": "10 - Junior High School", + SLTA: "9 - Senior High School", + "SLTA 高学": "9 - Senior High School", "D 1": "4 - Diploma 1", "D 2": "5 - Diploma 2", "D 3": "6 - Diploma 3", "D 1/2/3": ["4 - Diploma 1", "5 - Diploma 2", "6 - Diploma 3"], // Cari D1/D2/D3 tertinggi & terbaru S1: ["3 - Bachelor", "7 - Diploma 4"], // S1 setara dengan D4 S2: "2 - Master Degree", + "S2 研究": "2 - Master Degree", S3: "1 - Doctoral / Professor", }; @@ -29,7 +38,7 @@ export const findLastEducation = (searchTerm: string, userEducation: any[]) => { if (filteredEducations.length === 0) return null; // Pilih jenjang tertinggi, jika sama maka pilih graduate_year terbaru - return filteredEducations.reduce((highest, current) => { + const result = filteredEducations.reduce((highest, current) => { const highestIndex = mappedValue.indexOf(highest.education_level); const currentIndex = mappedValue.indexOf(current.education_level); @@ -43,6 +52,8 @@ export const findLastEducation = (searchTerm: string, userEducation: any[]) => { } return highest; }); + + return keys ? get(result, keys) : result; } else { // Jika hanya satu jenjang (misalnya SD, SLTP, SLTA, S2, S3) filteredEducations = userEducation.filter( @@ -51,8 +62,10 @@ export const findLastEducation = (searchTerm: string, userEducation: any[]) => { if (filteredEducations.length === 0) return null; // Pilih graduate_year terbaru - return filteredEducations.reduce((latest, current) => + const result = filteredEducations.reduce((latest, current) => current.graduate_year > latest.graduate_year ? current : latest ); + + return keys ? get(result, keys) : result; } };