From 688e894ef18e96d16f7cca948e5f1335b68d459a Mon Sep 17 00:00:00 2001 From: JKaypa Date: Mon, 2 Sep 2024 16:17:53 -0500 Subject: [PATCH 1/5] OV-133: + get full name from store and handle initials --- .../user-card/components/user-avatar.tsx | 11 +++--- .../user-card/helpers/get-initials.helper.ts | 12 ++++++ .../components/user-card/helpers/helpers.ts | 1 + .../users/components/user-card/user-card.tsx | 39 ++++++++++++------- 4 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 frontend/src/bundles/users/components/user-card/helpers/get-initials.helper.ts create mode 100644 frontend/src/bundles/users/components/user-card/helpers/helpers.ts diff --git a/frontend/src/bundles/users/components/user-card/components/user-avatar.tsx b/frontend/src/bundles/users/components/user-card/components/user-avatar.tsx index 9ef4a435d..32e91fcd8 100644 --- a/frontend/src/bundles/users/components/user-card/components/user-avatar.tsx +++ b/frontend/src/bundles/users/components/user-card/components/user-avatar.tsx @@ -1,10 +1,11 @@ import { Circle } from '~/bundles/common/components/components.js'; +import { useAppSelector } from '~/bundles/common/hooks/hooks.js'; -type Properties = { - username: string; -}; +import { getInitials } from '../helpers/helpers.js'; -const UserAvatar: React.FC = ({ username }) => { +const UserAvatar: React.FC = () => { + const { user } = useAppSelector(({ auth }) => auth); + const initials = getInitials(user?.fullName); return ( = ({ username }) => { borderColor="brand.secondary.900" color="brand.secondary.900" > - {username} + {initials} ); }; diff --git a/frontend/src/bundles/users/components/user-card/helpers/get-initials.helper.ts b/frontend/src/bundles/users/components/user-card/helpers/get-initials.helper.ts new file mode 100644 index 000000000..6ed062412 --- /dev/null +++ b/frontend/src/bundles/users/components/user-card/helpers/get-initials.helper.ts @@ -0,0 +1,12 @@ +const getInitials = (fullName: string | undefined): string => { + if (fullName) { + const splittedName = fullName.trim().split(/\s+/); + const firstInitial = splittedName[0]?.charAt(0).toUpperCase(); + const secondInitial = splittedName[1]?.charAt(0).toUpperCase() ?? ''; + + return `${firstInitial}${secondInitial}`; + } + return 'FN'; +}; + +export { getInitials }; diff --git a/frontend/src/bundles/users/components/user-card/helpers/helpers.ts b/frontend/src/bundles/users/components/user-card/helpers/helpers.ts new file mode 100644 index 000000000..3030e7966 --- /dev/null +++ b/frontend/src/bundles/users/components/user-card/helpers/helpers.ts @@ -0,0 +1 @@ +export { getInitials } from './get-initials.helper.js'; diff --git a/frontend/src/bundles/users/components/user-card/user-card.tsx b/frontend/src/bundles/users/components/user-card/user-card.tsx index 60aefd861..4fb14a60c 100644 --- a/frontend/src/bundles/users/components/user-card/user-card.tsx +++ b/frontend/src/bundles/users/components/user-card/user-card.tsx @@ -4,24 +4,33 @@ import { Text, VStack, } from '~/bundles/common/components/components.js'; +import { useAppSelector } from '~/bundles/common/hooks/hooks.js'; import { UserAvatar } from './components/user-avatar.js'; -const UserCard: React.FC = () => ( - - { + const { user } = useAppSelector(({ auth }) => auth); + + return ( + - {/* TODO: replace Circle and Text content with dynamic values */} - - Firstname Lastname - -