Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions components/form/ApplicationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/getCommitteeDisplayNameFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 13 additions & 4 deletions lib/utils/toString.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down