@campxdev/shared 1.11.7-1.alpha.1 → 1.11.7-1.alpha.3

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-1.alpha.1",
3
+ "version": "1.11.7-1.alpha.3",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -37,20 +37,18 @@ export default function PageHeader({
37
37
  }: PageHeaderProps) {
38
38
  return (
39
39
  <StyledBox noPadding={noPadding}>
40
- <Box key="0">
40
+ <>
41
41
  {typeof title === 'string' ? (
42
42
  <Typography variant="h1">{title}</Typography>
43
43
  ) : (
44
44
  title
45
45
  )}
46
- </Box>
47
- <Box marginTop={'10px'} key="1">
48
46
  {typeof subtitle === 'string' ? (
49
47
  <Typography>{subtitle}</Typography>
50
48
  ) : (
51
- subtitle
49
+ <Box marginTop={'10px'}>{subtitle}</Box>
52
50
  )}
53
- </Box>
51
+ </>
54
52
  <Box className="actions">{actions}</Box>
55
53
  </StyledBox>
56
54
  )
@@ -205,11 +205,11 @@ export default function ReactTable({
205
205
  />
206
206
  <Table sx={{ position: 'relative' }} {...getTableProps()}>
207
207
  <TableHead>
208
- {headerGroups.map((headerGroup, rowIndex) => (
209
- <TableRow {...headerGroup.getHeaderGroupProps()}>
208
+ {headerGroups.map((headerGroup, index) => (
209
+ <TableRow key={index} {...headerGroup.getHeaderGroupProps()}>
210
210
  {showSerialNumber && <TableCell>S. No.</TableCell>}
211
- {headerGroup.headers.map((column: any, colIndex) => (
212
- <TableCell {...column.getHeaderProps()}>
211
+ {headerGroup.headers.map((column: any, index) => (
212
+ <TableCell key={index} {...column.getHeaderProps()}>
213
213
  {column.render('Header')}
214
214
  {column.sort && (
215
215
  <IconButton onClick={() => handleSortClick(column.id)}>
@@ -1,3 +1,4 @@
1
+ import { AxiosError } from 'axios'
1
2
  import Cookies from 'js-cookie'
2
3
  import { useEffect, useState } from 'react'
3
4
  import { useNavigate } from 'react-router-dom'
@@ -76,6 +77,7 @@ const getInstitutionKey = () => {
76
77
  return instituitionKey
77
78
  }
78
79
  }
80
+ const navigate = useNavigate()
79
81
 
80
82
  function handleInstitutions(institutions) {
81
83
  if (institutions?.length === 0) {
@@ -94,87 +96,95 @@ function handleInstitutions(institutions) {
94
96
  }
95
97
  }
96
98
 
97
- const useAuth = ({
98
- permissionsEndpoint,
99
+ const loginErrorHandler = ({
99
100
  loginUrl,
100
- }: AuthParams): AuthResponse => {
101
+ setLoading,
102
+ err,
103
+ }: {
104
+ loginUrl: string
105
+ setLoading?: any
106
+ err: AxiosError
107
+ }) => {
108
+ setLoading(false)
109
+
110
+ if (isDevelopment) {
111
+ openRootModal({
112
+ key: 'login',
113
+ contentData: {
114
+ loginUrl,
115
+ },
116
+ dialogProps: {
117
+ disableEscapeKeyDown: true,
118
+ onClose: () => {},
119
+ },
120
+ })
121
+ return
122
+ } else {
123
+ navigate('/auth/login')
124
+ }
125
+ }
126
+
127
+ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
101
128
  const [loading, setLoading] = useState<boolean>(false)
102
- const [data, setData] = useState<any>(null)
129
+ const [data, setData] = useState(null)
103
130
  const { current } = InstitutionsStore.useState()
104
- const navigate = useNavigate()
105
131
 
106
132
  const appInit = async () => {
107
133
  setLoading(true)
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
- })
120
-
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
- })
134
+ axios
135
+ .get(permissionsEndpoint)
136
+ .then((res) => {
137
+ const isAdmin = checkIsAdmin(res.data.user)
138
+
139
+ setData(res.data)
140
+ UserStore.update((s) => {
141
+ s.username = res.data?.user?.username
142
+ s.user = res.data?.user
143
+ s.roles = res.data?.roles
144
+ s.globalUserId = res.data?.globalUserId
145
+ s.fullName = res.data?.fullName
146
+ })
143
147
 
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
- )
149
- })
148
+ PermissionsStore.update((s) => {
149
+ s.permissions = {
150
+ ...res.data?.permissions,
151
+ can_settings_view: 1,
152
+ can_dashboard_view: 1,
153
+ can_individual_pages_view: 1,
154
+ can_analatics_view: isAdmin,
155
+ can_admin_view: isAdmin,
156
+ can_my_mentees_view:
157
+ res.data?.user?.isMentor &&
158
+ res.data?.permissions.can_my_mentees_view,
159
+ } as any
160
+ s.applications = res.data?.applications ?? []
161
+ s.institutionType = res.data?.institutionType
162
+ s.masterInstitutionUniqueId = res.data?.masterInstitutionUniqueId
163
+ s.masterInstitutionId = res.data?.masterInstitutionId
164
+ s.isMasterInstitutionUser = res.data?.institutions
165
+ ?.map((institution) => institution?.id)
166
+ ?.includes(res?.data?.masterInstitutionUniqueId)
167
+ s.isMasterInstitution = res.data?.isMasterInstitution
168
+ s.isHomePageEnabled = res.data?.isHomePageEnabled
169
+ })
150
170
 
151
- AssetsStore.update((s) => {
152
- s.logo = res.data?.assets.logo
153
- s.logo_square = res.data?.assets.logo_square
154
- })
171
+ InstitutionsStore.update((s) => {
172
+ s.institutions = res.data?.institutions
173
+ s.current = res.data?.institutions.find(
174
+ (item) => item.code === Cookies.get('campx_institution'),
175
+ )
176
+ })
155
177
 
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
- },
178
+ AssetsStore.update((s) => {
179
+ s.logo = res.data?.assets.logo
180
+ s.logo_square = res.data?.assets.logo_square
172
181
  })
173
- return
174
- } else {
175
- navigate('/auth/login')
176
- }
177
- }
182
+
183
+ setLoading(false)
184
+ })
185
+ .catch((err: AxiosError) => {
186
+ loginErrorHandler({ loginUrl, setLoading, err })
187
+ })
178
188
  }
179
189
 
180
190
  useEffect(() => {
@@ -25,9 +25,9 @@ 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',
29
28
  background: theme.palette.secondary.main,
30
29
  color: 'white',
30
+ borderRadius: '8px 0px 0px 8px',
31
31
  overflowY: 'scroll',
32
32
  '&::-webkit-scrollbar': {
33
33
  width: '0.5em',