@campxdev/shared 1.11.7-0.alpha.52 → 1.11.7-0.alpha.54

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.7-0.alpha.52",
3
+ "version": "1.11.7-0.alpha.54",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -1,4 +1,3 @@
1
- import { AxiosError } from 'axios'
2
1
  import Cookies from 'js-cookie'
3
2
  import { useEffect, useState } from 'react'
4
3
  import { useNavigate } from 'react-router-dom'
@@ -95,98 +94,87 @@ function handleInstitutions(institutions) {
95
94
  }
96
95
  }
97
96
 
98
- const loginErrorHandler = ({
97
+ const useAuth = ({
98
+ permissionsEndpoint,
99
99
  loginUrl,
100
- setLoading,
101
- err,
102
- }: {
103
- loginUrl: string
104
- setLoading?: any
105
- err: AxiosError
106
- }) => {
107
- const navigate = useNavigate()
108
- setLoading && setLoading(false)
109
- const origin = window.location.origin
110
- const isStaging = origin.split('campx')[1] === '.dev'
111
-
112
- if (isDevelopment || isStaging) {
113
- openRootModal({
114
- key: 'login',
115
- contentData: {
116
- loginUrl,
117
- },
118
- dialogProps: {
119
- disableEscapeKeyDown: true,
120
- onClose: () => {},
121
- },
122
- })
123
- return
124
- } else {
125
- navigate('/auth/login')
126
- }
127
- }
128
-
129
- function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
100
+ }: AuthParams): AuthResponse => {
130
101
  const [loading, setLoading] = useState<boolean>(false)
131
- const [data, setData] = useState(null)
102
+ const [data, setData] = useState<any>(null)
132
103
  const { current } = InstitutionsStore.useState()
104
+ const navigate = useNavigate()
133
105
 
134
106
  const appInit = async () => {
135
107
  setLoading(true)
136
- axios
137
- .get(permissionsEndpoint)
138
- .then((res) => {
139
- const isAdmin = checkIsAdmin(res.data.user)
140
-
141
- setData(res.data)
142
- UserStore.update((s) => {
143
- s.username = res.data?.user?.username
144
- s.user = res.data?.user
145
- s.roles = res.data?.roles
146
- s.globalUserId = res.data?.globalUserId
147
- s.fullName = res.data?.fullName
148
- })
149
-
150
- PermissionsStore.update((s) => {
151
- s.permissions = {
152
- ...res.data?.permissions,
153
- can_settings_view: 1,
154
- can_dashboard_view: 1,
155
- can_individual_pages_view: 1,
156
- can_analatics_view: isAdmin,
157
- can_admin_view: isAdmin,
158
- can_my_mentees_view:
159
- res.data?.user?.isMentor &&
160
- res.data?.permissions.can_my_mentees_view,
161
- } as any
162
- s.applications = res.data?.applications ?? []
163
- s.institutionType = res.data?.institutionType
164
- s.masterInstitutionUniqueId = res.data?.masterInstitutionUniqueId
165
- s.masterInstitutionId = res.data?.masterInstitutionId
166
- s.isMasterInstitutionUser = res.data?.institutions
167
- ?.map((institution) => institution?.id)
168
- ?.includes(res?.data?.masterInstitutionUniqueId)
169
- s.isMasterInstitution = res.data?.isMasterInstitution
170
- s.isHomePageEnabled = res.data?.isHomePageEnabled
171
- })
172
-
173
- InstitutionsStore.update((s) => {
174
- s.institutions = res.data?.institutions
175
- s.current = res.data?.institutions.find(
176
- (item) => item.code === Cookies.get('campx_institution'),
177
- )
178
- })
108
+ try {
109
+ const res = await axios.get(permissionsEndpoint)
110
+ const isAdmin = checkIsAdmin(res.data.user)
111
+
112
+ setData(res.data)
113
+ UserStore.update((s) => {
114
+ s.username = res.data?.user?.username
115
+ s.user = res.data?.user
116
+ s.roles = res.data?.roles
117
+ s.globalUserId = res.data?.globalUserId
118
+ s.fullName = res.data?.fullName
119
+ })
179
120
 
180
- AssetsStore.update((s) => {
181
- s.logo = res.data?.assets.logo
182
- s.logo_square = res.data?.assets.logo_square
183
- })
121
+ PermissionsStore.update((s) => {
122
+ s.permissions = {
123
+ ...res.data?.permissions,
124
+ can_settings_view: 1,
125
+ can_dashboard_view: 1,
126
+ can_individual_pages_view: 1,
127
+ can_analatics_view: isAdmin,
128
+ can_admin_view: isAdmin,
129
+ can_my_mentees_view:
130
+ res.data?.user?.isMentor &&
131
+ res.data?.permissions.can_my_mentees_view,
132
+ }
133
+ s.applications = res.data?.applications ?? []
134
+ s.institutionType = res.data?.institutionType
135
+ s.masterInstitutionUniqueId = res.data?.masterInstitutionUniqueId
136
+ s.masterInstitutionId = res.data?.masterInstitutionId
137
+ s.isMasterInstitutionUser = res.data?.institutions
138
+ ?.map((institution) => institution?.id)
139
+ ?.includes(res?.data?.masterInstitutionUniqueId)
140
+ s.isMasterInstitution = res.data?.isMasterInstitution
141
+ s.isHomePageEnabled = res.data?.isHomePageEnabled
142
+ })
184
143
 
185
- setLoading(false)
144
+ InstitutionsStore.update((s) => {
145
+ s.institutions = res.data?.institutions
146
+ s.current = res.data?.institutions.find(
147
+ (item) => item.code === Cookies.get('campx_institution'),
148
+ )
186
149
  })
187
- .catch((err: AxiosError) => {
188
- loginErrorHandler({ loginUrl, setLoading, err })
150
+
151
+ AssetsStore.update((s) => {
152
+ s.logo = res.data?.assets.logo
153
+ s.logo_square = res.data?.assets.logo_square
189
154
  })
155
+
156
+ setLoading(false)
157
+ } catch (err: any) {
158
+ setLoading(false)
159
+ const origin = window.location.origin
160
+ const isStaging = origin.split('campx')[1] === '.dev'
161
+
162
+ if (isDevelopment || isStaging) {
163
+ openRootModal({
164
+ key: 'login',
165
+ contentData: {
166
+ loginUrl,
167
+ },
168
+ dialogProps: {
169
+ disableEscapeKeyDown: true,
170
+ onClose: () => {},
171
+ },
172
+ })
173
+ return
174
+ } else {
175
+ navigate('/auth/login')
176
+ }
177
+ }
190
178
  }
191
179
 
192
180
  useEffect(() => {
@@ -25,6 +25,7 @@ export const StyledHeaderContainer = styled.header`
25
25
 
26
26
  export const StyledLeftNavContainer = muiStyled('aside')(({ theme }) => ({
27
27
  width: sideNavWidth,
28
+ borderRadius: '8px 0px 0px 8px',
28
29
  background: theme.palette.secondary.main,
29
30
  color: 'white',
30
31
  overflowY: 'scroll',