Skip to content

Commit 8007d66

Browse files
committed
refactor: added userTypeToTitleCase instead of hardcoded values for user types
1 parent 78a33ee commit 8007d66

File tree

6 files changed

+19
-21
lines changed

6 files changed

+19
-21
lines changed

src/back-end/lib/resources/contact-list.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
nullRequestBodyHandler
1010
} from "back-end/lib/server";
1111
import { Session } from "shared/lib/resources/session";
12-
import { UserType } from "shared/lib/resources/user";
12+
import { UserType, userTypeToTitleCase } from "shared/lib/resources/user";
1313
import { adt } from "shared/lib/types";
1414
import { isValid } from "shared/lib/validation";
1515
import { getString } from "shared/lib";
@@ -108,11 +108,9 @@ const readMany: crud.ReadMany<Session, db.Connection> = (
108108
// Add user type if both Government and Vendor types are selected
109109
if (includeUserType) {
110110
const userTypeLabel =
111-
user.type === UserType.Government
112-
? "Government"
113-
: user.type === UserType.Vendor
114-
? "Vendor"
115-
: "Admin";
111+
user.type === UserType.Admin
112+
? "Admin"
113+
: userTypeToTitleCase(user.type);
116114
row.push(`"${userTypeLabel}"`);
117115
}
118116

src/front-end/typescript/lib/pages/sign-up/step-two.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
immutable,
1717
component as component_
1818
} from "front-end/lib/framework";
19-
import { userTypeToTitleCase } from "front-end/lib/pages/user/lib";
19+
import { userTypeToTitleCase } from "shared/lib/resources/user";
2020
import * as ProfileForm from "front-end/lib/pages/user/lib/components/profile-form";
2121
import Link, {
2222
iconLinkSymbol,

src/front-end/typescript/lib/pages/user/lib/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ export function userToKeyCloakIdentityProviderTitleCase(
4141
);
4242
}
4343

44-
export function userTypeToTitleCase(v: UserType): string {
45-
switch (v) {
46-
case UserType.Government:
47-
case UserType.Admin:
48-
return "Public Sector Employee";
49-
case UserType.Vendor:
50-
return "Vendor";
51-
}
52-
}
53-
5444
export function userTypeToPermissions(v: UserType): string[] {
5545
switch (v) {
5646
case UserType.Admin:

src/front-end/typescript/lib/pages/user/list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import {
1212
import * as api from "front-end/lib/http/api";
1313
import {
1414
userStatusToColor,
15-
userStatusToTitleCase,
16-
userTypeToTitleCase
15+
userStatusToTitleCase
1716
} from "front-end/lib/pages/user/lib";
17+
import { userTypeToTitleCase } from "shared/lib/resources/user";
1818
import Badge from "front-end/lib/views/badge";
1919
import Link, { routeDest } from "front-end/lib/views/link";
2020
import React from "react";

src/front-end/typescript/lib/pages/user/profile/tab/profile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import * as api from "front-end/lib/http/api";
1111
import {
1212
userStatusToColor,
1313
userStatusToTitleCase,
14-
userTypeToPermissions,
15-
userTypeToTitleCase
14+
userTypeToPermissions
1615
} from "front-end/lib/pages/user/lib";
16+
import { userTypeToTitleCase } from "shared/lib/resources/user";
1717
import * as ProfileForm from "front-end/lib/pages/user/lib/components/profile-form";
1818
import * as toasts from "front-end/lib/pages/user/lib/toasts";
1919
import * as Tab from "front-end/lib/pages/user/profile/tab";

src/shared/lib/resources/user.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ export function userTypeToKeycloakIdentityProvider(
2525
}
2626
}
2727

28+
export function userTypeToTitleCase(v: UserType): string {
29+
switch (v) {
30+
case UserType.Government:
31+
case UserType.Admin:
32+
return "Public Sector Employee";
33+
case UserType.Vendor:
34+
return "Vendor";
35+
}
36+
}
37+
2838
export function gitHubProfileLink(username: string): string {
2939
return `https://github.com/${username}`;
3040
}

0 commit comments

Comments
 (0)