Skip to content

Commit

Permalink
fix: #1540 add dashes to null name (#1616)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigyu authored Oct 3, 2024
1 parent 6b507c6 commit 051981c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/src/components/UserSummaryCard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Card from 'primevue/card';
import { AppActlApiService } from '@/services/ApiServiceFactory';
import { DEFAULT_COL_SIZE } from '@/components/UserSummaryCard/constants';
import CardTextCol from '@/components/CardTextCol/index.vue';
import { formatFullName } from '@/utils/UserUtils';
const props = defineProps<{
userId: string; // Fam User ID
Expand Down Expand Up @@ -41,7 +42,7 @@ const userQuery = useQuery(
:description="userQuery.data.value?.user_name" :is-loading="userQuery.isFetching.value" />

<CardTextCol :class="DEFAULT_COL_SIZE" id="full-name" label="Full name"
:description="`${userQuery.data.value?.first_name} ${userQuery.data.value?.last_name}`"
:description="formatFullName(userQuery.data.value?.first_name, userQuery.data.value?.last_name)"
:is-loading="userQuery.isFetching.value" />

<CardTextCol :class="DEFAULT_COL_SIZE" id="domain" label="Domain"
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/utils/UserUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PLACE_HOLDER } from "@/constants/constants";

/**
* Formats a user's full name and ID (userName) into a readable string.
* If both first and last names are missing, it returns the ID only.
Expand Down Expand Up @@ -31,3 +33,35 @@ export const formatUserNameAndId = (

return `${firstName} ${lastName} (${userName})`;
}

/**
* Formats a user's full name into a readable string.
* If both first and last names are missing, it returns an empty string.
* If either the first or last name is missing, it formats the remaining name.
* If both names are present, it combines them.
*
* @param {string} [firstName] - The optional first name of the user. Can be null.
* @param {string} [lastName] - The optional last name of the user. Can be null.
* @returns {string} - The formatted string in the format: "FirstName LastName",
* or just "LastName" if the first name is missing,
* or "FirstName" if the last name is missing,
* or a PLACE_HOLDER string if both names are missing.
*/
export const formatFullName = (
firstName?: string | null,
lastName?: string | null,
): string => {
if (!firstName && !lastName) {
return PLACE_HOLDER;
}

if (!firstName) {
return lastName!;
}

if (!lastName) {
return firstName!;
}

return `${firstName} ${lastName}`;
}

0 comments on commit 051981c

Please sign in to comment.