@salesforcedevs/dx-components 0.80.0 → 1.2.2-avatar-button-2

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.
Files changed (34) hide show
  1. package/lwc.config.json +5 -1
  2. package/package.json +3 -2
  3. package/src/assets/svg/login-widget-bg.png +0 -0
  4. package/src/modules/dx/avatarButton/avatarButton.css +129 -0
  5. package/src/modules/dx/avatarButton/avatarButton.html +155 -0
  6. package/src/modules/dx/avatarButton/avatarButton.ts +347 -0
  7. package/src/modules/dx/cardEvent/cardEvent.html +1 -2
  8. package/src/modules/dx/cardEvent/cardEvent.ts +1 -1
  9. package/src/modules/dx/cardExpanded/cardExpanded.html +1 -6
  10. package/src/modules/dx/cardExpanded/cardExpanded.ts +2 -2
  11. package/src/modules/dx/cardMinimal/cardMinimal.html +1 -6
  12. package/src/modules/dx/header/header.html +3 -0
  13. package/src/modules/dx/header/header.ts +4 -0
  14. package/src/modules/dx/logo/logo.ts +1 -1
  15. package/src/modules/dx/metadataBadge/metadataBadge.css +49 -0
  16. package/src/modules/dx/metadataBadge/metadataBadge.html +5 -0
  17. package/src/modules/dx/metadataBadge/metadataBadge.ts +24 -0
  18. package/src/modules/dx/treeItem/treeItem.html +1 -0
  19. package/src/modules/dx/treeTile/treeTile.css +17 -17
  20. package/src/modules/dx/treeTile/treeTile.html +5 -4
  21. package/src/modules/dx/treeTile/treeTile.ts +17 -3
  22. package/src/modules/dx/typeBadge/typeBadge.css +15 -56
  23. package/src/modules/dx/typeBadge/typeBadge.html +6 -0
  24. package/src/modules/dx/typeBadge/typeBadge.ts +142 -46
  25. package/src/modules/dxBaseElements/archiveCard/archiveCard.ts +2 -6
  26. package/src/modules/dxConstants/brands/brands.ts +14 -0
  27. package/src/modules/dxConstants/colors/colors.ts +14 -0
  28. package/src/modules/dxConstants/contentTypes/contentTypes.ts +10 -0
  29. package/src/modules/dxHelpers/commonHeader/commonHeader.css +4 -2
  30. package/src/modules/dxUtils/css/css.ts +10 -0
  31. package/yarn-error.log +19802 -0
  32. package/src/modules/dx/typeBadgeGroup/typeBadgeGroup.css +0 -12
  33. package/src/modules/dx/typeBadgeGroup/typeBadgeGroup.html +0 -11
  34. package/src/modules/dx/typeBadgeGroup/typeBadgeGroup.ts +0 -18
package/lwc.config.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "modules": [{ "dir": "src/modules" }],
3
3
  "expose": [
4
+ "dx/avatarButton",
4
5
  "dx/banner",
5
6
  "dx/brandThemeProvider",
6
7
  "dx/breadcrumbs",
@@ -46,6 +47,7 @@
46
47
  "dx/imageAndLabel",
47
48
  "dx/input",
48
49
  "dx/logo",
50
+ "dx/metadataBadge",
49
51
  "dx/modalDrawer",
50
52
  "dx/pagination",
51
53
  "dx/podcastHost",
@@ -68,10 +70,12 @@
68
70
  "dx/tooltip",
69
71
  "dx/tree",
70
72
  "dx/typeBadge",
71
- "dx/typeBadgeGroup",
72
73
  "dx/vimeoPlayer",
73
74
  "dxBaseElements/headerBase",
74
75
  "dxBaseElements/matchMediaElement",
76
+ "dxConstants/brands",
77
+ "dxConstants/colors",
78
+ "dxConstants/contentTypes",
75
79
  "dxHelpers/animations",
76
80
  "dxHelpers/button",
77
81
  "dxHelpers/card",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.80.0",
3
+ "version": "1.2.2-avatar-button-2",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -19,7 +19,8 @@
19
19
  "debounce": "^1.2.0",
20
20
  "lodash.get": "^4.4.2",
21
21
  "lodash.kebabcase": "^4.1.1",
22
- "microtip": "0.2.2"
22
+ "microtip": "0.2.2",
23
+ "salesforce-oauth2": "^0.2.0"
23
24
  },
24
25
  "devDependencies": {
25
26
  "@types/classnames": "^2.2.10",
@@ -0,0 +1,129 @@
1
+ :host {
2
+ --dx-c-button-custom-color: var(--dx-g-blue-vibrant-50);
3
+ --dx-c-button-custom-background: transparent;
4
+ --dx-c-button-custom-border: 1px solid transparent;
5
+ --dx-c-button-custom-color-hover: var(--dx-g-blue-vibrant-50);
6
+ --dx-c-button-custom-background-hover: var(--dx-g-cloud-blue-vibrant-90);
7
+ --dx-c-button-custom-border-hover: var(--dx-g-cloud-blue-vibrant-90);
8
+ --dx-c-slot-empty-width: max-content;
9
+ }
10
+
11
+ .avatar-small-container {
12
+ padding: 2px 0;
13
+ }
14
+
15
+ .avatar {
16
+ border-radius: 100%;
17
+ border: 2px solid #0d9dda;
18
+ }
19
+
20
+ .avatar.avatar-small {
21
+ display: block;
22
+ height: var(--dx-g-spacing-lg);
23
+ width: var(--dx-g-spacing-lg);
24
+ }
25
+
26
+ .avatar.avatar-medium {
27
+ margin-bottom: 14px;
28
+ width: var(--dx-g-spacing-2xl);
29
+ }
30
+
31
+ .login-container {
32
+ padding: 16px;
33
+ }
34
+
35
+ .login-container.logged-in {
36
+ padding-top: 68px;
37
+ }
38
+
39
+ .header-img {
40
+ left: 0;
41
+ position: absolute;
42
+ top: 0;
43
+ width: 100%;
44
+ z-index: -1;
45
+ }
46
+
47
+ .heading {
48
+ color: var(--dx-g-blue-vibrant-20);
49
+ display: block;
50
+ font-family: var(--dx-g-font-display);
51
+ font-size: var(--dx-g-text-lg);
52
+ line-height: 28px;
53
+ }
54
+
55
+ .sub-heading {
56
+ color: var(--dx-g-blue-vibrant-20);
57
+ display: block;
58
+ font-family: var(--dx-g-font-sans);
59
+ font-size: 12px;
60
+ line-height: 18px;
61
+ padding: 8px 0;
62
+ }
63
+
64
+ ul {
65
+ list-style: none;
66
+ margin: 0;
67
+ padding: 0;
68
+ }
69
+
70
+ .login-list-item {
71
+ padding-bottom: 10px;
72
+ }
73
+
74
+ .login-section ~ .login-section {
75
+ border-top: 1px solid var(--dx-g-gray-90);
76
+ margin-top: 12px;
77
+ }
78
+
79
+ .login-section-title {
80
+ color: var(--dx-g-gray-30);
81
+ display: inline-block;
82
+ font-family: var(--dx-g-font-sans);
83
+ font-size: 14px;
84
+ line-height: 20px;
85
+ padding: 20px 0 12px;
86
+ }
87
+
88
+ .login-link {
89
+ color: var(--dx-g-blue-vibrant-20);
90
+ display: block;
91
+ }
92
+
93
+ .login-link-label {
94
+ display: inline-block;
95
+ font-family: var(--dx-g-font-display);
96
+ font-size: 16px;
97
+ line-height: 24px;
98
+ }
99
+
100
+ .login-link-img {
101
+ display: inline-block;
102
+ height: 16px;
103
+ margin-left: 6px;
104
+ vertical-align: middle;
105
+ }
106
+
107
+ .login-link-icon {
108
+ display: inline-block;
109
+ margin-left: 6px;
110
+ vertical-align: baseline;
111
+ }
112
+
113
+ .login-link-blurb {
114
+ font-family: var(--dx-g-font-sans);
115
+ font-size: 14px;
116
+ line-height: 20px;
117
+ padding-top: 4px;
118
+ }
119
+
120
+ .heading-links {
121
+ color: var(--dx-g-gray-90);
122
+ font-family: var(--dx-g-font-sans);
123
+ font-size: 14px;
124
+ line-height: 20px;
125
+ }
126
+
127
+ a.inline-link {
128
+ color: var(--dx-g-blue-vibrant-50);
129
+ }
@@ -0,0 +1,155 @@
1
+ <template>
2
+ <div if:true={isLoggedIn}>
3
+ <dx-popover offset="small" width="320px" open-on-hover>
4
+ <div slot="control" class="avatar-small-container login-control">
5
+ <img src={userInfo.avatarImgSrc} class="avatar avatar-small" />
6
+ </div>
7
+ <div slot="content">
8
+ <div class="login-container logged-in">
9
+ <img
10
+ src="/assets/svg/login-widget-bg.png"
11
+ class="header-img"
12
+ />
13
+ <img
14
+ src={userInfo.avatarImgSrc}
15
+ class="avatar avatar-medium"
16
+ />
17
+ <span class="heading">{userInfo.fullName}</span>
18
+ <span class="sub-heading">{userInfo.username}</span>
19
+ <div class="heading-links">
20
+ <!--
21
+ <a href="#" class="inline-link">Switch account</a>
22
+ &nbsp;&nbsp;|&nbsp;&nbsp;
23
+ -->
24
+ <a
25
+ href="#"
26
+ onclick={handleComponentLogout}
27
+ class="inline-link"
28
+ >
29
+ Logout
30
+ </a>
31
+ </div>
32
+ <div class="login-section">
33
+ <span class="login-section-title">Trailblazer.me</span>
34
+ <ul>
35
+ <li class="login-list-item">
36
+ <a href={settingsUrl} class="login-link">
37
+ <span class="login-link-label">
38
+ Settings
39
+ </span>
40
+ <dx-icon
41
+ class="login-link-icon"
42
+ symbol="new_window"
43
+ size="xsmall"
44
+ ></dx-icon>
45
+ </a>
46
+ </li>
47
+ <li class="login-list-item">
48
+ <a href={profileUrl} class="login-link">
49
+ <span class="login-link-label">
50
+ Profile
51
+ </span>
52
+ <dx-icon
53
+ class="login-link-icon"
54
+ symbol="new_window"
55
+ size="xsmall"
56
+ ></dx-icon>
57
+ </a>
58
+ </li>
59
+ <li class="login-list-item">
60
+ <a href="#" class="login-link">
61
+ <span class="login-link-label">
62
+ Developer Forums
63
+ </span>
64
+ <dx-icon
65
+ class="login-link-icon"
66
+ symbol="new_window"
67
+ size="xsmall"
68
+ ></dx-icon>
69
+ </a>
70
+ <div class="login-link-blurb">
71
+ Our Developer Forums have a new home!&nbsp;
72
+ <a href="#" class="inline-link">
73
+ Learn more
74
+ </a>
75
+ </div>
76
+ </li>
77
+ </ul>
78
+ </div>
79
+ </div>
80
+ </div>
81
+ </dx-popover>
82
+ </div>
83
+ <div if:false={isLoggedIn}>
84
+ <dx-popover offset="small" width="320px" open-on-hover>
85
+ <dx-button
86
+ slot="control"
87
+ class="login-control"
88
+ icon-symbol="user"
89
+ icon-position="left"
90
+ loading={isLoading}
91
+ variant="custom"
92
+ >
93
+ Login
94
+ </dx-button>
95
+ <div slot="content">
96
+ <div class="login-container">
97
+ <span class="heading">Login</span>
98
+ <div class="login-section">
99
+ <span class="login-section-title">Products</span>
100
+ <ul>
101
+ <li class="login-list-item">
102
+ <a href="#" class="login-link">
103
+ <span class="login-link-label">
104
+ Salesforce
105
+ </span>
106
+ <img
107
+ class="login-link-img"
108
+ src="/assets/svg/salesforce-cloud.svg"
109
+ alt="Salesforce logo"
110
+ />
111
+ <dx-icon
112
+ class="login-link-icon"
113
+ symbol="new_window"
114
+ size="xsmall"
115
+ ></dx-icon>
116
+ </a>
117
+ </li>
118
+ <li class="login-list-item">
119
+ <a href="#" class="login-link">
120
+ <span class="login-link-label">
121
+ Marketing Cloud
122
+ </span>
123
+ <dx-icon
124
+ class="login-link-icon"
125
+ symbol="new_window"
126
+ size="xsmall"
127
+ ></dx-icon>
128
+ </a>
129
+ </li>
130
+ </ul>
131
+ </div>
132
+ <div class="login-section">
133
+ <span class="login-section-title">
134
+ Community & Resources
135
+ </span>
136
+ <ul>
137
+ <li class="login-list-item">
138
+ <a href={loginUrl} class="login-link">
139
+ <span class="login-link-label">
140
+ Trailblazer.me
141
+ </span>
142
+ </a>
143
+ <div class="login-link-blurb">
144
+ Login into access a rich community of
145
+ Salesforce Developers, get ideas, and find
146
+ solutions.
147
+ </div>
148
+ </li>
149
+ </ul>
150
+ </div>
151
+ </div>
152
+ </div>
153
+ </dx-popover>
154
+ </div>
155
+ </template>
@@ -0,0 +1,347 @@
1
+ import { api, LightningElement } from "lwc";
2
+ import { track } from "dxUtils/analytics";
3
+
4
+ // TODO: move to environment variable
5
+ const TBID_BASE_URL = "https://dev1-trailblazer-identity.cs192.force.com";
6
+ const TBID_SETTINGS_URL = `${TBID_BASE_URL}/settings`;
7
+ const TBID_PROFILE_URL = `${TBID_BASE_URL}/id`;
8
+ const TBID_IFRAME_URL = `${TBID_BASE_URL}/secur/logout.jsp`;
9
+ // TODO: move to environment variable
10
+ const TBID_API_BASE_URL = "https://development.developer.salesforce.com/tbid";
11
+ const TBID_API_LOGOUT_URL = `${TBID_API_BASE_URL}/logout`;
12
+ const TBID_API_USERINFO_URL = `${TBID_API_BASE_URL}/userinfo`;
13
+ const TBID_API_LOGIN_URL = `${TBID_API_BASE_URL}/dologin`;
14
+ const TBID_API_TOKEN_URL = `${TBID_API_BASE_URL}/token`;
15
+ const TBID_API_PLATFORM_EVENTS_URL = `${TBID_API_BASE_URL}/platform-events`;
16
+
17
+ declare global {
18
+ interface Window {
19
+ SFIDWidget?: {
20
+ logout(): void;
21
+ login(): void;
22
+ openid_response: any;
23
+ disabled: boolean;
24
+ };
25
+ }
26
+ }
27
+
28
+ export interface UserInfo {
29
+ avatarImgSrc?: string;
30
+ company?: string;
31
+ firstName?: string;
32
+ id?: string;
33
+ lastName?: string;
34
+ orgId?: string;
35
+ relationship?: string;
36
+ role?: string;
37
+ username?: string;
38
+ readonly fullName: string;
39
+ }
40
+
41
+ interface EventSourceEvent extends Event {
42
+ id: string;
43
+ retry?: number;
44
+ data: string;
45
+ event?: string;
46
+ }
47
+
48
+ const enum PlatformEventsType {
49
+ UserDataChange = "UserDataChange",
50
+ UserPhotoChange = "UserPhotoChange",
51
+ UserMerge = "UserMerge"
52
+ }
53
+
54
+ const trackableUserInfo = new Set([
55
+ "company",
56
+ "id",
57
+ "orgId",
58
+ "relationship",
59
+ "role"
60
+ ]);
61
+
62
+ export default class AvatarButton extends LightningElement {
63
+ @api size: "small" | "medium" | "large" = "medium";
64
+
65
+ private userInfo: UserInfo = {
66
+ get fullName() {
67
+ if (this.firstName && this.lastName) {
68
+ return `${this.firstName} ${this.lastName}`;
69
+ }
70
+ return this.firstName || this.lastName || "";
71
+ }
72
+ };
73
+ private isLoading = false;
74
+ private settingsUrl = TBID_SETTINGS_URL;
75
+ private profileUrl = TBID_PROFILE_URL;
76
+ private _didReceiveUserInfo = false;
77
+ private eventSource?: EventSource;
78
+
79
+ private get loginUrl() {
80
+ return `${TBID_API_LOGIN_URL}?startURL=${encodeURIComponent(
81
+ window.location.href
82
+ )}`;
83
+ }
84
+
85
+ private get isLoggedIn() {
86
+ return this._didReceiveUserInfo;
87
+ }
88
+
89
+ connectedCallback() {
90
+ const searchParams = new URLSearchParams(window.location.search);
91
+
92
+ if (searchParams.get("loginSuccess") === "true") {
93
+ // clear the query param
94
+ this.isLoading = true;
95
+ searchParams.delete("loginSuccess");
96
+ window.location.search = searchParams.toString();
97
+ }
98
+
99
+ window.addEventListener("tbid-login", this.handleSsoLogin);
100
+ window.addEventListener("tbid-logout", this.handleSsoLogout);
101
+
102
+ const isWidgetDisabled = window.SFIDWidget?.disabled;
103
+ const isWidgetLoggedIn = window.SFIDWidget?.openid_response;
104
+
105
+ // If the component loads and (1) we are logging in and (2) the embedded login widget script
106
+ // is in the DOM but (3) the widget has either not loaded or not completed login yet, we
107
+ // defer the userInfo request in order to allow the SFIDWidget the time to trigger it (via
108
+ // it's own login handler) after SSO login. If any of (1) - (3) are false, then we request
109
+ // user info immediately. The check prevents duplicate requests.
110
+ if (
111
+ this.isLoading &&
112
+ (!window.SFIDWidget || (!isWidgetDisabled && !isWidgetLoggedIn)) &&
113
+ document.querySelector('script[src*="authProviderEmbeddedLogin"]')
114
+ ) {
115
+ setTimeout(() => {
116
+ if (!window.SFIDWidget?.openid_response) {
117
+ // this.trackLogin(); TODO: track only clicks
118
+ this.platformEventsSubscribe();
119
+ this.requestUserInfo();
120
+ }
121
+ }, 1000);
122
+ } else {
123
+ if (this.isLoading) {
124
+ // This was a login.
125
+ this.platformEventsSubscribe();
126
+ // this.trackLogin(); TODO: track only clicks
127
+ }
128
+ this.requestUserInfo();
129
+ }
130
+ }
131
+
132
+ disconnectedCallback() {
133
+ window.removeEventListener("tbid-login", this.handleSsoLogin);
134
+ window.removeEventListener("tbid-logout", this.handleSsoLogout);
135
+ }
136
+
137
+ private handleUserDataChange = ({ data }: EventSourceEvent) => {
138
+ let parsedEventData: any;
139
+
140
+ try {
141
+ parsedEventData = JSON.parse(data);
142
+ } catch (ex) {
143
+ console.error(
144
+ `Unparseable ${PlatformEventsType.UserDataChange} data received`
145
+ );
146
+ return;
147
+ }
148
+
149
+ this.updateAvatarWithUserInfo(parsedEventData);
150
+ };
151
+
152
+ private setupEventSource = () => {
153
+ // subscribe to platform events
154
+ this.eventSource = new EventSource(TBID_API_PLATFORM_EVENTS_URL);
155
+ this.eventSource.addEventListener(
156
+ PlatformEventsType.UserDataChange,
157
+ // eslint-disable-next-line no-undef
158
+ this.handleUserDataChange as EventListener
159
+ );
160
+ this.eventSource.addEventListener(
161
+ PlatformEventsType.UserPhotoChange,
162
+ this.requestUserInfo
163
+ );
164
+ this.eventSource.addEventListener(
165
+ PlatformEventsType.UserMerge,
166
+ this.handleSsoLogout
167
+ );
168
+ };
169
+
170
+ private teardownEventSource = () => {
171
+ if (!this.eventSource) {
172
+ return;
173
+ }
174
+
175
+ this.eventSource.removeEventListener(
176
+ PlatformEventsType.UserDataChange,
177
+ // eslint-disable-next-line no-undef
178
+ this.handleUserDataChange as EventListener
179
+ );
180
+ this.eventSource.removeEventListener(
181
+ PlatformEventsType.UserPhotoChange,
182
+ this.requestUserInfo
183
+ );
184
+ this.eventSource.removeEventListener(
185
+ PlatformEventsType.UserMerge,
186
+ this.handleSsoLogout
187
+ );
188
+ if (this.eventSource.readyState !== 2 /* CLOSED */) {
189
+ this.eventSource.close();
190
+ }
191
+ this.eventSource = undefined;
192
+ };
193
+
194
+ private platformEventsSubscribe = () => {
195
+ this.teardownEventSource();
196
+ this.setupEventSource();
197
+ };
198
+
199
+ // This handles logout from within this component, rather than from SSO via the SFIDWidget.
200
+ private handleLogout = (isSsoLogout: boolean) => {
201
+ this._didReceiveUserInfo = false;
202
+ this.isLoading = false;
203
+ this.updateAvatarWithUserInfo({}); // clear old info
204
+ this.teardownEventSource();
205
+
206
+ if (!isSsoLogout) {
207
+ this.trackLogout();
208
+ }
209
+
210
+ if (!isSsoLogout && window.SFIDWidget?.openid_response) {
211
+ // If the SFIDWidget is around and has an access token, and if logout was not *already*
212
+ // triggered by SSO logout, defer to the SFIDWidget. This will ensure that the SSO
213
+ // session is logged out as well.
214
+ window.SFIDWidget.logout();
215
+ } else {
216
+ // Always clear the session token; if not SSO logout, this will also revoke the token with
217
+ // TBID; if SSO logout, that step is already taken care of
218
+ fetch(`${TBID_API_LOGOUT_URL}?isSsoLogout=${isSsoLogout}`); // no need to await this
219
+
220
+ if (!isSsoLogout) {
221
+ // Dropping an iframe is required to fully get TBID to destroy the session; this is
222
+ // a TBID issue and they have requested that we do this for now.
223
+ const ifr = document.createElement("iframe");
224
+ ifr.setAttribute("src", TBID_IFRAME_URL);
225
+ document.body.appendChild(ifr);
226
+ }
227
+ }
228
+ };
229
+
230
+ // This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
231
+ private handleSsoLogout = this.handleLogout.bind(this, true);
232
+
233
+ private handleComponentLogout = this.handleLogout.bind(this, false);
234
+
235
+ // This will only be called for "seamless SSO" login by the embedded login widget (SFIDWidget) on the website, if it exists.
236
+ private handleSsoLogin = async (event: Event) => {
237
+ const { userInfo } = (event as CustomEvent).detail;
238
+ const token = userInfo?.access_token;
239
+
240
+ // `token` should always be defined if an SSO login occurs, but we check for extra safety
241
+ if (token) {
242
+ this.isLoading = true;
243
+ // If an SSO login occurred and we have an SSO access token, we want to start using
244
+ // it rather than some other non-linked access token, for the "seamless SSO"
245
+ // experience
246
+ try {
247
+ await fetch(TBID_API_TOKEN_URL, {
248
+ method: "POST",
249
+ headers: {
250
+ "Content-Type": "application/json"
251
+ },
252
+ body: JSON.stringify({
253
+ token
254
+ })
255
+ });
256
+ this.platformEventsSubscribe();
257
+ } catch (ex) {
258
+ console.error(`Attempt to update token failed: ${ex}`);
259
+ }
260
+ }
261
+
262
+ if (userInfo) {
263
+ this.updateAvatarWithUserInfo(userInfo);
264
+ this._didReceiveUserInfo = true;
265
+ }
266
+
267
+ // this.trackLogin(); TODO: only track clicks
268
+ };
269
+
270
+ private handleComponentLogin = () => {
271
+ // Either of these methods will trigger a redirect, so we track the successful login after
272
+ // the redirect completes, and not here.
273
+ if (window.SFIDWidget) {
274
+ // If the SFIDWidget is around, defer to it for login. This will ensure that the SSO
275
+ // session is used if possible.
276
+ window.SFIDWidget.login();
277
+ } else {
278
+ window.location.href = this.loginUrl;
279
+ }
280
+ };
281
+
282
+ private trackLogin = () => {
283
+ track(document, "custEv_userLogin", {
284
+ authenticationMethod: "tbid",
285
+ id: {
286
+ tb: Object.entries(this.userInfo)
287
+ .filter(([key]) => trackableUserInfo.has(key))
288
+ .reduce(
289
+ (infoToTrack, [key, value]) => ({
290
+ ...infoToTrack,
291
+ [key]: value
292
+ }),
293
+ {} as Record<string, string>
294
+ )
295
+ }
296
+ });
297
+ };
298
+
299
+ private trackLogout = () => {
300
+ track(document, "custEv_userLogout", {
301
+ clickText: "logout",
302
+ clickUrl: TBID_API_LOGOUT_URL,
303
+ itemTitle: "TBID Logout Link",
304
+ elementType: "link"
305
+ });
306
+ };
307
+
308
+ private updateAvatarWithUserInfo = (userInfo: any) => {
309
+ if (!userInfo) {
310
+ return;
311
+ }
312
+
313
+ this.userInfo.avatarImgSrc = userInfo.photos?.thumbnail;
314
+ this.userInfo.firstName = userInfo.given_name;
315
+ this.userInfo.lastName = userInfo.family_name;
316
+ this.userInfo.username = userInfo.preferred_username;
317
+ this.userInfo.id = userInfo.user_id;
318
+ this.userInfo.orgId = userInfo.organization_id;
319
+
320
+ if (userInfo.custom_attributes) {
321
+ this.userInfo.company = userInfo.custom_attributes.CompanyName;
322
+ this.userInfo.relationship =
323
+ userInfo.custom_attributes.RelationshipToSalesforce;
324
+ this.userInfo.role = userInfo.custom_attributes.Role;
325
+ }
326
+ // TODO: Consider displaying initials if no photo. Is there always a photo even if just a default one?
327
+ };
328
+
329
+ private requestUserInfo = async () => {
330
+ this.isLoading = true;
331
+
332
+ try {
333
+ const userInfoRes = await fetch(TBID_API_USERINFO_URL);
334
+
335
+ if (userInfoRes.ok) {
336
+ const userInfo = await userInfoRes.json();
337
+ this.updateAvatarWithUserInfo(userInfo);
338
+ this._didReceiveUserInfo = true;
339
+ }
340
+ } catch (ex) {
341
+ // TODO: Something not directly related to auth went wrong. Unsure what to do here.
342
+ console.error(`Could not request user info: ${ex}`);
343
+ }
344
+
345
+ this.isLoading = false;
346
+ };
347
+ }
@@ -44,8 +44,7 @@
44
44
  {location}
45
45
  </span>
46
46
  <dx-type-badge
47
- color={brandType}
48
- type="content-type"
47
+ color={typeBadgeColor}
49
48
  value={type}
50
49
  if:true={type}
51
50
  ></dx-type-badge>