@campxdev/shared 0.5.4 → 0.5.6
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/ChangePassword.tsx +151 -151
- package/src/components/Layout/Header/AppsMenu.tsx +1 -1
- package/src/components/Layout/Header/applications.ts +85 -0
- package/src/components/Layout/Header/assets/campx_square_small.svg +9 -0
- package/src/components/Layout/Header/assets/exams_small.svg +12 -0
- package/src/components/Layout/Header/assets/hostel_small.svg +13 -0
- package/src/components/Layout/Header/assets/index.ts +21 -23
- package/src/components/Layout/Header/assets/pay_small.svg +16 -0
- package/src/components/Layout/Header/assets/people_small.svg +9 -0
- package/src/contexts/Providers.tsx +25 -8
- package/src/hooks/useAppInit.ts +22 -0
- package/src/hooks/useAuth.ts +74 -72
- package/src/permissions/PermissionsStore.ts +271 -267
- package/src/utils/logout.ts +1 -1
- package/src/components/Layout/Header/applications.tsx +0 -74
- package/src/components/Layout/Header/assets/CampxHeader.svg +0 -14
- package/src/components/Layout/Header/assets/enrollxHeader.svg +0 -14
- package/src/components/Layout/Header/assets/examxHeader.svg +0 -17
- package/src/components/Layout/Header/assets/hostelxHeader.svg +0 -18
package/src/hooks/useAuth.ts
CHANGED
|
@@ -1,82 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import axios from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import {useEffect, useState} from 'react'
|
|
2
|
+
import {useQuery} from 'react-query'
|
|
3
|
+
import {toast} from 'react-toastify'
|
|
4
|
+
import axios from '../config/axios'
|
|
5
|
+
import {isDevelopment} from '../constants'
|
|
6
|
+
import {useLoginForm} from '../contexts/LoginFormProvider'
|
|
7
|
+
import {PermissionsStore} from '../permissions'
|
|
8
|
+
import {AssetsStore, UserStore} from '../shared-state'
|
|
9
9
|
|
|
10
|
-
const url = window.location.origin
|
|
10
|
+
const url = window.location.origin
|
|
11
11
|
|
|
12
12
|
function useAuth(): {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
loading: boolean
|
|
14
|
+
data: {
|
|
15
|
+
user?: any
|
|
16
|
+
roles?: any
|
|
17
|
+
username?: any
|
|
18
|
+
permissions?: any
|
|
19
|
+
assets?: {
|
|
20
|
+
logo: string
|
|
21
|
+
logo_square: string
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
24
|
} {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
setLoading(true);
|
|
25
|
+
const {openLoginForm} = useLoginForm()
|
|
26
|
+
const [loading, setLoading] = useState<boolean>(false)
|
|
27
|
+
const [data, setData] = useState(null)
|
|
28
|
+
const appInit = async () => {
|
|
29
|
+
setLoading(true)
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
axios
|
|
32
|
+
.get('/auth/my-permissions')
|
|
33
|
+
.then((res) => {
|
|
34
|
+
console.log(res.data)
|
|
35
|
+
setLoading(false)
|
|
36
|
+
setData(res.data)
|
|
37
|
+
UserStore.update((s) => {
|
|
38
|
+
s.username = res.data?.username
|
|
39
|
+
s.user = res.data?.user
|
|
40
|
+
s.roles = res.data?.roles
|
|
41
|
+
})
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
};
|
|
43
|
+
PermissionsStore.update((s) => {
|
|
44
|
+
s.permissions = {
|
|
45
|
+
...res.data?.permissions,
|
|
46
|
+
can_settings_view: 1,
|
|
47
|
+
can_dashboard_view: 1,
|
|
48
|
+
can_individual_pages_view: 1,
|
|
49
|
+
} as any
|
|
50
|
+
})
|
|
51
|
+
AssetsStore.update((s) => {
|
|
52
|
+
s.logo = res.data?.assets.logo
|
|
53
|
+
s.logo_square = res.data?.assets.logo_square
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
setLoading(false)
|
|
58
|
+
if (err.response.status !== 401) {
|
|
59
|
+
toast.error('Server Error')
|
|
60
|
+
}
|
|
61
|
+
if (isDevelopment) {
|
|
62
|
+
openLoginForm()
|
|
63
|
+
} else {
|
|
64
|
+
window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
}
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (window.location.pathname === '/') {
|
|
71
|
+
if (isDevelopment) {
|
|
72
|
+
window.location.replace(window.location.origin + '/campx_dev')
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
appInit()
|
|
76
|
+
}, [])
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
return {
|
|
79
|
+
loading: loading || !data?.permissions,
|
|
80
|
+
data,
|
|
81
|
+
}
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
export default useAuth
|
|
84
|
+
export default useAuth
|