@campxdev/shared 1.8.49-alpha.3 → 1.8.49-alpha.5
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 +1 -1
- package/src/components/Institutions/InsititutionsNotAssignedDialog .tsx +12 -0
- package/src/components/Institutions/InstitutionsDropdown.tsx +1 -0
- package/src/components/Layout/Header/AppsMenu.tsx +6 -7
- package/src/contexts/RootModal.tsx +4 -1
- package/src/hooks/useAuth.ts +62 -8
- package/src/hooks/useInstitution.ts +0 -94
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material'
|
|
2
|
+
|
|
3
|
+
export default function InsititutionsNotAssignedDialog() {
|
|
4
|
+
return (
|
|
5
|
+
<Box padding="40px 10px">
|
|
6
|
+
<Typography variant="body2" textAlign="center">
|
|
7
|
+
You have not been assigned to any institutions. Please contact your
|
|
8
|
+
administrator.
|
|
9
|
+
</Typography>
|
|
10
|
+
</Box>
|
|
11
|
+
)
|
|
12
|
+
}
|
|
@@ -8,6 +8,7 @@ export default function SchoolSwitch() {
|
|
|
8
8
|
const { current, institutions } = InsititutionsStore.useState((s) => s)
|
|
9
9
|
|
|
10
10
|
const handleChange = (e) => {
|
|
11
|
+
localStorage.setItem('institution_key', e.target.value)
|
|
11
12
|
window.location.replace(
|
|
12
13
|
`${window.location.origin}/${urlTenantKey}/${e.target.value}`,
|
|
13
14
|
)
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
import AppsOutageIcon from '@mui/icons-material/AppsOutage'
|
|
1
2
|
import { Box, Menu, Typography, styled } from '@mui/material'
|
|
2
|
-
import Cookies from 'js-cookie'
|
|
3
3
|
import { useState } from 'react'
|
|
4
|
+
import { campxTenantKey, instituitionKey } from '../../../contexts/Providers'
|
|
5
|
+
import { PermissionsStore } from '../../../shared-state'
|
|
4
6
|
import { applications } from './applications'
|
|
5
7
|
import { AppsIcon } from './icons'
|
|
6
8
|
import {
|
|
7
9
|
StyledDescription,
|
|
8
10
|
StyledIconButton,
|
|
11
|
+
StyledImageBox,
|
|
12
|
+
StyledLink,
|
|
9
13
|
StyledMenuItem,
|
|
10
14
|
StyledMenuItemContainer,
|
|
11
|
-
StyledLink,
|
|
12
|
-
StyledImageBox,
|
|
13
15
|
} from './styles'
|
|
14
|
-
import { PermissionsStore } from '../../../shared-state'
|
|
15
|
-
import AppsOutageIcon from '@mui/icons-material/AppsOutage'
|
|
16
|
-
export const campxTenantKey = Cookies.get('campx_tenant')
|
|
17
16
|
|
|
18
17
|
const AppsMenu = () => {
|
|
19
18
|
const permissionState = PermissionsStore.useState((s) => s)
|
|
@@ -74,7 +73,7 @@ const AppsMenu = () => {
|
|
|
74
73
|
{applicationList.map((item, index) => {
|
|
75
74
|
return (
|
|
76
75
|
<StyledLink
|
|
77
|
-
href={item.path + `/${campxTenantKey
|
|
76
|
+
href={item.path + `/${campxTenantKey}/${instituitionKey}`}
|
|
78
77
|
key={index}
|
|
79
78
|
>
|
|
80
79
|
<StyledMenuItemContainer
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Store } from 'pullstate'
|
|
2
2
|
import { CustomDialog, LoginForm } from '../components'
|
|
3
|
-
import InsititutionsDialog from '../components/Institutions'
|
|
4
3
|
import { DialogProps } from '@mui/material'
|
|
4
|
+
import InsititutionsDialog from '../components/Institutions'
|
|
5
|
+
import InsititutionsNotAssignedDialog from '../components/Institutions/InsititutionsNotAssignedDialog '
|
|
5
6
|
|
|
6
7
|
const getRootDialogContent = (
|
|
7
8
|
key: string,
|
|
@@ -13,6 +14,8 @@ const getRootDialogContent = (
|
|
|
13
14
|
)
|
|
14
15
|
case 'institutions':
|
|
15
16
|
return ({ close }) => <InsititutionsDialog close={close} />
|
|
17
|
+
case 'institutions-not-assigned':
|
|
18
|
+
return ({ close }) => <InsititutionsNotAssignedDialog />
|
|
16
19
|
default:
|
|
17
20
|
return () => <></>
|
|
18
21
|
}
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { urlTenantKey } from '../contexts/Providers'
|
|
|
8
8
|
import { openRootModal } from '../contexts/RootModal'
|
|
9
9
|
import { AssetsStore, PermissionsStore, UserStore } from '../shared-state'
|
|
10
10
|
import { InsititutionsStore } from '../shared-state/InstitutionsStore'
|
|
11
|
-
import useInstitution from './useInstitution'
|
|
12
11
|
|
|
13
12
|
const url = window.location.origin
|
|
14
13
|
|
|
@@ -65,6 +64,59 @@ const checkIsAdmin = (user) => {
|
|
|
65
64
|
)
|
|
66
65
|
return profile ? (profile.isAdmin == true ? 1 : 0) : 0
|
|
67
66
|
}
|
|
67
|
+
const getInstitutionKey = () => {
|
|
68
|
+
const instituitionKey = window.location.pathname.split('/')[2]
|
|
69
|
+
if (!instituitionKey) {
|
|
70
|
+
const localInstituitionKey = localStorage.getItem('institution_key')
|
|
71
|
+
if (localInstituitionKey) {
|
|
72
|
+
return localInstituitionKey
|
|
73
|
+
} else {
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
return instituitionKey
|
|
78
|
+
}
|
|
79
|
+
return instituitionKey
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function handleInstitutions(institutions) {
|
|
83
|
+
const insititutionKey = getInstitutionKey()
|
|
84
|
+
if (institutions?.length === 0) {
|
|
85
|
+
openRootModal({
|
|
86
|
+
key: 'institutions-not-assigned',
|
|
87
|
+
dialogProps: {
|
|
88
|
+
disableEscapeKeyDown: true,
|
|
89
|
+
onClose: () => {},
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
if (institutions?.length === 1) {
|
|
94
|
+
if (!insititutionKey) {
|
|
95
|
+
window.location.replace(
|
|
96
|
+
`${window.location.origin}/${urlTenantKey}/${institutions[0]?.code}`,
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
InsititutionsStore.update((s) => {
|
|
100
|
+
s.current = institutions[0]
|
|
101
|
+
s.institutions = institutions
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
if (institutions?.length > 1) {
|
|
105
|
+
if (!insititutionKey) {
|
|
106
|
+
openRootModal({
|
|
107
|
+
key: 'institutions',
|
|
108
|
+
dialogProps: {
|
|
109
|
+
disableEscapeKeyDown: true,
|
|
110
|
+
onClose: () => {},
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
InsititutionsStore.update((s) => {
|
|
115
|
+
s.institutions = institutions
|
|
116
|
+
s.current = institutions.find((item) => item.code === insititutionKey)
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
}
|
|
68
120
|
|
|
69
121
|
const loginErrorHandler = ({
|
|
70
122
|
loginUrl,
|
|
@@ -75,7 +127,7 @@ const loginErrorHandler = ({
|
|
|
75
127
|
setLoading?: any
|
|
76
128
|
err: AxiosError
|
|
77
129
|
}) => {
|
|
78
|
-
|
|
130
|
+
setLoading && setLoading(false)
|
|
79
131
|
const origin = window.location.origin
|
|
80
132
|
const isStaging = origin.split('campx')[1] === '.dev'
|
|
81
133
|
|
|
@@ -107,9 +159,7 @@ const loginErrorHandler = ({
|
|
|
107
159
|
function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
108
160
|
const [loading, setLoading] = useState<boolean>(false)
|
|
109
161
|
const [data, setData] = useState(null)
|
|
110
|
-
const { current } = InsititutionsStore.useState(
|
|
111
|
-
|
|
112
|
-
const { loading: loadingInstituition } = useInstitution()
|
|
162
|
+
const { current } = InsititutionsStore.useState()
|
|
113
163
|
|
|
114
164
|
const appInit = async () => {
|
|
115
165
|
setLoading(true)
|
|
@@ -119,7 +169,6 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
|
119
169
|
const origin = window.location.origin
|
|
120
170
|
const originSubdomain =
|
|
121
171
|
window.location.host.split('.')?.slice(-3)[0] ?? 'ums'
|
|
122
|
-
|
|
123
172
|
const isStaging = origin.split('campx')[1] === '.dev'
|
|
124
173
|
|
|
125
174
|
if (isDevelopment == false && isStaging == false) {
|
|
@@ -132,7 +181,10 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
|
132
181
|
}
|
|
133
182
|
}
|
|
134
183
|
|
|
135
|
-
|
|
184
|
+
if (res.data?.user?.institutions) {
|
|
185
|
+
handleInstitutions(res.data?.user?.institutions)
|
|
186
|
+
}
|
|
187
|
+
|
|
136
188
|
setData(res.data)
|
|
137
189
|
UserStore.update((s) => {
|
|
138
190
|
s.username = res.data?.user?.username
|
|
@@ -158,6 +210,8 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
|
158
210
|
s.logo = res.data?.assets.logo
|
|
159
211
|
s.logo_square = res.data?.assets.logo_square
|
|
160
212
|
})
|
|
213
|
+
|
|
214
|
+
setLoading(false)
|
|
161
215
|
})
|
|
162
216
|
.catch((err: AxiosError) => {
|
|
163
217
|
loginErrorHandler({ loginUrl, setLoading, err })
|
|
@@ -169,7 +223,7 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
|
169
223
|
}, [])
|
|
170
224
|
|
|
171
225
|
return {
|
|
172
|
-
loading: loading || !data?.permissions || !current
|
|
226
|
+
loading: loading || !data?.permissions || !current,
|
|
173
227
|
data,
|
|
174
228
|
}
|
|
175
229
|
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
import { institutions } from '../components/Institutions/services'
|
|
3
|
-
import { urlTenantKey } from '../contexts/Providers'
|
|
4
|
-
import { openRootModal } from '../contexts/RootModal'
|
|
5
|
-
import { InsititutionsStore } from '../shared-state/InstitutionsStore'
|
|
6
|
-
|
|
7
|
-
const getInstitutionKey = () => {
|
|
8
|
-
const instituitionKey = window.location.pathname.split('/')[2]
|
|
9
|
-
// if (!instituitionKey) {
|
|
10
|
-
// const localInstituitionKey = localStorage.getItem('institution_key')
|
|
11
|
-
// if (localInstituitionKey) {
|
|
12
|
-
// return localInstituitionKey
|
|
13
|
-
// } else {
|
|
14
|
-
// return null
|
|
15
|
-
// }
|
|
16
|
-
// } else {
|
|
17
|
-
// return instituitionKey
|
|
18
|
-
// }
|
|
19
|
-
return instituitionKey
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const getInstitutions = async (startLoading, stopLoading) => {
|
|
23
|
-
const insititutionKey = getInstitutionKey()
|
|
24
|
-
try {
|
|
25
|
-
startLoading()
|
|
26
|
-
const data = await institutions.fetchInsititutions()
|
|
27
|
-
InsititutionsStore.update((s) => {
|
|
28
|
-
s.institutions = data?.institutions
|
|
29
|
-
})
|
|
30
|
-
if (data?.institutions?.length === 1 && !insititutionKey) {
|
|
31
|
-
window.location.replace(
|
|
32
|
-
`${window.location.origin}/${urlTenantKey}/${data?.institutions[0]?.code}`,
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
if (data?.institutions?.length > 1 && !insititutionKey) {
|
|
36
|
-
openRootModal({
|
|
37
|
-
key: 'institutions',
|
|
38
|
-
dialogProps: {
|
|
39
|
-
disableEscapeKeyDown: true,
|
|
40
|
-
onClose: () => {},
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
stopLoading()
|
|
45
|
-
} catch (error) {
|
|
46
|
-
stopLoading()
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const getInstitutionsByCode = async (code, startLoading, stopLoading) => {
|
|
51
|
-
try {
|
|
52
|
-
startLoading()
|
|
53
|
-
const data = await institutions.fetchInsititutionByCode(code)
|
|
54
|
-
InsititutionsStore.update((s) => {
|
|
55
|
-
s.current = data
|
|
56
|
-
})
|
|
57
|
-
stopLoading()
|
|
58
|
-
} catch (error) {
|
|
59
|
-
stopLoading()
|
|
60
|
-
openRootModal({
|
|
61
|
-
key: 'institutions',
|
|
62
|
-
dialogProps: {
|
|
63
|
-
disableEscapeKeyDown: true,
|
|
64
|
-
onClose: () => {},
|
|
65
|
-
},
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default function useInstitution() {
|
|
71
|
-
const insititutionKey = getInstitutionKey()
|
|
72
|
-
const [loading, setLoading] = useState(false)
|
|
73
|
-
|
|
74
|
-
const startLoading = () => {
|
|
75
|
-
setLoading(true)
|
|
76
|
-
}
|
|
77
|
-
const stopLoading = () => {
|
|
78
|
-
setLoading(false)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
getInstitutions(startLoading, stopLoading)
|
|
83
|
-
}, [insititutionKey])
|
|
84
|
-
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
if (insititutionKey) {
|
|
87
|
-
getInstitutionsByCode(insititutionKey, startLoading, stopLoading)
|
|
88
|
-
}
|
|
89
|
-
}, [insititutionKey])
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
loading: loading,
|
|
93
|
-
}
|
|
94
|
-
}
|