l-min-components 1.0.321 → 1.0.325

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,8 +30,8 @@ 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);
@@ -56,14 +56,14 @@ const AppMainLayout = () => {
56
56
  hasLayoutBackgroundImage,
57
57
  setHasLayoutBackgroundImage,
58
58
  setSideMenuLayout,
59
- activePage,
60
- setActivePage,
61
- studyTab,
59
+ activePage,
60
+ setActivePage,
61
+ studyTab,
62
62
  setStudyTab,
63
63
  page,
64
64
  setPage,
65
- selectedCourseId,
66
- setSelectedCourseId
65
+ selectedCourseId,
66
+ setSelectedCourseId,
67
67
  }}
68
68
  >
69
69
  <Layout
@@ -80,7 +80,17 @@ const AppMainLayout = () => {
80
80
  <SideMenu
81
81
  user={user}
82
82
  routes={sideMenuOptions}
83
- userType={"developer"}
83
+ userType={
84
+ window.location.pathname.includes("enterprise")
85
+ ? "enterprise"
86
+ : window.location.pathname.includes("personal")
87
+ ? "personal"
88
+ : window.location.pathname.includes("instructor")
89
+ ? "instructor"
90
+ : window.location.pathname.includes("developer")
91
+ ? "developer"
92
+ : "developer"
93
+ }
84
94
  isOpen={isOpen}
85
95
  setIsOpen={setIsOpen}
86
96
  />
@@ -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,6 +155,7 @@ const AccountDropdown = (props) => {
152
155
  }`}
153
156
  onClick={() => {
154
157
  props?.setSelectedAccount(instructorItem);
158
+ handleSetDefaultAccount(instructorItem?.id);
155
159
  if (window.location.port) {
156
160
  window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/instructor`;
157
161
  } else {
@@ -187,6 +191,7 @@ const AccountDropdown = (props) => {
187
191
  }`}
188
192
  onClick={() => {
189
193
  props?.setSelectedAccount(enterpriseItem);
194
+ handleSetDefaultAccount(enterpriseItem?.id);
190
195
  if (window.location.port) {
191
196
  window.location.href = `${window.location.protocol}//${window.location.hostname}:${window.location.port}/enterprise`;
192
197
  } else {
@@ -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,32 @@ const HeaderComponent = (props) => {
170
175
  document.removeEventListener("click", handleClickOutside);
171
176
  };
172
177
  }, [setIsOpen]);
178
+
179
+ // get current default account and store in cookie
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
+
173
204
  return (
174
205
  <Navbar>
175
206
  <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,29 @@ 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
+ window.location.hostname.includes("enterprise")
220
+ ) {
221
+ window.location.href = `https://developer-staging-01.learngual.com${path}`;
222
+ } else if (window.location.hostname.includes("localhost")) {
223
+ window.location.href = `http://localhost:${window.location.port}${path}`;
224
+ } else if (
225
+ window.location.hostname.includes("enterprise") &&
226
+ !window.location.hostname.includes("staging")
227
+ ) {
228
+ window.location.href = `https://developer.learngual.com${path}`;
229
+ }
75
230
  }}
76
231
  // to={route.path}
77
232
  key={index}
78
233
  className={cx(`${route.text} ${active ? "active" : ""}`)}
79
234
  minimal={isOpen}
80
235
  >
81
- <IconContainer active={active}>{icon}</IconContainer>
236
+ <IconContainer active={active}>
237
+ {active ? iconActive : icon}
238
+ </IconContainer>
82
239
 
83
240
  <TextContainer minimal={isOpen}>{text}</TextContainer>
84
241
 
@@ -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;
@@ -53,6 +53,10 @@ export const NavigationItemContainer = styled.p`
53
53
  &:hover {
54
54
  color: #ffffff;
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`