@@ -15,6 +15,7 @@ import FieldUserHoverCard, { IFieldUserHoverCardProps } from './FieldUserHoverCa
15
15
import * as appInsights from '../../../common/appInsights' ;
16
16
17
17
import * as strings from 'ControlStrings' ;
18
+ import { SPHelper } from '../../../common/utilities' ;
18
19
19
20
export interface IFieldUserRendererProps extends IFieldRendererProps {
20
21
/**
@@ -173,18 +174,18 @@ export class FieldUserRenderer extends React.Component<IFieldUserRendererProps,
173
174
< li className = { styles . section } >
174
175
< div className = { styles . header } > { strings . Contact } < Icon iconName = "ChevronRight" className = { styles . chevron } /> </ div >
175
176
< div className = { styles . contactItem } >
176
- < Icon iconName = { 'Mail' } />
177
+ < Icon iconName = { 'Mail' } />
177
178
< Link className = { styles . content } title = { user . email } href = { `mailto:${ user . email } ` } target = { '_self' } > { user . email } </ Link >
178
179
</ div >
179
180
{ user . workPhone &&
180
181
< div className = { styles . contactItem } >
181
- < Icon iconName = { 'Phone' } />
182
+ < Icon iconName = { 'Phone' } />
182
183
< Link className = { styles . content } title = { user . workPhone } href = { `tel:${ user . workPhone } ` } target = { '_self' } > { user . workPhone } </ Link >
183
184
</ div >
184
185
}
185
186
{ user . cellPhone &&
186
187
< div className = { styles . contactItem } >
187
- < Icon iconName = { 'Phone' } />
188
+ < Icon iconName = { 'Phone' } />
188
189
< Link className = { styles . content } title = { user . cellPhone } href = { `tel:${ user . cellPhone } ` } target = { '_self' } > { user . cellPhone } </ Link >
189
190
</ div >
190
191
}
@@ -236,67 +237,61 @@ export class FieldUserRenderer extends React.Component<IFieldUserRendererProps,
236
237
/**
237
238
* Requests User Profile Properties
238
239
*/
239
- private _requestUserProfile ( user : IFieldUser , index : number ) : void {
240
+ private async _requestUserProfile ( user : IFieldUser , index : number ) : Promise < void > {
240
241
if ( this . _loadedUserProfiles [ user . id ] ) {
241
242
return ; // we've already have the profile info
242
243
}
243
244
244
245
const context : IContext = this . props . context ;
245
- let url : string ;
246
- url = context . pageContext . web . absoluteUrl ;
247
- url = GeneralHelper . trimSlash ( url ) ;
248
246
249
- url += `/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor('i%3A0%23.f%7Cmembership%7C${ user . email . replace ( '@' , '%40' ) } ')` ;
250
- context . spHttpClient . get ( url , SPHttpClient . configurations . v1 )
251
- . then ( ( response ) : Promise < any > => {
252
- return response . json ( ) ;
253
- } )
254
- . then ( ( value ) => {
255
- const mthumbStr = 'MThumb.jpg' ;
256
- const userProfileProps : IUserProfileProperties = {
257
- displayName : value . DisplayName ,
258
- email : value . Email ,
259
- jobTitle : value . Title ,
260
- userUrl : value . UserUrl ,
261
- pictureUrl : value . PictureUrl && value . PictureUrl . toString ( ) . indexOf ( mthumbStr ) === value . PictureUrl . toString ( ) . length - mthumbStr . length ? '' : value . PictureUrl //this._userImageUrl.replace('{0}', user.email)
262
- } ;
247
+ const siteUser = await SPHelper . getUserById ( parseInt ( user . id ) , context ) ;
263
248
264
- const props : IODataKeyValuePair [ ] = value . UserProfileProperties as IODataKeyValuePair [ ] ;
265
- let foundPropsCount : number = 0 ;
266
- for ( let i = 0 , len = props . length ; i < len ; i ++ ) {
267
- const prop : IODataKeyValuePair = props [ i ] ;
268
- switch ( prop . Key ) {
269
- case 'WorkPhone' :
270
- userProfileProps . workPhone = prop . Value ;
271
- foundPropsCount ++ ;
272
- break ;
273
- case 'Department' :
274
- userProfileProps . department = prop . Value ;
275
- foundPropsCount ++ ;
276
- break ;
277
- case 'SPS-SipAddress' :
278
- userProfileProps . sip = prop . Value ;
279
- foundPropsCount ++ ;
280
- break ;
281
- case 'CellPhone' :
282
- userProfileProps . cellPhone = prop . Value ;
283
- foundPropsCount ++ ;
284
- break ;
285
- }
249
+ const value = await SPHelper . getUserProperties ( siteUser . LoginName , context ) ;
286
250
287
- if ( foundPropsCount === 4 ) {
288
- break ;
289
- }
290
- }
251
+ const mthumbStr = 'MThumb.jpg' ;
252
+ const userProfileProps : IUserProfileProperties = {
253
+ displayName : value . DisplayName ,
254
+ email : value . Email ,
255
+ jobTitle : value . Title ,
256
+ userUrl : value . UserUrl ,
257
+ pictureUrl : value . PictureUrl && value . PictureUrl . toString ( ) . indexOf ( mthumbStr ) === value . PictureUrl . toString ( ) . length - mthumbStr . length ? '' : value . PictureUrl //this._userImageUrl.replace('{0}', user.email)
258
+ } ;
291
259
292
- this . _loadedUserProfiles [ user . id ] = userProfileProps ;
293
- this . setState ( ( prevState : IFieldUserRendererState , componentProps : IFieldUserRendererProps ) => {
294
- const newUsers = _ . clone < IFieldUser [ ] > ( prevState . users ) ;
295
- newUsers [ index ] = this . _getUserFromPrincipalAndProps ( this . props . users [ index ] , userProfileProps ) ;
260
+ const props : IODataKeyValuePair [ ] = value . UserProfileProperties as IODataKeyValuePair [ ] ;
261
+ let foundPropsCount : number = 0 ;
262
+ for ( let i = 0 , len = props . length ; i < len ; i ++ ) {
263
+ const prop : IODataKeyValuePair = props [ i ] ;
264
+ switch ( prop . Key ) {
265
+ case 'WorkPhone' :
266
+ userProfileProps . workPhone = prop . Value ;
267
+ foundPropsCount ++ ;
268
+ break ;
269
+ case 'Department' :
270
+ userProfileProps . department = prop . Value ;
271
+ foundPropsCount ++ ;
272
+ break ;
273
+ case 'SPS-SipAddress' :
274
+ userProfileProps . sip = prop . Value ;
275
+ foundPropsCount ++ ;
276
+ break ;
277
+ case 'CellPhone' :
278
+ userProfileProps . cellPhone = prop . Value ;
279
+ foundPropsCount ++ ;
280
+ break ;
281
+ }
296
282
297
- return { users : newUsers } ;
283
+ if ( foundPropsCount === 4 ) {
284
+ break ;
285
+ }
286
+ }
287
+
288
+ this . _loadedUserProfiles [ user . id ] = userProfileProps ;
289
+ this . setState ( ( prevState : IFieldUserRendererState , componentProps : IFieldUserRendererProps ) => {
290
+ const newUsers = _ . clone < IFieldUser [ ] > ( prevState . users ) ;
291
+ newUsers [ index ] = this . _getUserFromPrincipalAndProps ( this . props . users [ index ] , userProfileProps ) ;
298
292
299
- } ) ;
300
- } ) ;
293
+ return { users : newUsers } ;
294
+
295
+ } ) ;
301
296
}
302
297
}
0 commit comments