fix: enhance findLastEducation utility to support dynamic key retrieval and update DocumentBiodata component for improved education level display

This commit is contained in:
faisolavolut 2025-03-14 11:14:47 +07:00
parent 7f503e7050
commit 97e7bf8eec
2 changed files with 26 additions and 9 deletions

View File

@ -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<any> = ({ data, onRender }) => {
borderColor: "black",
}}
>
{}
{findLastEducation(level, data?.educations, "graduate_year")}
</Text>
<Text
style={{
@ -749,7 +750,8 @@ export const DocumentBiodata: FC<any> = ({ data, onRender }) => {
borderColor: "black",
}}
>
{level}
{findLastEducation(level, data?.educations, "school_name") ||
level}
</Text>
<Text
style={{
@ -758,7 +760,9 @@ export const DocumentBiodata: FC<any> = ({ data, onRender }) => {
borderRight: 1,
borderColor: "black",
}}
></Text>
>
{findLastEducation(level, data?.educations, "major")}
</Text>
<Text
style={{
width: 100,

View File

@ -1,18 +1,27 @@
export const findLastEducation = (searchTerm: string, userEducation: any[]) => {
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<string, string | string[]> = {
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;
}
};