l-min-components 1.0.170 → 1.0.176

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": "l-min-components",
3
- "version": "1.0.170",
3
+ "version": "1.0.176",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import { CloseIcon } from "./assets/svg/close";
3
3
  import { AddIcon } from "./assets/svg/add";
4
4
  import {
@@ -7,6 +7,7 @@ import {
7
7
  AccountDropdownBody,
8
8
  AccountDropdownFooter,
9
9
  } from "./index.styled";
10
+ import { useLocation, useNavigate } from "react-router-dom";
10
11
  /**
11
12
  * @param {{
12
13
  * type: string,
@@ -17,59 +18,222 @@ import {
17
18
  *
18
19
  */
19
20
  const AccountDropdown = (props) => {
21
+ const [personalAccountData, setPersonalAccountData] = useState([]);
22
+ const [developerAccountData, setDeveloperAccountData] = useState([]);
23
+ const [instructorAccountData, setInstructorAccountData] = useState([]);
24
+ const [enterpriseAccountData, setEnterpriseAccountData] = useState([]);
25
+ const [selectedAccount, setSelectedAccount] = useState();
26
+ const navigate = useNavigate();
27
+ const { pathname } = useLocation();
28
+ useEffect(() => {
29
+ if (pathname?.includes("personal")) {
30
+ setSelectedAccount(personalAccountData[0]);
31
+ }
32
+ if (pathname?.includes("developer")) {
33
+ setSelectedAccount(developerAccountData[0]);
34
+ }
35
+ if (pathname?.includes("instructor")) {
36
+ setSelectedAccount(instructorAccountData[0]);
37
+ }
38
+ if (pathname?.includes("enterprise")) {
39
+ setSelectedAccount(enterpriseAccountData[0]);
40
+ }
41
+ }, [pathname]);
42
+ useEffect(() => {
43
+ if (props?.data?.data) {
44
+ let personalArray = [];
45
+ let developerArray = [];
46
+ let instructorArray = [];
47
+ let enterpriseArray = [];
48
+ props?.data?.data?.results?.map((accountItem, idx) => {
49
+ if (
50
+ accountItem?.type === "PERSONAL" &&
51
+ !personalAccountData?.includes(accountItem)
52
+ ) {
53
+ personalArray.push(accountItem);
54
+ setPersonalAccountData(personalArray);
55
+ }
56
+ if (
57
+ accountItem?.type === "DEVELOPER" &&
58
+ !developerAccountData?.includes(accountItem)
59
+ ) {
60
+ developerArray.push(accountItem);
61
+ setDeveloperAccountData(developerArray);
62
+ }
63
+ if (
64
+ accountItem?.type === "INSTRUCTOR" &&
65
+ !instructorAccountData?.includes(accountItem)
66
+ ) {
67
+ instructorArray.push(accountItem);
68
+ setInstructorAccountData(instructorArray);
69
+ }
70
+ if (
71
+ accountItem?.type === "ENTERPRISE" &&
72
+ !enterpriseAccountData?.includes(accountItem)
73
+ ) {
74
+ enterpriseArray.push(accountItem);
75
+ setEnterpriseAccountData(enterpriseArray);
76
+ }
77
+ });
78
+ }
79
+ }, [props?.data?.data]);
80
+ useEffect(() => {
81
+ if (selectedAccount) {
82
+ window.localStorage.setItem("current-account", selectedAccount);
83
+ }
84
+ }, [selectedAccount]);
20
85
  return (
21
86
  <>
22
87
  <AccountDropdownLayout>
23
88
  <AccountDropdownHeader>
24
89
  <div>
25
- <img src={props.avatar} alt="account photo" />
90
+ <img
91
+ src={selectedAccount?.profile_photo || props?.avatar}
92
+ alt="account photo"
93
+ />
26
94
  </div>
27
95
  <div>
28
- <h1> {props.activeAccountName}</h1>
29
- <h2>{props.activeAccountType} </h2>
96
+ <h1>
97
+ {" "}
98
+ {selectedAccount?.display_name ||
99
+ selectedAccount?.metadata?.organization_name ||
100
+ props.activeAccountName}
101
+ </h1>
102
+ <h2 style={{ textTransform: "capitalize" }}>
103
+ {selectedAccount?.type || props.activeAccountType}{" "}
104
+ </h2>
30
105
  </div>
31
106
  <CloseIcon onClick={(e) => props.setIsOpen(!props.isOpen)} />
32
107
  </AccountDropdownHeader>
33
108
  <AccountDropdownBody>
34
109
  {/* {props.apiAccountType === `${props.accountType}` && ( */}
35
- <div>
36
- <h3>{props.accountType} </h3>
37
- <div className="account-info">
38
- <div className="avatar-container">
39
- <img src={props.avatar} alt="account photo" />
40
- </div>
41
- <div className="account-details">
42
- <h1> {props.accountName}</h1>
43
- <span>{props.notificationCount} </span>
44
- </div>
45
- </div>
46
- </div>
47
110
 
48
- <div>
49
- <h3>{props.accountType} </h3>
50
- <div className="account-info">
51
- <div className="avatar-container">
52
- <img src={props.avatar} alt="account photo" />
53
- </div>
54
- <div className="account-details">
55
- <h1> {props.accountName}</h1>
56
- <span>{props.notificationCount} </span>
57
- </div>
111
+ {personalAccountData?.length > 0 && (
112
+ <div>
113
+ <h3>Personal account</h3>
114
+ {personalAccountData?.map((personalItem, idx) => (
115
+ <div
116
+ className="account-info"
117
+ onClick={() => {
118
+ setSelectedAccount(personalItem);
119
+ if (window.location.port) {
120
+ window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/personal`;
121
+ } else {
122
+ window.location.href = `${window.location.protocol}//${window.location.hostname}/personal`;
123
+ }
124
+ }}
125
+ key={idx}
126
+ >
127
+ <div className="avatar-container">
128
+ <img
129
+ src={personalItem?.profile_photo || props?.avatar}
130
+ alt="account photo"
131
+ />
132
+ </div>
133
+ <div className="account-details">
134
+ <h1> {personalItem?.display_name || props.accountName}</h1>
135
+ <span>{props.notificationCount} </span>
136
+ </div>
137
+ </div>
138
+ ))}
58
139
  </div>
59
- </div>
60
-
61
- <div>
62
- <h3>{props.accountType} </h3>
63
- <div className="account-info">
64
- <div className="avatar-container">
65
- <img src={props.avatar} alt="account photo" />
66
- </div>
67
- <div className="account-details">
68
- <h1> {props.accountName}</h1>
69
- <span>{props.notificationCount} </span>
70
- </div>
140
+ )}
141
+ {developerAccountData.length > 0 && (
142
+ <div>
143
+ <h3>Developer account</h3>
144
+ {developerAccountData?.map((developerItem, idx) => (
145
+ <div
146
+ className="account-info"
147
+ onClick={() => {
148
+ setSelectedAccount(developerItem);
149
+ if (window.location.port) {
150
+ window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/developer`;
151
+ } else {
152
+ window.location.href = `${window.location.protocol}//${window.location.hostname}/developer`;
153
+ }
154
+ }}
155
+ key={idx}
156
+ >
157
+ <div className="avatar-container">
158
+ <img
159
+ src={developerItem?.profile_photo || props.avatar}
160
+ alt="account photo"
161
+ />
162
+ </div>
163
+ <div className="account-details">
164
+ <h1> {developerItem?.display_name || props.accountName}</h1>
165
+ <span>{props.notificationCount} </span>
166
+ </div>
167
+ </div>
168
+ ))}
71
169
  </div>
72
- </div>
170
+ )}
171
+ {instructorAccountData?.length > 0 && (
172
+ <div>
173
+ <h3>Instructor account</h3>
174
+ {instructorAccountData?.map((instructorItem, idx) => (
175
+ <div
176
+ className="account-info"
177
+ onClick={() => {
178
+ setSelectedAccount(instructorItem);
179
+ if (window.location.port) {
180
+ window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/instructor`;
181
+ } else {
182
+ window.location.href = `${window.location.protocol}//${window.location.hostname}/instructor`;
183
+ }
184
+ }}
185
+ key={idx}
186
+ >
187
+ <div className="avatar-container">
188
+ <img
189
+ src={instructorItem?.profile_photo || props.avatar}
190
+ alt="account photo"
191
+ />
192
+ </div>
193
+ <div className="account-details">
194
+ <h1>
195
+ {" "}
196
+ {instructorItem?.display_name || props.accountName}
197
+ </h1>
198
+ <span>{props.notificationCount} </span>
199
+ </div>
200
+ </div>
201
+ ))}
202
+ </div>
203
+ )}
204
+ {enterpriseAccountData?.length > 0 && (
205
+ <div>
206
+ <h3>Enterprise account</h3>
207
+ {enterpriseAccountData?.map((enterpriseItem, idx) => (
208
+ <div
209
+ className="account-info"
210
+ onClick={() => {
211
+ setSelectedAccount(enterpriseItem);
212
+ if (window.location.port) {
213
+ window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/enterprise`;
214
+ } else {
215
+ window.location.href = `${window.location.protocol}//${window.location.hostname}/enterprise`;
216
+ }
217
+ }}
218
+ key={idx}
219
+ >
220
+ <div className="avatar-container">
221
+ <img
222
+ src={enterpriseItem?.profile_photo || props.avatar}
223
+ alt="account photo"
224
+ />
225
+ </div>
226
+ <div className="account-details">
227
+ <h1>
228
+ {" "}
229
+ {enterpriseItem?.display_name || props.accountName}
230
+ </h1>
231
+ <span>{props.notificationCount} </span>
232
+ </div>
233
+ </div>
234
+ ))}
235
+ </div>
236
+ )}
73
237
  {/* // )} */}
74
238
  </AccountDropdownBody>
75
239
 
@@ -0,0 +1,31 @@
1
+ import useAxios from "axios-hooks";
2
+
3
+ const useHeader = () => {
4
+ // get user details
5
+ const [{ ...userDetails }, getUserDetails] = useAxios();
6
+
7
+ const handleGetUserDetails = async () => {
8
+ await getUserDetails({
9
+ method: "get",
10
+ url: "/iam/v1/users/me/",
11
+ });
12
+ };
13
+
14
+ // get user accounts detail
15
+
16
+ const [{ ...userAccountsDetail }, getUserAccountsDetail] = useAxios();
17
+
18
+ const handleGetUserAccountsDetail = async () => {
19
+ await getUserAccountsDetail({
20
+ method: "get",
21
+ url: "/iam/v1/accounts/",
22
+ });
23
+ };
24
+ return {
25
+ handleGetUserDetails,
26
+ userDetails,
27
+ handleGetUserAccountsDetail,
28
+ userAccountsDetail,
29
+ };
30
+ };
31
+ export default useHeader;
@@ -19,6 +19,7 @@ import {
19
19
  UserProfile,
20
20
  CountryFlagGroup,
21
21
  } from "./index.styled";
22
+ import useHeader from "./getHeaderDetails";
22
23
 
23
24
  /**
24
25
  * @param {{
@@ -33,11 +34,17 @@ const HeaderComponent = (props) => {
33
34
  const [selected, setSelected] = useState("ES");
34
35
  const [isOpen, setIsOpen] = useState(false);
35
36
  const [searchResultOpen, setSearchResultOpen] = useState(false);
36
-
37
- console.log(selected);
37
+ const {
38
+ handleGetUserAccountsDetail,
39
+ handleGetUserDetails,
40
+ userAccountsDetail,
41
+ userDetails,
42
+ } = useHeader();
38
43
 
39
44
  useEffect(() => {
40
45
  setIsOpen(false);
46
+ handleGetUserAccountsDetail();
47
+ // handleGetUserDetails();
41
48
  }, []);
42
49
 
43
50
  return (
@@ -118,13 +125,14 @@ const HeaderComponent = (props) => {
118
125
  {isOpen && (
119
126
  <AccountDropdown
120
127
  avatar={avatar}
121
- activeAccountName={"Michael Ohaga"}
128
+ activeAccountName={"Default name"}
122
129
  activeAccountType={"Personal Account"}
123
- accountName={"Jo Gulgowski"}
124
- accountType={"Instructor Account"}
130
+ accountName={"Default name"}
131
+ accountType={"Default Account"}
125
132
  notificationCount={"5"}
126
133
  isOpen={isOpen}
127
134
  setIsOpen={setIsOpen}
135
+ data={userAccountsDetail}
128
136
  />
129
137
  )}
130
138
  </Navbar>
@@ -370,6 +370,7 @@ export const Navbar2 = styled.nav`
370
370
  width: 100%;
371
371
  align-items: center;
372
372
  position: fixed;
373
+ z-index: 99;
373
374
  `;
374
375
 
375
376
  export const Nav2 = styled.ul`
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useEffect } from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import {
4
4
  UserCardContainer,
@@ -7,15 +7,31 @@ import {
7
7
  Handle,
8
8
  UserDetail,
9
9
  } from "./styles";
10
+ import useHeader from "../../header/getHeaderDetails";
11
+ import Loader from "../../loader";
10
12
 
11
13
  const UserCard = ({ user, isOpen }) => {
14
+ const { handleGetUserDetails, userDetails } = useHeader();
15
+ useEffect(() => {
16
+ handleGetUserDetails();
17
+ }, []);
12
18
  return (
13
19
  <UserCardContainer isOpen={isOpen}>
14
- <Avatar src={user.avatar} isOpen={isOpen} />
15
- <UserDetail isOpen={isOpen}>
16
- <UserName>{user.name}</UserName>
17
- <Handle>{user.handle}</Handle>
18
- </UserDetail>
20
+ {userDetails?.loading ? (
21
+ <Loader />
22
+ ) : (
23
+ <>
24
+ <Avatar src={user.avatar} isOpen={isOpen} />
25
+ <UserDetail isOpen={isOpen}>
26
+ <UserName>
27
+ {userDetails?.data?.first_name +
28
+ " " +
29
+ userDetails?.data?.last_name}
30
+ </UserName>
31
+ <Handle>{`@ ${userDetails?.data?.username}`}</Handle>
32
+ </UserDetail>
33
+ </>
34
+ )}
19
35
  </UserCardContainer>
20
36
  );
21
37
  };