@@ -2,7 +2,6 @@ import React, { useMemo, useState, useCallback } from 'react';
22import { Field , TextInput , Box , Skeleton , ToggleSwitch , Icon , TextAreaInput , MultiSelectFiltered , Margins , Button , Divider } from '@rocket.chat/fuselage' ;
33
44import { useTranslation } from '../../contexts/TranslationContext' ;
5- import { useEndpointData } from '../../hooks/useEndpointData' ;
65import { useEndpointDataExperimental , ENDPOINT_STATES } from '../../hooks/useEndpointDataExperimental' ;
76import { useEndpointAction } from '../../hooks/useEndpointAction' ;
87import { useEndpointUpload } from '../../hooks/useEndpointUpload' ;
@@ -14,10 +13,10 @@ import VerticalBar from '../../components/basic/VerticalBar';
1413
1514export function EditUserWithData ( { userId, ...props } ) {
1615 const t = useTranslation ( ) ;
17- const roleData = useEndpointData ( 'roles.list' , '' ) || { } ;
16+ const { data : roleData , state : roleState , error : roleError } = useEndpointDataExperimental ( 'roles.list' , '' ) || { } ;
1817 const { data, state, error } = useEndpointDataExperimental ( 'users.info' , useMemo ( ( ) => ( { userId } ) , [ userId ] ) ) ;
1918
20- if ( state === ENDPOINT_STATES . LOADING ) {
19+ if ( [ state , roleState ] . includes ( ENDPOINT_STATES . LOADING ) ) {
2120 return < Box w = 'full' pb = 'x24' { ...props } >
2221 < Skeleton mbe = 'x4' />
2322 < Skeleton mbe = 'x8' />
@@ -28,7 +27,7 @@ export function EditUserWithData({ userId, ...props }) {
2827 </ Box > ;
2928 }
3029
31- if ( error ) {
30+ if ( error || roleError ) {
3231 return < Box mbs = 'x16' { ...props } > { t ( 'User_not_found' ) } </ Box > ;
3332 }
3433
@@ -106,7 +105,7 @@ export function EditUser({ data, roles, ...props }) {
106105 const testEqual = ( a , b ) => a === b || ! ( a || b ) ;
107106 const handleChange = ( field , currentValue , getValue = ( e ) => e . currentTarget . value , areEqual = testEqual ) => ( e ) => setNewData ( { ...newData , [ field ] : areEqual ( getValue ( e ) , currentValue ) ? null : getValue ( e ) } ) ;
108107
109- const availableRoles = roles . map ( ( { _id, description } ) => [ _id , description || _id ] ) ;
108+ const availableRoles = roles . map ( ( { _id, description } ) => [ _id , description || _id ] ) ; // memo
110109 const selectedRoles = newData . roles ?? data . roles ;
111110 const name = newData . name ?? data . name ?? '' ;
112111 const username = newData . username ?? data . username ;
@@ -182,8 +181,10 @@ export function EditUser({ data, roles, ...props }) {
182181 </ Field . Row >
183182 </ Field >
184183 < Divider />
185- < Box fontScale = 's2' > { t ( 'Custom_Fields' ) } </ Box >
186- < CustomFieldsForm customFieldsData = { customFieldsData } setCustomFieldsData = { setCustomFieldsData } />
184+ { customFieldsData && < >
185+ < Box fontScale = 's2' > { t ( 'Custom_Fields' ) } </ Box >
186+ < CustomFieldsForm customFieldsData = { customFieldsData } setCustomFieldsData = { setCustomFieldsData } />
187+ </ > }
187188 < Field >
188189 < Field . Row >
189190 < Box display = 'flex' flexDirection = 'row' justifyContent = 'space-between' w = 'full' >
0 commit comments