From 47e63d80b66b3eb1d807b3afc8a14fa0ddfff5bd Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Wed, 14 Jun 2023 15:56:26 -0300 Subject: [PATCH] chore(meteor): Replace `useEndpointData` in favor of `useQuery` in `UserCard` (#29477) Co-authored-by: Douglas Fabris <27704687+dougfabris@users.noreply.github.com> --- .../views/room/UserCard/UserCardWithData.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/apps/meteor/client/views/room/UserCard/UserCardWithData.tsx b/apps/meteor/client/views/room/UserCard/UserCardWithData.tsx index b9c701cc442..cf43ff90d16 100644 --- a/apps/meteor/client/views/room/UserCard/UserCardWithData.tsx +++ b/apps/meteor/client/views/room/UserCard/UserCardWithData.tsx @@ -5,12 +5,12 @@ import { useSetting, useRolesDescription } from '@rocket.chat/ui-contexts'; import type { ReactElement, UIEvent } from 'react'; import React, { useMemo, useRef } from 'react'; +import { getUserDisplayName } from '../../../../lib/getUserDisplayName'; import { Backdrop } from '../../../components/Backdrop'; import LocalTime from '../../../components/LocalTime'; import UserCard from '../../../components/UserCard'; import { ReactiveUserStatus } from '../../../components/UserStatus'; -import { AsyncStatePhase } from '../../../hooks/useAsyncState'; -import { useEndpointData } from '../../../hooks/useEndpointData'; +import { useUserInfoQuery } from '../../../hooks/useUserInfoQuery'; import { useActionSpread } from '../../hooks/useActionSpread'; import { useUserInfoActions } from '../hooks/useUserInfoActions'; @@ -25,21 +25,18 @@ type UserCardWithDataProps = { const UserCardWithData = ({ username, target, rid, open, onClose }: UserCardWithDataProps): ReactElement => { const ref = useRef(target); const getRoles = useRolesDescription(); - const showRealNames = useSetting('UI_Use_Real_Name'); + const showRealNames = Boolean(useSetting('UI_Use_Real_Name')); - const query = useMemo(() => ({ username }), [username]); - const { value: data, phase: state } = useEndpointData('/v1/users.info', { params: query }); + const { data, isLoading } = useUserInfoQuery({ username }); ref.current = target; - const isLoading = state === AsyncStatePhase.LOADING; - const user = useMemo(() => { const defaultValue = isLoading ? undefined : null; const { _id, - name = username, + name, roles = defaultValue, statusText = defaultValue, bio = defaultValue, @@ -50,7 +47,7 @@ const UserCardWithData = ({ username, target, rid, open, onClose }: UserCardWith return { _id, - name: showRealNames ? name : username, + name: getUserDisplayName(name, username, showRealNames), username, roles: roles && getRoles(roles).map((role, index) => {role}), bio,