@antscorp/antsomi-ui 1.3.5-beta.607 → 1.3.5-beta.609

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.
@@ -15,5 +15,6 @@ export interface AccountSharingProps {
15
15
  isShareAccountAccess?: boolean;
16
16
  u_ogs: string;
17
17
  callbackLogout?: () => void;
18
+ usePrivilege?: boolean;
18
19
  }
19
20
  export declare const AccountSharing: React.FC<AccountSharingProps>;
@@ -19,7 +19,7 @@ import CloseIcon from './icons/close';
19
19
  import SearchIcon from './icons/search';
20
20
  import { InnerCardStyled, InputSearchStyled, PackageSharingStyled, TriggerPopoverStyled, } from './styled';
21
21
  // Utils
22
- import { formatUserId, removeAppCookieSessionSubdomain, removeAppCookieSessionSubdomainPrefix, } from '@antscorp/antsomi-ui/es/utils';
22
+ import { formatUserId, getObjectPropSafely, removeAppCookieSessionSubdomain, removeAppCookieSessionSubdomainPrefix, } from '@antscorp/antsomi-ui/es/utils';
23
23
  import { translate } from './utils';
24
24
  import Icon from '@antscorp/icons';
25
25
  import { useDebounce } from '@antscorp/antsomi-ui/es/hooks/useDebounceV2';
@@ -40,7 +40,7 @@ const InputSearch = props => {
40
40
  };
41
41
  export const AccountSharing = props => {
42
42
  var _a;
43
- const { permissionDomain = '', iamDomain = '', token = '', accountId = 0, networkId = 0, appCode = '', lang = 'en', translateData = DEFAULT_TRANSLATE_DATA, urlEditProfile = '', callbackGetInfoAccount, urlLogout = '', isShowSharing = false, isShareAccountAccess = false, u_ogs = '', callbackLogout, } = props;
43
+ const { permissionDomain = '', iamDomain = '', token = '', accountId = 0, networkId = 0, appCode = '', lang = 'en', translateData = DEFAULT_TRANSLATE_DATA, urlEditProfile = '', callbackGetInfoAccount, urlLogout = '', isShowSharing = false, isShareAccountAccess = false, u_ogs = '', callbackLogout, usePrivilege = true, } = props;
44
44
  const { appConfig } = useAppConfigContext();
45
45
  const { env } = appConfig;
46
46
  const selectedNetworkRef = useRef();
@@ -120,6 +120,77 @@ export const AccountSharing = props => {
120
120
  }
121
121
  });
122
122
  };
123
+ const getMenuUrl = (menu, userId = '') => {
124
+ if (!menu || !menu.menu_path) {
125
+ return '';
126
+ }
127
+ const { app_domain: appDomain, app_path: appPath, menu_path: menuPath } = menu;
128
+ return (appDomain + appPath + menuPath).replaceAll(':user_id', userId);
129
+ };
130
+ const redirectFirstMenu = (data, redirectAccountId) => {
131
+ if (!Array.isArray(data)) {
132
+ return false;
133
+ }
134
+ const arrMenus = getObjectPropSafely(() => [...data].sort((first, second) => first.app_order - second.app_order)[0].childs) || [];
135
+ if (arrMenus && arrMenus.length) {
136
+ const firstMenu = arrMenus
137
+ .filter(menu => +menu.show_hide)
138
+ .sort((first, second) => first.menu_order - second.menu_order)[0];
139
+ if (firstMenu) {
140
+ const redirectUrl = getMenuUrl(firstMenu, redirectAccountId);
141
+ window.location.href = redirectUrl;
142
+ }
143
+ }
144
+ };
145
+ const buildListAppMenus = (data, userId) => {
146
+ if (!Array.isArray(data) || !data.length) {
147
+ return [];
148
+ }
149
+ let arrMenus = [];
150
+ data.forEach(item => {
151
+ if (item.menu_id) {
152
+ arrMenus.push(getMenuUrl(item, userId));
153
+ }
154
+ if (item.childs && item.childs.length) {
155
+ arrMenus = arrMenus.concat(buildListAppMenus(item.childs, userId));
156
+ }
157
+ });
158
+ return arrMenus;
159
+ };
160
+ const checkRedirectHomePage = (homePage, data, userId) => {
161
+ const convertedHomePage = String(homePage).replace(/:user_id/g, userId);
162
+ if (!Array.isArray(data) || !data.length) {
163
+ window.location.href = convertedHomePage;
164
+ return;
165
+ }
166
+ const arrMenus = buildListAppMenus(data, userId);
167
+ if (!arrMenus.some(url => convertedHomePage.includes(url))) {
168
+ return redirectFirstMenu(data, userId);
169
+ }
170
+ window.location.href = convertedHomePage;
171
+ };
172
+ const getAppsMenus = ({ token, userId, accountId, homePage }) => {
173
+ if (permissionDomain && token && userId && accountId) {
174
+ const apiUrl = permissionDomain + (usePrivilege ? '/api/privilege/index' : '/api/permission/index');
175
+ return axios({
176
+ url: apiUrl,
177
+ params: {
178
+ type: 'list-app',
179
+ _token: token,
180
+ _user_id: userId,
181
+ _account_id: accountId,
182
+ _lang: 'en',
183
+ hasChild: true,
184
+ from: 'login',
185
+ },
186
+ }).then(res => {
187
+ if (res && res.data) {
188
+ checkRedirectHomePage(homePage, res.data.data, userId);
189
+ }
190
+ });
191
+ }
192
+ return null;
193
+ };
123
194
  const getListAccountSharing = () => {
124
195
  if (isShareAccountAccess) {
125
196
  const params = {
@@ -208,7 +279,11 @@ export const AccountSharing = props => {
208
279
  });
209
280
  }
210
281
  }, [limitAccount]);
211
- const filterListNetwork = useMemo(() => listNetworks.filter((netWork) => netWork.networkName.toLocaleLowerCase().indexOf(portalSearch.toLocaleLowerCase()) !== -1), [listNetworks, portalSearch]);
282
+ const filterListNetwork = useMemo(() => listNetworks.filter((netWork) => netWork.networkName.toLocaleLowerCase().indexOf(portalSearch.toLocaleLowerCase()) !==
283
+ -1 ||
284
+ String(netWork.networkId)
285
+ .toLocaleLowerCase()
286
+ .indexOf(portalSearch.toLocaleLowerCase()) !== -1), [listNetworks, portalSearch]);
212
287
  const logAccountSwitch = (switchAccountId) => __awaiter(void 0, void 0, void 0, function* () {
213
288
  // setIsShowLoading(true)
214
289
  if (switchAccountId && isShareAccountAccess) {
@@ -343,7 +418,13 @@ export const AccountSharing = props => {
343
418
  }
344
419
  }
345
420
  if (selectedNetworkRef.current && selectedNetworkRef.current.homePage) {
346
- window.location.href = selectedNetworkRef.current.homePage.replaceAll(':user_id', accountId);
421
+ getAppsMenus({
422
+ token: postParam.token,
423
+ userId: accountId,
424
+ accountId,
425
+ homePage: selectedNetworkRef.current.homePage,
426
+ });
427
+ // window.location.href = selectedNetworkRef.current.homePage.replaceAll(':user_id', accountId);
347
428
  }
348
429
  };
349
430
  const handleLoginData = (data = null) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.607",
3
+ "version": "1.3.5-beta.609",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",