fix: enhance findLastEducation utility to support dynamic key retrieval and update DocumentBiodata component for improved education level display
This commit is contained in:
parent
7f503e7050
commit
97e7bf8eec
|
|
@ -13,6 +13,7 @@ import {
|
||||||
import get from "lodash.get";
|
import get from "lodash.get";
|
||||||
import { dayDate } from "@/lib/utils/date";
|
import { dayDate } from "@/lib/utils/date";
|
||||||
import { getNumber } from "@/lib/utils/getNumber";
|
import { getNumber } from "@/lib/utils/getNumber";
|
||||||
|
import { findLastEducation } from "@/lib/utils/findLastEducation";
|
||||||
Font.register({
|
Font.register({
|
||||||
family: "zen",
|
family: "zen",
|
||||||
src: `${process.env.NEXT_PUBLIC_BASE_URL}/zen.ttf`,
|
src: `${process.env.NEXT_PUBLIC_BASE_URL}/zen.ttf`,
|
||||||
|
|
@ -739,7 +740,7 @@ export const DocumentBiodata: FC<any> = ({ data, onRender }) => {
|
||||||
borderColor: "black",
|
borderColor: "black",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{}
|
{findLastEducation(level, data?.educations, "graduate_year")}
|
||||||
</Text>
|
</Text>
|
||||||
<Text
|
<Text
|
||||||
style={{
|
style={{
|
||||||
|
|
@ -749,7 +750,8 @@ export const DocumentBiodata: FC<any> = ({ data, onRender }) => {
|
||||||
borderColor: "black",
|
borderColor: "black",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{level}
|
{findLastEducation(level, data?.educations, "school_name") ||
|
||||||
|
level}
|
||||||
</Text>
|
</Text>
|
||||||
<Text
|
<Text
|
||||||
style={{
|
style={{
|
||||||
|
|
@ -758,7 +760,9 @@ export const DocumentBiodata: FC<any> = ({ data, onRender }) => {
|
||||||
borderRight: 1,
|
borderRight: 1,
|
||||||
borderColor: "black",
|
borderColor: "black",
|
||||||
}}
|
}}
|
||||||
></Text>
|
>
|
||||||
|
{findLastEducation(level, data?.educations, "major")}
|
||||||
|
</Text>
|
||||||
<Text
|
<Text
|
||||||
style={{
|
style={{
|
||||||
width: 100,
|
width: 100,
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
if (!Array.isArray(userEducation) || userEducation.length === 0) {
|
||||||
return null; // Jika array kosong, kembalikan null
|
return null; // Jika array kosong, kembalikan null
|
||||||
}
|
}
|
||||||
|
|
||||||
const educationMapping: Record<string, string | string[]> = {
|
const educationMapping: Record<string, string | string[]> = {
|
||||||
SD: "10 - Junior High School",
|
SD: "8 - Elementary School",
|
||||||
SLTP: "9 - Senior High School",
|
"SD 小学": "8 - Elementary School",
|
||||||
SLTA: "3 - Bachelor",
|
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 1": "4 - Diploma 1",
|
||||||
"D 2": "5 - Diploma 2",
|
"D 2": "5 - Diploma 2",
|
||||||
"D 3": "6 - Diploma 3",
|
"D 3": "6 - Diploma 3",
|
||||||
"D 1/2/3": ["4 - Diploma 1", "5 - Diploma 2", "6 - Diploma 3"], // Cari D1/D2/D3 tertinggi & terbaru
|
"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
|
S1: ["3 - Bachelor", "7 - Diploma 4"], // S1 setara dengan D4
|
||||||
S2: "2 - Master Degree",
|
S2: "2 - Master Degree",
|
||||||
|
"S2 研究": "2 - Master Degree",
|
||||||
S3: "1 - Doctoral / Professor",
|
S3: "1 - Doctoral / Professor",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -29,7 +38,7 @@ export const findLastEducation = (searchTerm: string, userEducation: any[]) => {
|
||||||
if (filteredEducations.length === 0) return null;
|
if (filteredEducations.length === 0) return null;
|
||||||
|
|
||||||
// Pilih jenjang tertinggi, jika sama maka pilih graduate_year terbaru
|
// 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 highestIndex = mappedValue.indexOf(highest.education_level);
|
||||||
const currentIndex = mappedValue.indexOf(current.education_level);
|
const currentIndex = mappedValue.indexOf(current.education_level);
|
||||||
|
|
||||||
|
|
@ -43,6 +52,8 @@ export const findLastEducation = (searchTerm: string, userEducation: any[]) => {
|
||||||
}
|
}
|
||||||
return highest;
|
return highest;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return keys ? get(result, keys) : result;
|
||||||
} else {
|
} else {
|
||||||
// Jika hanya satu jenjang (misalnya SD, SLTP, SLTA, S2, S3)
|
// Jika hanya satu jenjang (misalnya SD, SLTP, SLTA, S2, S3)
|
||||||
filteredEducations = userEducation.filter(
|
filteredEducations = userEducation.filter(
|
||||||
|
|
@ -51,8 +62,10 @@ export const findLastEducation = (searchTerm: string, userEducation: any[]) => {
|
||||||
if (filteredEducations.length === 0) return null;
|
if (filteredEducations.length === 0) return null;
|
||||||
|
|
||||||
// Pilih graduate_year terbaru
|
// Pilih graduate_year terbaru
|
||||||
return filteredEducations.reduce((latest, current) =>
|
const result = filteredEducations.reduce((latest, current) =>
|
||||||
current.graduate_year > latest.graduate_year ? current : latest
|
current.graduate_year > latest.graduate_year ? current : latest
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return keys ? get(result, keys) : result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue