@campxdev/shared 1.8.50 → 1.9.1

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.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/src/components/ApplicationProfile/ApplicationProfile.tsx +29 -27
  3. package/src/components/ApplicationProfile/UserProfileRelation.tsx +9 -53
  4. package/src/components/ErrorBoundary/ErrorFallback.tsx +5 -6
  5. package/src/components/Institutions/InsititutionsDialog.tsx +86 -0
  6. package/src/components/Institutions/InsititutionsNotAssignedDialog .tsx +12 -0
  7. package/src/components/Institutions/InstitutionsDropdown.tsx +33 -0
  8. package/src/components/Institutions/index.tsx +1 -0
  9. package/src/components/Institutions/services.ts +12 -0
  10. package/src/components/Layout/Header/AppHeader.tsx +3 -7
  11. package/src/components/Layout/Header/AppsMenu.tsx +6 -7
  12. package/src/components/Layout/Header/HeaderActions/HeaderActions.tsx +2 -2
  13. package/src/components/Layout/Header/applications.ts +7 -7
  14. package/src/components/LoginForm.tsx +21 -26
  15. package/src/components/ModalButtons/DialogButton.tsx +28 -24
  16. package/src/components/NoDataIllustration.tsx +8 -5
  17. package/src/components/Tables/common/NoRecordsFound.tsx +5 -1
  18. package/src/components/Tables/common/no-data-illu.svg +24 -1
  19. package/src/components/UploadButton/UploadButton.tsx +3 -3
  20. package/src/config/axios.ts +4 -3
  21. package/src/constants/UIConstants.ts +1 -1
  22. package/src/contexts/LoginFormProvider.tsx +3 -5
  23. package/src/contexts/Providers.tsx +40 -18
  24. package/src/contexts/RootModal.tsx +76 -0
  25. package/src/hooks/useAuth.ts +122 -27
  26. package/src/shared-state/InstitutionsStore.ts +8 -0
  27. package/src/shared-state/PermissionsStore.ts +5 -1
  28. package/src/components/Layout/Header/SchoolSwitch/SchoolSwitch.tsx +0 -33
  29. /package/src/components/ApplicationProfile/{Service.ts → services.ts} +0 -0
@@ -1,10 +1,13 @@
1
1
  import { AxiosError } from 'axios'
2
2
  import { useEffect, useState } from 'react'
3
3
  import { toast } from 'react-toastify'
4
+ import { institutions } from '../components/Institutions/services'
4
5
  import axios from '../config/axios'
5
6
  import { isDevelopment } from '../constants'
6
- import { useLoginForm } from '../contexts/LoginFormProvider'
7
- import { PermissionsStore, AssetsStore, UserStore } from '../shared-state'
7
+ import { urlTenantKey } from '../contexts/Providers'
8
+ import { openRootModal } from '../contexts/RootModal'
9
+ import { AssetsStore, PermissionsStore, UserStore } from '../shared-state'
10
+ import { InsititutionsStore } from '../shared-state/InstitutionsStore'
8
11
 
9
12
  const url = window.location.origin
10
13
 
@@ -34,7 +37,6 @@ const ApplicationObj = {
34
37
  exams: 'exams',
35
38
  hostel: 'hostels',
36
39
  }
37
-
38
40
  const checkIsAdmin = (user) => {
39
41
  let subDomain = window.location.host.split('.')?.slice(-3)[0]
40
42
  const localSubDomain = process.env.REACT_APP_SUBDOMAIN
@@ -62,11 +64,119 @@ const checkIsAdmin = (user) => {
62
64
  )
63
65
  return profile ? (profile.isAdmin == true ? 1 : 0) : 0
64
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
+ if (insititutionKey !== institutions[0]?.code) {
100
+ window.location.replace(
101
+ `${window.location.origin}/${urlTenantKey}/${institutions[0]?.code}`,
102
+ )
103
+ }
104
+ InsititutionsStore.update((s) => {
105
+ s.current = institutions[0]
106
+ s.institutions = institutions
107
+ })
108
+ }
109
+ if (institutions?.length > 1) {
110
+ if (!insititutionKey) {
111
+ openRootModal({
112
+ key: 'institutions',
113
+ dialogProps: {
114
+ disableEscapeKeyDown: true,
115
+ onClose: () => {},
116
+ },
117
+ })
118
+ }
119
+ if (
120
+ insititutionKey &&
121
+ !institutions?.find((item) => item.code === insititutionKey)
122
+ ) {
123
+ openRootModal({
124
+ key: 'institutions',
125
+ dialogProps: {
126
+ disableEscapeKeyDown: true,
127
+ onClose: () => {},
128
+ },
129
+ })
130
+ }
131
+ InsititutionsStore.update((s) => {
132
+ s.institutions = institutions
133
+ s.current = institutions.find((item) => item.code === insititutionKey)
134
+ })
135
+ }
136
+ }
137
+
138
+ const loginErrorHandler = ({
139
+ loginUrl,
140
+ setLoading,
141
+ err,
142
+ }: {
143
+ loginUrl: string
144
+ setLoading?: any
145
+ err: AxiosError
146
+ }) => {
147
+ setLoading && setLoading(false)
148
+ const origin = window.location.origin
149
+ const isStaging = origin.split('campx')[1] === '.dev'
150
+
151
+ if (isDevelopment || isStaging) {
152
+ openRootModal({
153
+ key: 'login',
154
+ contentData: {
155
+ loginUrl,
156
+ },
157
+ dialogProps: {
158
+ disableEscapeKeyDown: true,
159
+ onClose: () => {},
160
+ },
161
+ })
162
+ return
163
+ } else {
164
+ window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
165
+ }
166
+
167
+ if (err.response.status !== 401) {
168
+ if (err.response.status > 400 && err.response.status < 500) {
169
+ window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
170
+ } else {
171
+ toast.error('Server Error')
172
+ }
173
+ }
174
+ }
65
175
 
66
176
  function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
67
- const { openLoginForm } = useLoginForm()
68
177
  const [loading, setLoading] = useState<boolean>(false)
69
178
  const [data, setData] = useState(null)
179
+ const { current } = InsititutionsStore.useState()
70
180
 
71
181
  const appInit = async () => {
72
182
  setLoading(true)
@@ -76,7 +186,6 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
76
186
  const origin = window.location.origin
77
187
  const originSubdomain =
78
188
  window.location.host.split('.')?.slice(-3)[0] ?? 'ums'
79
-
80
189
  const isStaging = origin.split('campx')[1] === '.dev'
81
190
 
82
191
  if (isDevelopment == false && isStaging == false) {
@@ -89,7 +198,10 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
89
198
  }
90
199
  }
91
200
 
92
- setLoading(false)
201
+ if (res.data?.institutions) {
202
+ handleInstitutions(res.data?.institutions)
203
+ }
204
+
93
205
  setData(res.data)
94
206
  UserStore.update((s) => {
95
207
  s.username = res.data?.user?.username
@@ -115,28 +227,11 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
115
227
  s.logo = res.data?.assets.logo
116
228
  s.logo_square = res.data?.assets.logo_square
117
229
  })
230
+
231
+ setLoading(false)
118
232
  })
119
233
  .catch((err: AxiosError) => {
120
- setLoading(false)
121
- const origin = window.location.origin
122
- const isStaging = origin.split('campx')[1] === '.dev'
123
-
124
- if (isDevelopment || isStaging) {
125
- openLoginForm(loginUrl)
126
- return
127
- } else {
128
- window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
129
- }
130
-
131
- if (err.response.status !== 401) {
132
- if (err.response.status > 400 && err.response.status < 500) {
133
- window.location.replace(
134
- `https://www.id.campx.in/?redirect_to=${url}`,
135
- )
136
- } else {
137
- toast.error('Server Error')
138
- }
139
- }
234
+ loginErrorHandler({ loginUrl, setLoading, err })
140
235
  })
141
236
  }
142
237
 
@@ -145,7 +240,7 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
145
240
  }, [])
146
241
 
147
242
  return {
148
- loading: loading || !data?.permissions,
243
+ loading: loading || !data?.permissions || !current,
149
244
  data,
150
245
  }
151
246
  }
@@ -0,0 +1,8 @@
1
+ import { Store } from 'pullstate'
2
+
3
+ export const InsititutionsStore = new Store({
4
+ institutions: [],
5
+ loading: false,
6
+ error: null,
7
+ current: null,
8
+ })
@@ -349,7 +349,10 @@ export enum EnrollPermissions {
349
349
  ADMISSIONS_CONFIRM = 'can_admissions_confirm',
350
350
  CAN_ADMISSION_REJECT = 'can_admissions_reject',
351
351
  CAN_ADMISSIONS_DASHBOARD_VIEW = 'can_admission_dashboard_view',
352
-
352
+ CAN_ADMISSIONS_GRAPH_VIEW = 'can_admission_graph_view',
353
+ CAN_ADMISSIONS_LEAD_REMARKS = 'can_admission_lead_remarks',
354
+ CAN_ENROLL_X_AUDIT_LOGS = 'can_enroll_x_view_audit_logs',
355
+ CAN_ADMISSION_APPROVAL = 'can_admission_approvals',
353
356
  // CET & PHD
354
357
  CAN_PHD_FORM_VIEW = 'can_admissions_view_phd_applications',
355
358
  CAN_PHD_FORM_DOWNLOAD = 'can_admissions_download_phd_applications',
@@ -850,6 +853,7 @@ export enum Permission {
850
853
  CAN_COUNSELLOR_VIEW = 'can_counsellor_view',
851
854
  CAN_COUNSELLOR_ADD = 'can_counsellor_add',
852
855
  CAN_COUNSELLOR_DELETE = 'can_counsellor_delete',
856
+ CAN_COUNSELLOR_REPORT_VIEW = 'can_counsellor_report_view',
853
857
 
854
858
  // Notifications
855
859
  CAN_NOTIFICATION_ADD = 'can_notification_add',
@@ -1,33 +0,0 @@
1
- import { useState } from 'react'
2
- import { FormSingleSelect } from '../../../HookForm'
3
- import { SingleSelect } from '../../../Input'
4
-
5
- export default function SchoolSwitch() {
6
- const [state, setStatr] = useState()
7
-
8
- return (
9
- <SingleSelect
10
- containerProps={{
11
- sx: {
12
- width: '200px',
13
- },
14
- }}
15
- options={[
16
- {
17
- label: 'School 1',
18
- value: 'school1',
19
- },
20
- {
21
- label: 'School 2',
22
- value: 'school2',
23
- },
24
- {
25
- label: 'School 3',
26
- value: 'school3',
27
- },
28
- ]}
29
- value={state}
30
- onChange={(e) => setStatr(e.target.value)}
31
- />
32
- )
33
- }