@campxdev/shared 1.11.64 → 1.11.66

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": "@campxdev/shared",
3
- "version": "1.11.64",
3
+ "version": "1.11.66",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -31,9 +31,9 @@
31
31
  "@emotion/react": "^11.11.1",
32
32
  "@emotion/styled": "^11.11.0",
33
33
  "@hookform/resolvers": "^2.9.10",
34
- "@mui/icons-material": "^5.14.11",
34
+ "@mui/icons-material": "^5.15.18",
35
35
  "@mui/lab": "^5.0.0-alpha.146",
36
- "@mui/material": "^5.14.11",
36
+ "@mui/material": "^5.15.18",
37
37
  "@mui/x-date-pickers": "^6.16.0",
38
38
  "axios": "^0.27.2",
39
39
  "date-fns": "^2.28.0",
@@ -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
- return permissions[permissionKey] && institutionType == 'MASTER_CHILD'
29
- ? true
30
- : false
31
- } else {
32
- return permissionKey ? permissions[permissionKey] : true
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 = false,
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 { permissions, institutionType } = PermissionsStore.useState((s) => s)
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 { permissions, institutionType } = PermissionsStore.useState((s) => s)
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
  )
@@ -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) => {
@@ -49,8 +49,8 @@ const checkHasAccess = (
49
49
  institutionType,
50
50
  permissions,
51
51
  checkIsMasterInstitution,
52
- masterInstitutionUniqueId,
53
52
  isMasterInstitution,
53
+ masterInstitutionUniqueId,
54
54
  user,
55
55
  ) => {
56
56
  if (checkForMasterSlave) {