l-min-components 1.0.321 → 1.0.331

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.
@@ -30,12 +30,14 @@ const AppMainLayout = () => {
30
30
  const [generalData, setGeneralData] = useState({});
31
31
  const [coming, setComing] = useState();
32
32
  const [activePage, setActivePage] = useState("reports");
33
- const [page, setPage] = useState("index")
34
- const [studyTab, setStudyTab] = useState("analysis")
33
+ const [page, setPage] = useState("index");
34
+ const [studyTab, setStudyTab] = useState("analysis");
35
35
  const [selectedCourseId, setSelectedCourseId] = useState(null);
36
36
  const [hasLayoutBackgroundImage, setHasLayoutBackgroundImage] =
37
37
  useState(false);
38
38
  const [sideMenuLayout, setSideMenuLayout] = useState(true);
39
+ const [defaultAcct, setDefaultAcct] = useState("");
40
+ const centerLayoutStyle = {};
39
41
 
40
42
  useEffect(() => {
41
43
  if (window.location.host.includes("coming")) {
@@ -45,6 +47,21 @@ const AppMainLayout = () => {
45
47
  }
46
48
  }, []);
47
49
 
50
+ useEffect(() => {
51
+ let cookieValue = null;
52
+ const cookieName = "defaultAccountType";
53
+ // Retrieve the value of the cookie
54
+ const cookies = document.cookie.split(";");
55
+ for (let i = 0; i < cookies.length; i++) {
56
+ const cookie = cookies[i].trim();
57
+ if (cookie.startsWith(cookieName + "=")) {
58
+ cookieValue = cookie.substring(cookieName.length + 1);
59
+ setDefaultAcct(cookieValue)
60
+ break;
61
+ }
62
+ }
63
+ }, [defaultAcct]);
64
+
48
65
  return (
49
66
  <OutletContext.Provider
50
67
  value={{
@@ -56,14 +73,15 @@ const AppMainLayout = () => {
56
73
  hasLayoutBackgroundImage,
57
74
  setHasLayoutBackgroundImage,
58
75
  setSideMenuLayout,
59
- activePage,
60
- setActivePage,
61
- studyTab,
76
+ activePage,
77
+ setActivePage,
78
+ studyTab,
62
79
  setStudyTab,
63
80
  page,
64
81
  setPage,
65
- selectedCourseId,
66
- setSelectedCourseId
82
+ selectedCourseId,
83
+ setSelectedCourseId,
84
+ centerLayoutStyle,
67
85
  }}
68
86
  >
69
87
  <Layout
@@ -80,7 +98,17 @@ const AppMainLayout = () => {
80
98
  <SideMenu
81
99
  user={user}
82
100
  routes={sideMenuOptions}
83
- userType={"developer"}
101
+ userType={
102
+ window.location.pathname.includes("enterprise")
103
+ ? "enterprise"
104
+ : window.location.pathname.includes("personal")
105
+ ? "personal"
106
+ : window.location.pathname.includes("instructor")
107
+ ? "instructor"
108
+ : window.location.pathname.includes("developer")
109
+ ? "developer"
110
+ : defaultAcct
111
+ }
84
112
  isOpen={isOpen}
85
113
  setIsOpen={setIsOpen}
86
114
  />
@@ -88,7 +116,7 @@ const AppMainLayout = () => {
88
116
  </>
89
117
  )}
90
118
  </LeftLayout>
91
- <CenterLayout isOpen={isOpen}>
119
+ <CenterLayout isOpen={isOpen} style={centerLayoutStyle}>
92
120
  <Outlet />
93
121
  </CenterLayout>
94
122
 
@@ -8,6 +8,7 @@ import {
8
8
  AccountDropdownFooter,
9
9
  } from "./index.styled";
10
10
  import { useLocation, useNavigate } from "react-router-dom";
11
+ import useHeader from "./getHeaderDetails";
11
12
  /**
12
13
  * @param {{
13
14
  * type: string,
@@ -22,6 +23,7 @@ const AccountDropdown = (props) => {
22
23
  const navigate = useNavigate();
23
24
  const { pathname } = useLocation();
24
25
  useEffect(() => {}, [pathname]);
26
+ const { setDefaultAccount, handleSetDefaultAccount } = useHeader();
25
27
 
26
28
  useEffect(() => {
27
29
  if (props?.selectedAccount?.type === "DEVELOPER") {
@@ -44,6 +46,7 @@ const AccountDropdown = (props) => {
44
46
  }
45
47
  }, [props?.selectedAccount]);
46
48
  console.log(props?.selectedAccount, "selected");
49
+
47
50
  return (
48
51
  <>
49
52
  <AccountDropdownLayout>
@@ -109,7 +112,7 @@ const AccountDropdown = (props) => {
109
112
  }`}
110
113
  onClick={() => {
111
114
  props?.setSelectedAccount(developerItem);
112
-
115
+ handleSetDefaultAccount(developerItem?.id);
113
116
  if (
114
117
  window.location.port &&
115
118
  window.location.host.includes("developer")
@@ -152,10 +155,11 @@ const AccountDropdown = (props) => {
152
155
  }`}
153
156
  onClick={() => {
154
157
  props?.setSelectedAccount(instructorItem);
158
+ handleSetDefaultAccount(instructorItem?.id);
155
159
  if (window.location.port) {
156
- window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/instructor`;
160
+ window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/instructor/dashboard`;
157
161
  } else {
158
- window.location.href = `${window.location.protocol}//${window.location.hostname}/instructor`;
162
+ window.location.href = `${window.location.protocol}//${window.location.hostname}/instructor/dashboard`;
159
163
  }
160
164
  }}
161
165
  key={idx}
@@ -187,10 +191,11 @@ const AccountDropdown = (props) => {
187
191
  }`}
188
192
  onClick={() => {
189
193
  props?.setSelectedAccount(enterpriseItem);
194
+ handleSetDefaultAccount(enterpriseItem?.id);
190
195
  if (window.location.port) {
191
- window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/enterprise`;
196
+ window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/enterprise/dashboard`;
192
197
  } else {
193
- window.location.href = `${window.location.protocol}//${window.location.hostname}/enterprise`;
198
+ window.location.href = `${window.location.protocol}//${window.location.hostname}/enterprise/dashboard`;
194
199
  }
195
200
  }}
196
201
  key={idx}
@@ -212,6 +217,42 @@ const AccountDropdown = (props) => {
212
217
  ))}
213
218
  </div>
214
219
  )}
220
+ {props?.personalAccountData?.length > 0 && (
221
+ <div>
222
+ <h3>Personal account</h3>
223
+ {props?.personalAccountData?.map((personalItem, idx) => (
224
+ <div
225
+ className={`account-info ${
226
+ personalItem === props?.selectedAccount ? "activated" : ""
227
+ }`}
228
+ onClick={() => {
229
+ props?.setSelectedAccount(personalItem);
230
+ handleSetDefaultAccount(personalItem?.id);
231
+ if (window.location.port) {
232
+ window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/personal/dashboard`;
233
+ } else {
234
+ window.location.href = `${window.location.protocol}//${window.location.hostname}/personal/dashboard`;
235
+ }
236
+ }}
237
+ key={idx}
238
+ >
239
+ <div className="avatar-container">
240
+ <img
241
+ src={personalItem?.profile_photo?.url || props.avatar}
242
+ alt="account photo"
243
+ />
244
+ </div>
245
+ <div className="account-details">
246
+ <h1>
247
+ {" "}
248
+ {personalItem?.display_name || props.accountName}
249
+ </h1>
250
+ <span>{props.notificationCount} </span>
251
+ </div>
252
+ </div>
253
+ ))}
254
+ </div>
255
+ )}
215
256
  {/* // )} */}
216
257
  </AccountDropdownBody>
217
258
 
@@ -21,11 +21,63 @@ const useHeader = () => {
21
21
  url: "/iam/v1/accounts/",
22
22
  });
23
23
  };
24
+
25
+ // get user default account
26
+ const [{ ...getDefaultAccount }, defaultAccount] = useAxios(
27
+ {
28
+ method: "GET",
29
+ },
30
+ {
31
+ manual: true,
32
+ }
33
+ );
34
+
35
+ const handleGetDefaultAccount = async (data) => {
36
+ try {
37
+ await defaultAccount({
38
+ url: "/iam/v1/users/default_account/",
39
+ });
40
+ } catch (err) {
41
+ console.log(err);
42
+ }
43
+ };
44
+
45
+ // set user default account
46
+ const [{ ...setDefaultAccount }, postDefaultAccount] = useAxios(
47
+ {
48
+ method: "POST",
49
+ },
50
+ {
51
+ manual: true,
52
+ }
53
+ );
54
+
55
+ const handleSetDefaultAccount = async (accountID) => {
56
+ try {
57
+ await postDefaultAccount({
58
+ url: "/iam/v1/users/default_account/",
59
+ params: {
60
+ _account: accountID,
61
+ },
62
+ // headers: {
63
+ // "Content-Type": "application/json",
64
+ // account: accountID,
65
+ // },
66
+ });
67
+ } catch (err) {
68
+ console.log(err);
69
+ }
70
+ };
71
+
24
72
  return {
25
73
  handleGetUserDetails,
26
74
  userDetails,
27
75
  handleGetUserAccountsDetail,
28
76
  userAccountsDetail,
77
+ handleGetDefaultAccount,
78
+ getDefaultAccount,
79
+ handleSetDefaultAccount,
80
+ setDefaultAccount,
29
81
  };
30
82
  };
31
83
  export default useHeader;
@@ -45,15 +45,18 @@ const HeaderComponent = (props) => {
45
45
  handleGetUserDetails,
46
46
  userAccountsDetail,
47
47
  userDetails,
48
+ getDefaultAccount,
49
+ handleGetDefaultAccount,
48
50
  } = useHeader();
49
51
  const { pathname } = useLocation();
50
- const { setGeneralData } = useContext(OutletContext);
52
+ const { setGeneralData, generalData } = useContext(OutletContext);
51
53
  const [selectedAccount, setSelectedAccount] = useState();
52
54
 
53
55
  useEffect(() => {
54
56
  setIsOpen(false);
55
57
  handleGetUserAccountsDetail();
56
58
  handleGetUserDetails();
59
+ handleGetDefaultAccount();
57
60
  }, []);
58
61
  useEffect(() => {
59
62
  if (userAccountsDetail?.data) {
@@ -62,6 +65,7 @@ const HeaderComponent = (props) => {
62
65
  accounts: userAccountsDetail?.data,
63
66
  user: userDetails?.data,
64
67
  selectedAccount,
68
+ defaultAccount: getDefaultAccount?.data,
65
69
  }));
66
70
  const cookies = document.cookie;
67
71
  const cookieArray = cookies.split(";");
@@ -80,6 +84,7 @@ const HeaderComponent = (props) => {
80
84
  let developerArray = [];
81
85
  let instructorArray = [];
82
86
  let enterpriseArray = [];
87
+
83
88
  userAccountsDetail?.data?.results?.map((accountItem, idx) => {
84
89
  if (
85
90
  accountItem?.type === "PERSONAL" &&
@@ -170,6 +175,39 @@ const HeaderComponent = (props) => {
170
175
  document.removeEventListener("click", handleClickOutside);
171
176
  };
172
177
  }, [setIsOpen]);
178
+
179
+ // get current default account and store in cookie (from api)
180
+ useEffect(() => {
181
+ if (getDefaultAccount?.data) {
182
+ const date = new Date();
183
+ date.setDate(date.getDate() + 28);
184
+ document.cookie =
185
+ "defaultAccountID=" +
186
+ getDefaultAccount?.data?.id +
187
+ `; domain=${
188
+ window.location.href.includes("localhost")
189
+ ? ".localhost"
190
+ : ".learngual.com"
191
+ }; path=/; expires=${date.toUTCString()};`;
192
+
193
+ document.cookie =
194
+ "defaultAccountType=" +
195
+ getDefaultAccount?.data?.type +
196
+ `; domain=${
197
+ window.location.href.includes("localhost")
198
+ ? ".localhost"
199
+ : ".learngual.com"
200
+ }; path=/; expires=${date.toUTCString()};`;
201
+ }
202
+ }, [getDefaultAccount?.response]);
203
+
204
+ // get current default account and store in cookie from path
205
+ useEffect(() => {
206
+ if (pathname?.includes("personal")) {
207
+ // document.cookie = "activeAccount" + path;
208
+ }
209
+ }, []);
210
+
173
211
  return (
174
212
  <Navbar>
175
213
  <img src={logo} alt="Learngual logo" />
@@ -32,10 +32,11 @@ const SideMenu = ({
32
32
  )?.routes;
33
33
 
34
34
  const renderNavigationItem = (route, index) => {
35
- const { icon, text, notifications, path } = route;
35
+ const { icon, iconActive, text, notifications, path } = route;
36
36
  const handlePathCheck = () => {
37
37
  let statusText;
38
38
  console.log(window.location.pathname, "pathname");
39
+ // checking developer account routes
39
40
  if (
40
41
  (window.location.pathname.includes("api") && path === "/") ||
41
42
  (window.location.pathname === "/" && path === "/")
@@ -50,6 +51,146 @@ const SideMenu = ({
50
51
  }
51
52
  if (window.location.pathname.includes("report") && path === "/report") {
52
53
  return (statusText = true);
54
+ }
55
+
56
+ // checking personal account routes
57
+ if (
58
+ window.location.pathname.includes("/personal/dashboard") &&
59
+ path === "/personal/dashboard"
60
+ ) {
61
+ return (statusText = true);
62
+ }
63
+ if (
64
+ window.location.pathname.includes("/personal/library") &&
65
+ path === "/personal/library"
66
+ ) {
67
+ return (statusText = true);
68
+ }
69
+ if (
70
+ window.location.pathname.includes("/personal/courses") &&
71
+ path === "/personal/courses"
72
+ ) {
73
+ return (statusText = true);
74
+ }
75
+ if (
76
+ window.location.pathname.includes("/personal/reports") &&
77
+ path === "/personal/reports"
78
+ ) {
79
+ return (statusText = true);
80
+ }
81
+ if (
82
+ window.location.pathname.includes("/personal/messages") &&
83
+ path === "/personal/messages"
84
+ ) {
85
+ return (statusText = true);
86
+ }
87
+ if (
88
+ window.location.pathname.includes("/personal/addons") &&
89
+ path === "/personal/addons"
90
+ ) {
91
+ return (statusText = true);
92
+ }
93
+
94
+ // checking enterprise account routes
95
+
96
+ if (
97
+ window.location.pathname.includes("/enterprise/dashboard") &&
98
+ path === "/enterprise/dashboard"
99
+ ) {
100
+ return (statusText = true);
101
+ }
102
+ if (
103
+ window.location.pathname.includes("/enterprise/courses") &&
104
+ path === "/enterprise/courses"
105
+ ) {
106
+ return (statusText = true);
107
+ }
108
+ if (
109
+ window.location.pathname.includes("/enterprise/reports") &&
110
+ path === "/enterprise/reports/"
111
+ ) {
112
+ return (statusText = true);
113
+ }
114
+ if (
115
+ window.location.pathname.includes("/enterprise/manage-teams") &&
116
+ path === "/enterprise/manage-teams"
117
+ ) {
118
+ return (statusText = true);
119
+ }
120
+ if (
121
+ window.location.pathname.includes("/enterprise/messages") &&
122
+ path === "/enterprise/messages"
123
+ ) {
124
+ return (statusText = true);
125
+ }
126
+ if (
127
+ window.location.pathname.includes("/enterprise/announcements") &&
128
+ path === "/enterprise/announcements"
129
+ ) {
130
+ return (statusText = true);
131
+ }
132
+ if (
133
+ window.location.pathname.includes("/enterprise/file-manager") &&
134
+ path === "/enterprise/file-manager"
135
+ ) {
136
+ return (statusText = true);
137
+ }
138
+
139
+ // checking instructor account routes
140
+
141
+ if (
142
+ window.location.pathname.includes("/instructor/dashboard") &&
143
+ path === "/instructor/dashboard"
144
+ ) {
145
+ return (statusText = true);
146
+ }
147
+ if (
148
+ window.location.pathname.includes("/instructor/manage-courses") &&
149
+ path === "/instructor/manage-courses"
150
+ ) {
151
+ return (statusText = true);
152
+ }
153
+ if (
154
+ window.location.pathname.includes("/instructor/reports") &&
155
+ path === "/instructor/reports"
156
+ ) {
157
+ return (statusText = true);
158
+ }
159
+ if (
160
+ window.location.pathname.includes("/instructor/manage-teams") &&
161
+ path === "/instructor/manage-teams"
162
+ ) {
163
+ return (statusText = true);
164
+ }
165
+ if (
166
+ window.location.pathname.includes("/instructor/manage-students") &&
167
+ path === "/instructor/manage-students"
168
+ ) {
169
+ return (statusText = true);
170
+ }
171
+ if (
172
+ window.location.pathname.includes("/instructor/messages") &&
173
+ path === "/instructor/messages"
174
+ ) {
175
+ return (statusText = true);
176
+ }
177
+ if (
178
+ window.location.pathname.includes("/instructor/contracts") &&
179
+ path === "/instructor/contracts"
180
+ ) {
181
+ return (statusText = true);
182
+ }
183
+ if (
184
+ window.location.pathname.includes("/instructor/announcements") &&
185
+ path === "/instructor/announcements"
186
+ ) {
187
+ return (statusText = true);
188
+ }
189
+ if (
190
+ window.location.pathname.includes("/instructor/file-manager") &&
191
+ path === "/instructor/file-manager"
192
+ ) {
193
+ return (statusText = true);
53
194
  } else {
54
195
  return (statusText = false);
55
196
  }
@@ -72,13 +213,24 @@ const SideMenu = ({
72
213
  ) {
73
214
  window.location.href = `https://developer.learngual.com${path}`;
74
215
  }
216
+
217
+ if (
218
+ window.location.hostname.includes("staging")
219
+ ) {
220
+ window.location.href = `https://559staging.learngual.com/${path}`;
221
+ } else if (window.location.hostname.includes("localhost")) {
222
+ window.location.href = `http://localhost:${window.location.port}${path}`;
223
+ }
224
+
75
225
  }}
76
226
  // to={route.path}
77
227
  key={index}
78
228
  className={cx(`${route.text} ${active ? "active" : ""}`)}
79
229
  minimal={isOpen}
80
230
  >
81
- <IconContainer active={active}>{icon}</IconContainer>
231
+ <IconContainer active={active}>
232
+ {active ? iconActive : icon}
233
+ </IconContainer>
82
234
 
83
235
  <TextContainer minimal={isOpen}>{text}</TextContainer>
84
236
 
@@ -5,7 +5,7 @@ export const SideMenuContainer = styled.div`
5
5
  position: fixed;
6
6
 
7
7
  width: ${({ isOpen }) => (isOpen ? "239px" : "48px")};
8
- height: 625px;
8
+ height: 625px;
9
9
  // max-height: 609px;
10
10
  display: flex;
11
11
  flex-direction: column;
@@ -37,7 +37,7 @@ export const NavigationContainer = styled.div`
37
37
  display: flex;
38
38
  flex-direction: column;
39
39
  justify-content: center;
40
- margin-top: 20px;
40
+ margin-top: 5px;
41
41
  `;
42
42
  export const NavigationItemContainer = styled.p`
43
43
  text-decoration: none;
@@ -49,10 +49,14 @@ export const NavigationItemContainer = styled.p`
49
49
  position: relative;
50
50
  padding: ${({ minimal }) => (minimal ? "12px 16px" : "12px 12px")};
51
51
  color: ${({ active }) =>
52
- active ? "rgb(255, 255, 255)" : "rgba(255, 255, 255, 0.625)"};
52
+ active ? "rgb(255, 255, 255) !important" : "rgba(255, 255, 255, 0.625) !important"};
53
53
  &:hover {
54
- color: #ffffff;
54
+ color: #ffffff !important;
55
55
  background-color: #31cdcd;
56
+
57
+ > div {
58
+ opacity: 1;
59
+ }
56
60
  }
57
61
  &.active {
58
62
  background-color: rgba(0, 153, 153, 0.5);
@@ -78,12 +82,15 @@ export const IconContainer = styled.div`
78
82
  align-items: center;
79
83
  justify-content: center;
80
84
  font-size: 25px;
85
+ opacity: ${({ active }) => (active ? "1" : "0.625")};
81
86
  `;
82
87
 
83
88
  export const TextContainer = styled.div`
84
89
  display: ${({ minimal }) => (minimal ? "flex" : "none")};
85
90
  align-items: center;
86
91
  font-size: 16px;
92
+ letter-spacing: 0.32px;
93
+ font-weight: 600;
87
94
  `;
88
95
 
89
96
  export const NotificationCount = styled.div`