@salesforcedevs/dx-components 1.2.2-avatar-button-4 → 1.2.2-avatar-button-6

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": "1.2.2-avatar-button-4",
3
+ "version": "1.2.2-avatar-button-6",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -17,6 +17,7 @@
17
17
  "classnames": "^2.2.6",
18
18
  "coveo-search-ui": "^2.10082.5",
19
19
  "debounce": "^1.2.0",
20
+ "js-cookie": "^3.0.1",
20
21
  "lodash.get": "^4.4.2",
21
22
  "lodash.kebabcase": "^4.1.1",
22
23
  "microtip": "0.2.2",
@@ -25,6 +26,7 @@
25
26
  "devDependencies": {
26
27
  "@types/classnames": "^2.2.10",
27
28
  "@types/debounce": "^1.2.0",
29
+ "@types/js-cookie": "^3.0.2",
28
30
  "@types/lodash.get": "^4.4.6",
29
31
  "@types/lodash.kebabcase": "^4.1.7",
30
32
  "@types/vimeo__player": "^2.16.2"
@@ -1,4 +1,5 @@
1
1
  import { api, LightningElement } from "lwc";
2
+ import Cookies from 'js-cookie';
2
3
  import { track } from "dxUtils/analytics";
3
4
 
4
5
  // TODO: move to environment variable
@@ -88,34 +89,15 @@ export default class AvatarButton extends LightningElement {
88
89
  }
89
90
 
90
91
  connectedCallback() {
91
- const searchParams = new URLSearchParams(window.location.search);
92
+ const isLoginSuccessRedirect = Cookies.get('tbidLoginSuccess') === 'true';
92
93
 
93
- if (searchParams.get("loginSuccess") === "true") {
94
+ if (isLoginSuccessRedirect) {
94
95
  this.isLoading = true;
95
- // clear the query param
96
- searchParams.delete("loginSuccess");
97
- window.history.replaceState(
98
- null,
99
- "",
100
- `${window.location.pathname}${
101
- window.location.hash
102
- }${searchParams.toString()}`
103
- );
96
+ Cookies.remove('tbidLoginSuccess'); // cleanup
104
97
  }
105
98
 
106
99
  window.addEventListener("tbid-login", this.handleSsoLogin);
107
100
  window.addEventListener("tbid-logout", this.handleSsoLogout);
108
- }
109
-
110
- disconnectedCallback() {
111
- window.removeEventListener("tbid-login", this.handleSsoLogin);
112
- window.removeEventListener("tbid-logout", this.handleSsoLogout);
113
- }
114
-
115
- renderedCallback() {
116
- if (this._hasRendered) {
117
- return;
118
- }
119
101
 
120
102
  const isWidgetDisabled = window.SFIDWidget?.disabled;
121
103
  const isWidgetLoggedIn = window.SFIDWidget?.openid_response;
@@ -133,21 +115,24 @@ export default class AvatarButton extends LightningElement {
133
115
  setTimeout(() => {
134
116
  if (!window.SFIDWidget?.openid_response) {
135
117
  // this.trackLogin(); TODO: track only clicks
136
- this.platformEventsSubscribe();
137
118
  this.requestUserInfo();
138
119
  }
139
120
  }, 1000);
140
121
  } else {
141
122
  if (this.isLoading) {
142
123
  // This was a login.
143
- console.log("Subscribing to platform events!");
144
- this.platformEventsSubscribe();
145
124
  // this.trackLogin(); TODO: track only clicks
146
125
  }
147
126
  this.requestUserInfo();
148
127
  }
149
128
  }
150
129
 
130
+ disconnectedCallback() {
131
+ window.removeEventListener("tbid-login", this.handleSsoLogin);
132
+ window.removeEventListener("tbid-logout", this.handleSsoLogout);
133
+ this.teardownEventSource();
134
+ }
135
+
151
136
  private handleUserDataChange = ({ data }: EventSourceEvent) => {
152
137
  let parsedEventData: any;
153
138
 
@@ -199,14 +184,11 @@ export default class AvatarButton extends LightningElement {
199
184
  PlatformEventsType.UserMerge,
200
185
  this.handleSsoLogout
201
186
  );
202
- if (this.eventSource.readyState !== 2 /* CLOSED */) {
203
- this.eventSource.close();
204
- }
187
+ this.eventSource.close();
205
188
  this.eventSource = undefined;
206
189
  };
207
190
 
208
191
  private platformEventsSubscribe = () => {
209
- console.log("platform events subscribe");
210
192
  this.teardownEventSource();
211
193
  this.setupEventSource();
212
194
  };
@@ -348,6 +330,9 @@ export default class AvatarButton extends LightningElement {
348
330
  const userInfoRes = await fetch(TBID_API_USERINFO_URL);
349
331
 
350
332
  if (userInfoRes.ok) {
333
+ if (!this.eventSource) {
334
+ this.setupEventSource();
335
+ }
351
336
  const userInfo = await userInfoRes.json();
352
337
  this.updateAvatarWithUserInfo(userInfo);
353
338
  this._didReceiveUserInfo = true;