Skip to content

Commit 5606784

Browse files
gavinbarronmusale
andauthored
fix: rework parameter passing to click events in contact card section (#1809)
* fix: rework parameter passing to click events in contact card section * Adding a story to demonstrate the anonymous use of mgt-person-card Co-authored-by: Musale Martin <[email protected]>
1 parent 590828d commit 5606784

File tree

2 files changed

+54
-32
lines changed

2 files changed

+54
-32
lines changed

packages/mgt-components/src/components/mgt-person-card/sections/mgt-person-card-contact/mgt-person-card-contact.ts

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { strings } from './strings';
1919
/**
2020
* Represents a contact part and its metadata
2121
*
22-
* @interface IContectPart
22+
* @interface IContactPart
2323
*/
2424
interface IContactPart {
2525
// tslint:disable-next-line: completed-docs
@@ -34,6 +34,8 @@ interface IContactPart {
3434
showCompact: boolean;
3535
}
3636

37+
type Protocol = 'mailto:' | 'tel:';
38+
3739
/**
3840
* The contact details subsection of the person card
3941
*
@@ -73,49 +75,49 @@ export class MgtPersonCardContact extends BasePersonCardSection {
7375
return !!availableParts.length;
7476
}
7577

76-
private _person: User;
78+
private _person?: User;
7779

7880
// tslint:disable: object-literal-sort-keys
79-
private _contactParts = {
81+
private _contactParts: Record<string, IContactPart> = {
8082
email: {
8183
icon: getSvg(SvgIcon.Email, '#929292'),
82-
onClick: () => this.sendEmail(),
84+
onClick: () => this.sendEmail(getEmailFromGraphEntity(this._person)),
8385
showCompact: true,
8486
title: 'Email'
85-
} as IContactPart,
87+
},
8688
chat: {
8789
icon: getSvg(SvgIcon.Chat, '#929292'),
88-
onClick: () => this.sendChat(),
90+
onClick: () => this.sendChat(this._person?.userPrincipalName),
8991
showCompact: false,
9092
title: 'Teams'
91-
} as IContactPart,
93+
},
9294
businessPhone: {
9395
icon: getSvg(SvgIcon.CellPhone, '#929292'),
94-
onClick: () => this.sendCall('businessPhone'),
96+
onClick: () => this.sendCall(this._person?.businessPhones?.length > 0 ? this._person.businessPhones[0] : null),
9597
showCompact: true,
9698
title: 'Business Phone'
97-
} as IContactPart,
99+
},
98100
cellPhone: {
99101
icon: getSvg(SvgIcon.CellPhone, '#929292'),
100-
onClick: () => this.sendCall('cellPhone'),
102+
onClick: () => this.sendCall(this._person?.mobilePhone),
101103
showCompact: true,
102104
title: 'Mobile Phone'
103-
} as IContactPart,
105+
},
104106
department: {
105107
icon: getSvg(SvgIcon.Department, '#929292'),
106108
showCompact: false,
107109
title: 'Department'
108-
} as IContactPart,
110+
},
109111
title: {
110112
icon: getSvg(SvgIcon.Person, '#929292'),
111113
showCompact: false,
112114
title: 'Title'
113-
} as IContactPart,
115+
},
114116
officeLocation: {
115117
icon: getSvg(SvgIcon.OfficeLocation, '#929292'),
116118
showCompact: true,
117119
title: 'Office Location'
118-
} as IContactPart
120+
}
119121
};
120122
// tslint:enable: object-literal-sort-keys
121123

@@ -286,19 +288,27 @@ export class MgtPersonCardContact extends BasePersonCardSection {
286288
}
287289
}
288290

291+
private sendLink(protocol: Protocol, resource: string): void {
292+
if (resource) {
293+
window.open(`${protocol}${resource}`, '_blank', 'noreferrer');
294+
} else {
295+
console.error(`Target resource for ${protocol} link was not provided: resource: ${resource}`);
296+
}
297+
}
298+
289299
/**
290300
* Send a chat message to the user
291301
*
292302
* @protected
293303
* @memberof MgtPersonCardContact
294304
*/
295-
protected sendChat(): void {
296-
const chat = this._contactParts.chat.value;
297-
if (!chat) {
305+
protected sendChat(upn: string): void {
306+
if (!upn) {
307+
console.error("Can't send chat when upn is not provided");
298308
return;
299309
}
300310

301-
const url = `https://teams.microsoft.com/l/chat/0/0?users=${chat}`;
311+
const url = `https://teams.microsoft.com/l/chat/0/0?users=${upn}`;
302312
const openWindow = () => window.open(url, '_blank', 'noreferrer');
303313

304314
if (TeamsHelper.isAvailable) {
@@ -318,11 +328,8 @@ export class MgtPersonCardContact extends BasePersonCardSection {
318328
* @protected
319329
* @memberof MgtPersonCardContact
320330
*/
321-
protected sendEmail(): void {
322-
const email = this._contactParts.email.value;
323-
if (email) {
324-
window.open('mailto:' + email, '_blank', 'noreferrer');
325-
}
331+
protected sendEmail(email: string): void {
332+
this.sendLink('mailto:', email);
326333
}
327334

328335
/**
@@ -331,13 +338,7 @@ export class MgtPersonCardContact extends BasePersonCardSection {
331338
* @protected
332339
* @memberof MgtPersonCardContact
333340
*/
334-
protected sendCall(phone): void {
335-
const cellPhone = this._contactParts.cellPhone.value;
336-
const businessPhone = this._contactParts.businessPhone.value;
337-
if (phone === 'cellPhone') {
338-
window.open('tel:' + cellPhone, '_blank', 'noreferrer');
339-
} else if (phone === 'businessPhone') {
340-
window.open('tel:' + businessPhone, '_blank', 'noreferrer');
341-
}
342-
}
341+
protected sendCall = (phone: string): void => {
342+
this.sendLink('tel:', phone);
343+
};
343344
}

stories/components/personCard/personCard.a.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,24 @@ export const localization = () => html`
8585
};
8686
</script>
8787
`;
88+
89+
export const AnonymousDisplay = () => html`
90+
<div style="margin-bottom: 10px">
91+
<strong>Note:</strong> this story forces an anonymous context and explicity sets the user being displayed.<br />
92+
Refer to the JavaScript tab for setup details.
93+
</div>
94+
<mgt-person-card class="anonymous-display"></mgt-person-card>
95+
<script>
96+
import { Providers, Msal2Provider } from './mgt.storybook.js';
97+
Providers.globalProvider = new Msal2Provider({ clientId: "fake" });
98+
const personCard = document.querySelector('.anonymous-display');
99+
personCard.personDetails = {
100+
displayName: 'Megan Bowen',
101+
jobTitle: 'CEO',
102+
userPrincipalName: '[email protected]',
103+
104+
businessPhones: ['423-555-0120'],
105+
mobilePhone: '424-555-0130',
106+
};
107+
</script>
108+
`;

0 commit comments

Comments
 (0)