@salesforcedevs/dx-components 0.55.3-alpha-1 → 0.55.3-alpha-4

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.55.3-alpha-1",
3
+ "version": "0.55.3-alpha-4",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -5,6 +5,11 @@
5
5
  --dx-c-button-custom-color-hover: var(--dx-g-blue-vibrant-50);
6
6
  --dx-c-button-custom-background-hover: var(--dx-g-cloud-blue-vibrant-90);
7
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;
8
13
  }
9
14
 
10
15
  .avatar {
@@ -13,6 +18,8 @@
13
18
  }
14
19
 
15
20
  .avatar.avatar-small {
21
+ display: block;
22
+ height: var(--dx-g-spacing-lg);
16
23
  width: var(--dx-g-spacing-lg);
17
24
  }
18
25
 
@@ -22,9 +29,7 @@
22
29
  }
23
30
 
24
31
  .login-control {
25
- background: var(--dx-g-cloud-blue-vibrant-90);
26
- border-color: var(--dx-g-cloud-blue-vibrant-90);
27
- border-radius: 50%;
32
+ margin-left: var(--dx-g-spacing-smd);
28
33
  }
29
34
 
30
35
  .login-container {
@@ -1,30 +1,35 @@
1
1
  <template>
2
- <div if:false={isLoggedIn}>
2
+ <div if:true={isLoggedIn}>
3
3
  <dx-popover offset="small" width="320px" open-on-hover>
4
- <img
5
- slot="control"
6
- src="https://placekitten.com/300/300"
7
- class="avatar avatar-small"
8
- />
4
+ <div slot="control" class="avatar-small-container login-control">
5
+ <img src={userInfo.avatarImgSrc} class="avatar avatar-small" />
6
+ </div>
9
7
  <div slot="content">
10
8
  <div class="login-container logged-in">
11
- <img src={userInfo.avatarImgSrc} class="header-img" />
12
9
  <img
13
- src="https://placekitten.com/300/300"
10
+ src="/assets/svg/login-widget-bg.png"
11
+ class="header-img"
12
+ />
13
+ <img
14
+ src={userInfo.avatarImgSrc}
14
15
  class="avatar avatar-medium"
15
16
  />
16
- <span class="heading">Jasmine Young</span>
17
- <span class="sub-heading">jyoung58</span>
17
+ <span class="heading">{userInfo.fullName}</span>
18
+ <span class="sub-heading">{userInfo.username}</span>
18
19
  <div class="heading-links">
20
+ <!--
19
21
  <a href="#" class="inline-link">Switch account</a>
20
22
  &nbsp;&nbsp;|&nbsp;&nbsp;
21
- <a href="#" class="inline-link">Logout</a>
23
+ -->
24
+ <a href="#" onclick={handleLogout} class="inline-link">
25
+ Logout
26
+ </a>
22
27
  </div>
23
28
  <div class="login-section">
24
29
  <span class="login-section-title">Trailblazer.me</span>
25
30
  <ul>
26
31
  <li class="login-list-item">
27
- <a href="#" class="login-link">
32
+ <a href={settingsUrl} class="login-link">
28
33
  <span class="login-link-label">
29
34
  Settings
30
35
  </span>
@@ -36,7 +41,7 @@
36
41
  </a>
37
42
  </li>
38
43
  <li class="login-list-item">
39
- <a href="#" class="login-link">
44
+ <a href={profileUrl} class="login-link">
40
45
  <span class="login-link-label">
41
46
  Profile
42
47
  </span>
@@ -59,7 +64,7 @@
59
64
  ></dx-icon>
60
65
  </a>
61
66
  <div class="login-link-blurb">
62
- Our Developer Forums have a new home!
67
+ Our Developer Forums have a new home!&nbsp;
63
68
  <a href="#" class="inline-link">
64
69
  Learn more
65
70
  </a>
@@ -71,13 +76,14 @@
71
76
  </div>
72
77
  </dx-popover>
73
78
  </div>
74
- <div if:true={isLoggedIn}>
79
+ <div if:false={isLoggedIn}>
75
80
  <dx-popover offset="small" width="320px" open-on-hover>
76
81
  <dx-button
77
- class="login-control"
78
82
  slot="control"
83
+ class="login-control"
79
84
  icon-symbol="user"
80
85
  icon-position="left"
86
+ loading={isLoading}
81
87
  variant="custom"
82
88
  >
83
89
  Login
@@ -125,7 +131,7 @@
125
131
  </span>
126
132
  <ul>
127
133
  <li class="login-list-item">
128
- <a href="#" class="login-link">
134
+ <a href={loginUrl} class="login-link">
129
135
  <span class="login-link-label">
130
136
  Trailblazer.me
131
137
  </span>
@@ -1,34 +1,47 @@
1
- import { api, LightningElement, track } from "lwc";
1
+ import { api, LightningElement } from "lwc";
2
2
  import Cookie from "js-cookie";
3
- // import oauth2 from "salesforce-oauth2";
4
3
 
5
- // TODO: move to env vars
6
- // const TBID_CLIENT_ID = '3MVG982oBBDdwyHh3OFdQJTLxbk1dWC8NhBSiKvAsu3gn9m6WhiDKT8iLn34y4w6xsLeIHTbMbhuPPnGfYoW.';
7
- // const TBID_CLIENT_SECRET = 'FC1B4F3E83746CD6ED3A6356B2FCF671A0470C6ADB88BE1A9F288B2D58400BEA';
8
- // const TBID_COMMUNITY_URL = 'https://dev1-trailblazer-identity.cs192.force.com';
9
- const TBID_AUTH_URL = "https://tbid-auth-app-dev.herokuapp.com/tbid/dologin";
10
- const TBID_USERINFO_URL =
11
- "https://dev1-trailblazer-identity.cs192.force.com/services/oauth2/userinfo";
4
+ const TBID_BASE_URL = "https://dev1-trailblazer-identity.cs192.force.com";
5
+ const TBID_LOGIN_URL =
6
+ "https://development.developer.salesforce.com/tbid/dologin";
7
+ const TBID_LOGOUT_URL = `${TBID_BASE_URL}/services/auth/idp/oidc/logout`;
8
+ const TBID_USERINFO_URL = `${TBID_BASE_URL}/services/oauth2/userinfo`;
9
+ const TBID_REVOKE_URL = `${TBID_BASE_URL}/services/oauth2/revoke`;
12
10
 
13
11
  export interface UserInfo {
14
12
  avatarImgSrc?: string;
15
13
  firstName?: string;
16
14
  lastName?: string;
17
15
  username?: string;
16
+ readonly fullName: string;
18
17
  }
19
18
 
20
19
  export default class AvatarButton extends LightningElement {
21
20
  @api size: "small" | "medium" | "large" = "medium";
22
21
 
23
- @track
24
- private userInfo: UserInfo = {};
25
- private _isLoading = false;
26
- private _tbidAccessToken: string | undefined;
22
+ private userInfo: UserInfo = {
23
+ get fullName() {
24
+ if (this.firstName && this.lastName) {
25
+ return `${this.firstName} ${this.lastName}`;
26
+ }
27
+ return this.firstName || this.lastName || "";
28
+ }
29
+ };
30
+ private isLoading = false;
31
+ private settingsUrl = `${TBID_BASE_URL}/settings`;
32
+ private profileUrl = `${TBID_BASE_URL}/id`;
33
+ private loginUrl = TBID_LOGIN_URL;
34
+ private logoutUrl = TBID_LOGOUT_URL;
27
35
 
36
+ // A user only counts as logged in for our purposes if they have an access token
37
+ // and we have successfully used it to get their info.
28
38
  private get isLoggedIn() {
29
- return Boolean(this._tbidAccessToken);
39
+ return Boolean(this._tbidAccessToken) && this._didReceiveUserInfo;
30
40
  }
31
41
 
42
+ private _didReceiveUserInfo = false;
43
+ private _tbidAccessToken: string | undefined;
44
+
32
45
  connectedCallback() {
33
46
  this._tbidAccessToken = Cookie.get("TBID");
34
47
 
@@ -37,42 +50,79 @@ export default class AvatarButton extends LightningElement {
37
50
  }
38
51
  }
39
52
 
40
- onLoginClick() {
41
- if (!this.isLoggedIn) {
42
- window.location.assign(TBID_AUTH_URL);
53
+ private updateAvatarWithUserInfo(userInfo: any) {
54
+ if (!userInfo) {
55
+ return;
43
56
  }
44
- }
45
57
 
46
- private updateAvatarWithUserInfo(userInfo: any) {
47
- this.userInfo.avatarImgSrc = userInfo?.photos?.thumbnail;
58
+ this.userInfo.avatarImgSrc = userInfo.photos?.thumbnail;
59
+ this.userInfo.firstName = userInfo.given_name;
60
+ this.userInfo.lastName = userInfo.family_name;
61
+ this.userInfo.username = userInfo.preferred_username;
48
62
  // TODO: Consider displaying initials if no photo. Is there always a photo?
49
63
  }
50
64
 
51
65
  private async requestUserInfo(accessToken: string) {
52
- this._isLoading = true;
66
+ this.isLoading = true;
53
67
 
54
68
  try {
55
69
  // FIXME: The TBID userinfo currently only accepts the access token in the URL
56
70
  // as a query parameter. This is bad, but they're aware of it, and when it is
57
71
  // fixed, we should use a header or something instead.
58
72
  const userInfoRes = await fetch(
59
- TBID_USERINFO_URL + "?access_token=" + accessToken
73
+ TBID_USERINFO_URL +
74
+ "?access_token=" +
75
+ encodeURIComponent(accessToken)
60
76
  );
61
77
 
62
78
  if (userInfoRes.ok) {
63
79
  const userInfo = await userInfoRes.json();
64
80
  this.updateAvatarWithUserInfo(userInfo);
81
+ this._didReceiveUserInfo = true;
65
82
  } else {
66
83
  if (userInfoRes.status === 403) {
67
- // Bad access token; try to refresh the token
84
+ const refreshToken = Cookie.get("TBID_REFRESH");
85
+ if (refreshToken) {
86
+ console.log("Would use refresh token");
87
+ }
68
88
  }
89
+ // TODO: Do we want a "something went wrong" state here?
69
90
  }
70
91
  } catch (ex) {
71
92
  // TODO: Something not directly related to auth went wrong. Unsure what to do here.
72
93
  }
73
94
 
74
- this._isLoading = false;
95
+ this.isLoading = false;
75
96
  }
76
97
 
77
- private handleAuthFailure() {}
98
+ // private refreshAccessToken(refreshToken);
99
+
100
+ // private handleAuthFailure() {}
101
+ private async handleLogout() {
102
+ // TODO: Check for refresh token and invalidate.
103
+ if (!this._tbidAccessToken) {
104
+ return;
105
+ }
106
+
107
+ Cookie.remove("TBID");
108
+ Cookie.remove("TBID_REFRESH");
109
+
110
+ const formData = new FormData();
111
+ formData.append("token", this._tbidAccessToken);
112
+
113
+ this.isLoading = true;
114
+
115
+ // TODO/QUESTION: should this hit a different or additional URL?
116
+ await fetch(`${TBID_REVOKE_URL}`, {
117
+ method: "POST",
118
+ headers: {
119
+ "Content-Type": "application/x-www-form-urlencoded"
120
+ },
121
+ body: formData
122
+ });
123
+
124
+ this._tbidAccessToken = undefined;
125
+ this._didReceiveUserInfo = false;
126
+ this.isLoading = false;
127
+ }
78
128
  }