@salesforcedevs/dx-components 0.59.0-avatar-button-2 → 0.59.0-avatar-button-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules/dx/avatarButton/avatarButton.css +0 -4
- package/src/modules/dx/avatarButton/avatarButton.html +5 -1
- package/src/modules/dx/avatarButton/avatarButton.ts +21 -17
- package/src/modules/dx/header/header.html +3 -1
- package/src/modules/dx/header/header.ts +4 -0
- package/src/modules/dxHelpers/commonHeader/commonHeader.css +4 -2
package/package.json
CHANGED
|
@@ -21,7 +21,11 @@
|
|
|
21
21
|
<a href="#" class="inline-link">Switch account</a>
|
|
22
22
|
|
|
|
23
23
|
-->
|
|
24
|
-
<a
|
|
24
|
+
<a
|
|
25
|
+
href="#"
|
|
26
|
+
onclick={handleComponentLogout}
|
|
27
|
+
class="inline-link"
|
|
28
|
+
>
|
|
25
29
|
Logout
|
|
26
30
|
</a>
|
|
27
31
|
</div>
|
|
@@ -40,7 +40,7 @@ export default class AvatarButton extends LightningElement {
|
|
|
40
40
|
|
|
41
41
|
connectedCallback() {
|
|
42
42
|
window.addEventListener("tbid-login", this.handleSsoLogin);
|
|
43
|
-
window.addEventListener("tbid-logout", this.
|
|
43
|
+
window.addEventListener("tbid-logout", this.handleSsoLogout);
|
|
44
44
|
|
|
45
45
|
// Whenever this component is added to the DOM, immediately request user info; if the user is logged in
|
|
46
46
|
// and we receive the info, this component will display the avatar UI; otherwise, it will display the login
|
|
@@ -50,29 +50,33 @@ export default class AvatarButton extends LightningElement {
|
|
|
50
50
|
|
|
51
51
|
disconnectedCallback() {
|
|
52
52
|
window.removeEventListener("tbid-login", this.handleSsoLogin);
|
|
53
|
-
window.removeEventListener("tbid-logout", this.
|
|
53
|
+
window.removeEventListener("tbid-logout", this.handleSsoLogout);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// This
|
|
57
|
-
private
|
|
56
|
+
// This handles logout from within this component, rather than from SSO via the SFIDWidget.
|
|
57
|
+
private handleLogout = async (isSsoLogout: boolean) => {
|
|
58
|
+
this._didReceiveUserInfo = false;
|
|
59
|
+
this.isLoading = false;
|
|
60
|
+
this.updateAvatarWithUserInfo({}); // clear old info
|
|
61
|
+
|
|
62
|
+
fetch(`${TBID_API_LOGOUT_URL}?isSsoLogout=${isSsoLogout}`); // no need to await this
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
|
|
66
|
+
private handleSsoLogin = (event: Event) => {
|
|
58
67
|
const userInfo = (event as CustomEvent).detail;
|
|
59
68
|
if (userInfo) {
|
|
60
69
|
this.updateAvatarWithUserInfo(userInfo);
|
|
61
70
|
this._didReceiveUserInfo = true;
|
|
62
71
|
}
|
|
63
|
-
}
|
|
72
|
+
};
|
|
64
73
|
|
|
65
|
-
// This
|
|
66
|
-
|
|
67
|
-
private async handleLogout() {
|
|
68
|
-
this._didReceiveUserInfo = false;
|
|
69
|
-
this.isLoading = false;
|
|
70
|
-
this.updateAvatarWithUserInfo({}); // clear old info
|
|
74
|
+
// This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
|
|
75
|
+
private handleSsoLogout = this.handleLogout.bind(this, true);
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
}
|
|
77
|
+
private handleComponentLogout = this.handleLogout.bind(this, false);
|
|
74
78
|
|
|
75
|
-
private updateAvatarWithUserInfo(userInfo: any) {
|
|
79
|
+
private updateAvatarWithUserInfo = (userInfo: any) => {
|
|
76
80
|
if (!userInfo) {
|
|
77
81
|
return;
|
|
78
82
|
}
|
|
@@ -82,9 +86,9 @@ export default class AvatarButton extends LightningElement {
|
|
|
82
86
|
this.userInfo.lastName = userInfo.family_name;
|
|
83
87
|
this.userInfo.username = userInfo.preferred_username;
|
|
84
88
|
// TODO: Consider displaying initials if no photo. Is there always a photo?
|
|
85
|
-
}
|
|
89
|
+
};
|
|
86
90
|
|
|
87
|
-
private async
|
|
91
|
+
private requestUserInfo = async () => {
|
|
88
92
|
this.isLoading = true;
|
|
89
93
|
|
|
90
94
|
try {
|
|
@@ -101,5 +105,5 @@ export default class AvatarButton extends LightningElement {
|
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
this.isLoading = false;
|
|
104
|
-
}
|
|
108
|
+
};
|
|
105
109
|
}
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
onstatechange={handleStateChange}
|
|
20
20
|
></dx-header-search>
|
|
21
21
|
</div>
|
|
22
|
-
<
|
|
22
|
+
<div if:true={showTbidLogin} class="header-tbid-login">
|
|
23
|
+
<dx-avatar-button></dx-avatar-button>
|
|
24
|
+
</div>
|
|
23
25
|
<div if:true={showSignup} class="header-login-signup">
|
|
24
26
|
<dx-button
|
|
25
27
|
aria-label="Sign Up For Salesforce Developer Edition"
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { HeaderBase } from "dxBaseElements/headerBase";
|
|
2
2
|
|
|
3
3
|
export default class Header extends HeaderBase {
|
|
4
|
+
private get showTbidLogin(): boolean {
|
|
5
|
+
return this.showSignup;
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
private get showSignup(): boolean {
|
|
5
9
|
return this.signupLink
|
|
6
10
|
? (this.mobile && !this.isSearchOpen) || !this.mobile
|
|
@@ -109,12 +109,14 @@ header.state-show-mobile-nav .header_l2_group-nav_overflow {
|
|
|
109
109
|
margin-left: var(--dx-g-spacing-sm);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
.header-login-signup
|
|
112
|
+
.header-login-signup,
|
|
113
|
+
.header-tbid-login {
|
|
113
114
|
display: flex;
|
|
114
115
|
align-items: center;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
.header-login-signup dx-button
|
|
118
|
+
.header-login-signup dx-button,
|
|
119
|
+
.header-tbid-login dx-avatar-button {
|
|
118
120
|
margin-left: var(--dx-g-spacing-smd);
|
|
119
121
|
}
|
|
120
122
|
|