Skip to content

Commit

Permalink
fix(components): enhance user name handling for multiple surnames
Browse files Browse the repository at this point in the history
- Add support for two surnames in `getUserFullName` function
- Refactor `AvatarsGroup` component to handle new name format
- Refactor `UserDisplayItem` component to handle new name format

Ticket: task/Transversal-176
Reviewed-by: @MIGUELez11
Refs: #209
  • Loading branch information
fermarinsanchez authored Nov 22, 2024
1 parent c533c07 commit 10874bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/components/src/helpers/getUserFullName.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
function getUserFullName(user) {
function getUserFullName(user, options = { singleSurname: false }) {
const name = user.name?.trim() ?? null;
const surname = user.surnames?.trim() ?? null;
const secondSurname = user.secondSurname?.trim() ?? null;

const surnames = [secondSurname, surname].filter(Boolean).join(' ');
if (options.singleSurname && name && surname) {
const surnameParts = surname.split(' ');
const firstSurname = surnameParts[0];
return `${firstSurname}, ${name}`;
}

const surnames = [surname, secondSurname].filter(Boolean).join(', ');
const fullName = [surnames, name].filter(Boolean).join(', ');

return fullName.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Box } from '../../layout/Box';
import { Avatar } from '../Avatar/Avatar';
import { AvatarsGroupStyles } from './AvatarsGroup.styles';
import { AVATARS_GROUP_DEFAULT_PROPS, AVATARS_GROUP_PROP_TYPES } from './AvatarsGroup.constants';
import { getUserFullName } from '../../helpers';

const AvatarsGroup = ({
data,
Expand Down Expand Up @@ -35,7 +36,7 @@ const AvatarsGroup = ({
if (item.surnames && item.name) {
return {
...item,
fullName: `${item.surnames}, ${item.name}`,
fullName: getUserFullName(item, { singleSurname: true }),
};
}
return item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const UserDisplayItem = (properties) => {
return name;
}, [name, surnames, variant]);

const userFullName = getUserFullName(properties);
const userFullName = getUserFullName(properties, { singleSurname: true });

const Icon = (
<>
Expand Down

0 comments on commit 10874bd

Please sign in to comment.