From 767825b7211a2c2b7328506379e5174b77487c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Galdal?= Date: Tue, 19 Aug 2025 21:09:25 +0200 Subject: [PATCH 1/2] Don't duplicate if short name is same as long name --- lib/utils/getCommitteeDisplayNameFactory.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/utils/getCommitteeDisplayNameFactory.ts b/lib/utils/getCommitteeDisplayNameFactory.ts index 732b0c57..981c22e5 100644 --- a/lib/utils/getCommitteeDisplayNameFactory.ts +++ b/lib/utils/getCommitteeDisplayNameFactory.ts @@ -16,7 +16,13 @@ export const getCommitteeDisplayNameFactory = async () => { ({ name_short }) => name_short == committee )?.name_long; - return name_long ? `${name_long} (${committee})` : committee; + if (!name_long) { + return committee; + } else if (name_long == committee) { + return committee; + } else { + return `${name_long} (${committee})`; + } }; return getCommitteeDisplayName; From 5a531aa3e28807c9b3c3281447e124d0d1893416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Galdal?= Date: Tue, 19 Aug 2025 21:09:46 +0200 Subject: [PATCH 2/2] feat: use display name for optional --- components/form/ApplicationForm.tsx | 8 ++++---- lib/utils/toString.ts | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/components/form/ApplicationForm.tsx b/components/form/ApplicationForm.tsx index 339343c5..68959721 100644 --- a/components/form/ApplicationForm.tsx +++ b/components/form/ApplicationForm.tsx @@ -4,7 +4,7 @@ import TextAreaInput from "./TextAreaInput"; import SelectInput from "./SelectInput"; import Line from "./Line"; import { DeepPartial, applicantType } from "../../lib/types/types"; -import { changeDisplayName } from "../../lib/utils/toString"; +import { revertDisplayName } from "../../lib/utils/toString"; import { useEffect, useState } from "react"; import CustomPhoneInput from "./CustomPhoneInput"; import "react-phone-input-2/lib/bootstrap.css"; @@ -212,9 +212,9 @@ export const ApplicationForm = (props: Props) => { ["Ja", "ja"], ["Nei", "nei"], ]} - label={`Ønsker du å søke ${changeDisplayName(committee)} ${ - availableCommittees.length > 1 ? "i tillegg?" : "?" - }`} + label={`Ønsker du å søke ${props.getCommitteeDisplayName( + revertDisplayName(committee) + )} ${availableCommittees.length > 1 ? "i tillegg?" : "?"}`} updateInputValues={(value: string) => addOptionalCommittee(committee, value) } diff --git a/lib/utils/toString.ts b/lib/utils/toString.ts index 6ae506ef..5b5ba8a8 100644 --- a/lib/utils/toString.ts +++ b/lib/utils/toString.ts @@ -1,8 +1,17 @@ export const changeDisplayName = (committee: string) => { - if (committee.toLowerCase() === "kjelleren") { - return "Realfagskjelleren"; - } - return committee.charAt(0).toUpperCase() + committee.slice(1); + const apiName = revertDisplayName(committee); + return apiName === "Kjelleren" ? "Realfagskjelleren" : apiName; +}; + +/** + * Changes committeeName back to the capitalization used in the API. + * + * @param committee + */ +export const revertDisplayName = (committee: string) => { + // TODO: Don't do this reverse .toLowerCase(), but use the value given from the api along the whole path instead + const capitalized = committee.charAt(0).toUpperCase() + committee.slice(1); + return capitalized; }; export function formatPhoneNumber(phoneNumber: string) {