mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
fix(console): remove username admin tag (#2973)
This commit is contained in:
parent
ece866db7c
commit
b87b9def62
1 changed files with 4 additions and 10 deletions
|
@ -1,5 +1,4 @@
|
|||
import type { UserWithRoleNames } from '@logto/schemas';
|
||||
import { UserRole } from '@logto/schemas';
|
||||
import type { User } from '@logto/schemas';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link } from 'react-router-dom';
|
||||
import useSWR from 'swr';
|
||||
|
@ -14,29 +13,24 @@ type Props = {
|
|||
};
|
||||
|
||||
const UserName = ({ userId, isLink = false }: Props) => {
|
||||
const { data, error } = useSWR<UserWithRoleNames, RequestError>(`/api/users/${userId}`);
|
||||
const { data, error } = useSWR<User, RequestError>(`/api/users/${userId}`);
|
||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||
|
||||
const isLoading = !data && !error;
|
||||
const name = data?.name ?? t('users.unnamed');
|
||||
|
||||
const isAdmin = data?.roleNames.includes(UserRole.Admin);
|
||||
|
||||
if (isLoading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.userName}>
|
||||
{isLink && !isAdmin ? (
|
||||
{isLink ? (
|
||||
<Link to={`/users/${userId}`} target="_blank" className={styles.link}>
|
||||
{name}
|
||||
</Link>
|
||||
) : (
|
||||
<span>
|
||||
{name}
|
||||
{isAdmin && <> ({t('admin_user')})</>}
|
||||
</span>
|
||||
<span>{name}</span>
|
||||
)}
|
||||
<span className={styles.userId}>{userId}</span>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue