0
Fork 0
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:
wangsijie 2023-01-18 15:56:47 +08:00 committed by GitHub
parent ece866db7c
commit b87b9def62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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>