@campxdev/shared 1.11.64 → 1.11.65
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
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { Store } from 'pullstate'
|
|
10
10
|
import { ReactNode, memo } from 'react'
|
|
11
11
|
import { Link, useMatch, useResolvedPath } from 'react-router-dom'
|
|
12
|
-
import { PermissionsStore } from '../../shared-state'
|
|
12
|
+
import { PermissionsStore, UserStore } from '../../shared-state'
|
|
13
13
|
import {
|
|
14
14
|
ListItemButton,
|
|
15
15
|
StyledChevronIcon,
|
|
@@ -23,14 +23,24 @@ const checkHasAccess = (
|
|
|
23
23
|
permissionKey,
|
|
24
24
|
institutionType,
|
|
25
25
|
permissions,
|
|
26
|
+
checkIsMasterInstitution,
|
|
27
|
+
masterInstitutionUniqueId,
|
|
28
|
+
isMasterInstitution,
|
|
29
|
+
user,
|
|
26
30
|
) => {
|
|
27
31
|
if (checkForMasterSlave) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
if (institutionType == 'MASTER_CHILD') {
|
|
33
|
+
if (checkIsMasterInstitution) {
|
|
34
|
+
return (
|
|
35
|
+
permissions[permissionKey] &&
|
|
36
|
+
user.institutionIds.includes(masterInstitutionUniqueId) &&
|
|
37
|
+
isMasterInstitution
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
return permissionKey ? permissions[permissionKey] : true
|
|
41
|
+
}
|
|
33
42
|
}
|
|
43
|
+
return permissionKey ? permissions[permissionKey] : true
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
const sideNavStore = new Store({
|
|
@@ -73,17 +83,30 @@ const RenderMenuItem = ({ menuItem }) => {
|
|
|
73
83
|
title,
|
|
74
84
|
icon,
|
|
75
85
|
permissionKey,
|
|
76
|
-
checkForMasterSlave
|
|
86
|
+
checkForMasterSlave,
|
|
87
|
+
checkIsMasterInstitution,
|
|
77
88
|
} = menuItem
|
|
89
|
+
|
|
78
90
|
let resolved = useResolvedPath(path)
|
|
79
91
|
let match = useMatch({ path: resolved.pathname, end: false })
|
|
80
92
|
|
|
81
|
-
const {
|
|
93
|
+
const {
|
|
94
|
+
permissions,
|
|
95
|
+
institutionType,
|
|
96
|
+
masterInstitutionUniqueId,
|
|
97
|
+
isMasterInstitution,
|
|
98
|
+
} = PermissionsStore.useState((s) => s)
|
|
99
|
+
const { user } = UserStore.useState((s) => s)
|
|
100
|
+
|
|
82
101
|
const hasAccess = checkHasAccess(
|
|
83
102
|
checkForMasterSlave,
|
|
84
103
|
permissionKey,
|
|
85
104
|
institutionType,
|
|
86
105
|
permissions,
|
|
106
|
+
checkIsMasterInstitution,
|
|
107
|
+
masterInstitutionUniqueId,
|
|
108
|
+
isMasterInstitution,
|
|
109
|
+
user,
|
|
87
110
|
)
|
|
88
111
|
|
|
89
112
|
if (children?.length)
|
|
@@ -126,7 +149,13 @@ const RenderMenuItem = ({ menuItem }) => {
|
|
|
126
149
|
|
|
127
150
|
const DropDownMenu = ({ path, title, icon, menuItems }) => {
|
|
128
151
|
const { activeKey } = sideNavStore.useState((s) => s)
|
|
129
|
-
const {
|
|
152
|
+
const {
|
|
153
|
+
permissions,
|
|
154
|
+
institutionType,
|
|
155
|
+
masterInstitutionUniqueId,
|
|
156
|
+
isMasterInstitution,
|
|
157
|
+
} = PermissionsStore.useState((s) => s)
|
|
158
|
+
const { user } = UserStore.useState((s) => s)
|
|
130
159
|
|
|
131
160
|
const validateDropdownAccess = () => {
|
|
132
161
|
if (process.env.NODE_ENV === 'development' && !permissions) return true
|
|
@@ -138,6 +167,10 @@ const DropDownMenu = ({ path, title, icon, menuItems }) => {
|
|
|
138
167
|
item?.permissionKey,
|
|
139
168
|
institutionType,
|
|
140
169
|
permissions,
|
|
170
|
+
item?.checkIsMasterInstitution,
|
|
171
|
+
masterInstitutionUniqueId,
|
|
172
|
+
isMasterInstitution,
|
|
173
|
+
user,
|
|
141
174
|
)
|
|
142
175
|
: accessIfNoKey,
|
|
143
176
|
)
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -236,6 +236,7 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
|
236
236
|
s.isMasterInstitutionUser = res.data?.institutions
|
|
237
237
|
?.map((institution) => institution?.id)
|
|
238
238
|
?.includes(res?.data?.masterInstitutionUniqueId)
|
|
239
|
+
s.isMasterInstitution = res.data?.isMasterInstitution
|
|
239
240
|
s.isHomePageEnabled = res.data?.isHomePageEnabled
|
|
240
241
|
})
|
|
241
242
|
AssetsStore.update((s) => {
|