@campxdev/shared 1.11.63 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.11.63",
3
+ "version": "1.11.65",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -226,10 +226,10 @@ export const TimeLineComponent = ({
226
226
  }}
227
227
  >
228
228
  <StyledAvatar>
229
- {item?.fullName.charAt(0).toUpperCase()}
229
+ {item?.userName.charAt(0).toUpperCase()}
230
230
  </StyledAvatar>
231
231
  <Typography sx={{ fontSize: '13px', fontWeight: 900 }}>
232
- {item?.fullName}
232
+ {item?.userName}
233
233
  </Typography>
234
234
  </Typography>
235
235
  </Box>
@@ -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) => {
@@ -1,4 +1,5 @@
1
1
  import React from 'react'
2
+ import { UserStore } from '../shared-state'
2
3
  import {
3
4
  EnrollPermissions,
4
5
  Permission,
@@ -10,17 +11,30 @@ export default function ValidateAccess({
10
11
  accessKey,
11
12
  children,
12
13
  checkForMasterSlave = false,
14
+ checkIsMasterInstitution = false,
13
15
  }: {
14
16
  accessKey: Permission | SquarePermissions | EnrollPermissions
15
17
  children: React.ReactNode
16
18
  checkForMasterSlave?: boolean
19
+ checkIsMasterInstitution?: boolean
17
20
  }) {
18
- const { permissions, institutionType } = PermissionsStore.useState((s) => s)
21
+ const {
22
+ permissions,
23
+ institutionType,
24
+ masterInstitutionUniqueId,
25
+ isMasterInstitution,
26
+ } = PermissionsStore.useState((s) => s)
27
+
28
+ const { user } = UserStore.useState((s) => s)
19
29
  const hasAccess = checkHasAccess(
20
30
  checkForMasterSlave,
21
31
  accessKey,
22
32
  institutionType,
23
33
  permissions,
34
+ checkIsMasterInstitution,
35
+ isMasterInstitution,
36
+ masterInstitutionUniqueId,
37
+ user,
24
38
  )
25
39
 
26
40
  if (hasAccess) {
@@ -34,12 +48,22 @@ const checkHasAccess = (
34
48
  accessKey,
35
49
  institutionType,
36
50
  permissions,
51
+ checkIsMasterInstitution,
52
+ isMasterInstitution,
53
+ masterInstitutionUniqueId,
54
+ user,
37
55
  ) => {
38
56
  if (checkForMasterSlave) {
39
- return permissions[accessKey] && institutionType == 'MASTER_CHILD'
40
- ? true
41
- : false
42
- } else {
43
- return accessKey ? permissions[accessKey] : true
57
+ if (institutionType == 'MASTER_CHILD') {
58
+ if (checkIsMasterInstitution) {
59
+ return (
60
+ permissions[accessKey] &&
61
+ user.institutionIds.includes(masterInstitutionUniqueId) &&
62
+ isMasterInstitution
63
+ )
64
+ }
65
+ return accessKey ? permissions[accessKey] : true
66
+ }
44
67
  }
68
+ return accessKey ? permissions[accessKey] : true
45
69
  }