Fix name showing undefined in users tab and fix initials always being PC
This commit is contained in:
parent
1f9086f639
commit
e47fbf2df1
|
@ -44,6 +44,8 @@
|
||||||
$: hasGroupsLicense = $auth.user?.license.features.includes(
|
$: hasGroupsLicense = $auth.user?.license.features.includes(
|
||||||
Constants.Features.USER_GROUPS
|
Constants.Features.USER_GROUPS
|
||||||
)
|
)
|
||||||
|
$: nameLabel = getNameLabel($userFetch)
|
||||||
|
$: initials = getInitials(nameLabel, $userFetch)
|
||||||
|
|
||||||
$: allAppList = $apps
|
$: allAppList = $apps
|
||||||
.filter(x => {
|
.filter(x => {
|
||||||
|
@ -86,6 +88,38 @@
|
||||||
|
|
||||||
const userFetch = fetchData(`/api/global/users/${userId}`)
|
const userFetch = fetchData(`/api/global/users/${userId}`)
|
||||||
|
|
||||||
|
const getNameLabel = userFetch => {
|
||||||
|
const { firstName, lastName } = userFetch?.data || {}
|
||||||
|
if (!firstName && !lastName) {
|
||||||
|
return "Name unavailable"
|
||||||
|
}
|
||||||
|
let label
|
||||||
|
if (firstName) {
|
||||||
|
label = firstName
|
||||||
|
if (lastName) {
|
||||||
|
label += ` ${lastName}`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
label = lastName
|
||||||
|
}
|
||||||
|
return label
|
||||||
|
}
|
||||||
|
|
||||||
|
const getInitials = (nameLabel, userFetch) => {
|
||||||
|
if (nameLabel !== "Name unavailable") {
|
||||||
|
return nameLabel
|
||||||
|
.split(" ")
|
||||||
|
.slice(0, 2)
|
||||||
|
.map(x => x[0])
|
||||||
|
.join("")
|
||||||
|
}
|
||||||
|
const { email } = userFetch?.data || {}
|
||||||
|
if (!email) {
|
||||||
|
return "PC"
|
||||||
|
}
|
||||||
|
return email.substring(0, 2)
|
||||||
|
}
|
||||||
|
|
||||||
function getHighestRole(roles) {
|
function getHighestRole(roles) {
|
||||||
let highestRole
|
let highestRole
|
||||||
let highestRoleNumber = 0
|
let highestRoleNumber = 0
|
||||||
|
@ -186,13 +220,9 @@
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<div>
|
<div>
|
||||||
<div style="display: flex;">
|
<div style="display: flex;">
|
||||||
<Avatar size="XXL" initials="PC" />
|
<Avatar size="XXL" {initials} />
|
||||||
<div class="subtitle">
|
<div class="subtitle">
|
||||||
<Heading size="S"
|
<Heading size="S">{nameLabel}</Heading>
|
||||||
>{$userFetch?.data?.firstName +
|
|
||||||
" " +
|
|
||||||
$userFetch?.data?.lastName}</Heading
|
|
||||||
>
|
|
||||||
<Body size="XS">{$userFetch?.data?.email}</Body>
|
<Body size="XS">{$userFetch?.data?.email}</Body>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue