@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.59.0-avatar-button-2",
3
+ "version": "0.59.0-avatar-button-5",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -28,10 +28,6 @@
28
28
  width: var(--dx-g-spacing-2xl);
29
29
  }
30
30
 
31
- .login-control {
32
- margin-left: var(--dx-g-spacing-smd);
33
- }
34
-
35
31
  .login-container {
36
32
  padding: 16px;
37
33
  }
@@ -21,7 +21,11 @@
21
21
  <a href="#" class="inline-link">Switch account</a>
22
22
  &nbsp;&nbsp;|&nbsp;&nbsp;
23
23
  -->
24
- <a href="#" onclick={handleLogout} class="inline-link">
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.handleLogout);
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.handleLogout);
53
+ window.removeEventListener("tbid-logout", this.handleSsoLogout);
54
54
  }
55
55
 
56
- // This will only be called for "seamless SSO" login by the embedded login widget (SFWidget) on the website, if it exists.
57
- private handleSsoLogin(event: Event) {
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 can be called *either* by the embedded login widget (SFWidget) on the website, if it exists,
66
- // in the event of "seamless SSO" logout, *or* by a user clicking logout on this component.
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
- fetch(TBID_API_LOGOUT_URL); // no need to await this
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 requestUserInfo() {
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
- <dx-avatar-button></dx-avatar-button>
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