@campxdev/shared 1.11.7-1.alpha.1 → 1.11.7-1.alpha.10
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/LoginForm.tsx +3 -2
- package/src/components/PageHeader.tsx +3 -5
- package/src/components/Tables/ReactTable/ReactTable.tsx +4 -4
- package/src/config/axios.ts +12 -10
- package/src/constants/isDevelopment.ts +1 -4
- package/src/contexts/Providers.tsx +38 -5
- package/src/hooks/useAuth.ts +6 -10
- package/src/layouts/Components/styles.tsx +1 -1
- package/yarn-error.log +0 -15782
package/package.json
CHANGED
|
@@ -61,10 +61,11 @@ export function LoginForm({
|
|
|
61
61
|
...deviceState.deviceInformation,
|
|
62
62
|
},
|
|
63
63
|
})
|
|
64
|
-
Cookies.set('campx_tenant', res?.data?.subDomain)
|
|
65
64
|
Cookies.set('campx_session_key', res.data?.token)
|
|
65
|
+
Cookies.set('campx_tenant', res.data?.subDomain)
|
|
66
66
|
Cookies.set('campx_institution', res.data?.institutionCode)
|
|
67
|
-
window.location.
|
|
67
|
+
window.location.href = `/${res.data.institutionCode}`
|
|
68
|
+
//window.location.reload()
|
|
68
69
|
} catch (err) {
|
|
69
70
|
// eslint-disable-next-line no-console
|
|
70
71
|
console.log(err)
|
|
@@ -37,20 +37,18 @@ export default function PageHeader({
|
|
|
37
37
|
}: PageHeaderProps) {
|
|
38
38
|
return (
|
|
39
39
|
<StyledBox noPadding={noPadding}>
|
|
40
|
-
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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)}>
|
package/src/config/axios.ts
CHANGED
|
@@ -3,14 +3,15 @@ import Cookies from 'js-cookie'
|
|
|
3
3
|
import { toast } from 'react-toastify'
|
|
4
4
|
import { NetworkStore } from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
|
|
5
5
|
|
|
6
|
+
const isDevelopment = process.env.NODE_ENV == 'development'
|
|
7
|
+
|
|
6
8
|
const sessionKey = Cookies.get('campx_session_key')
|
|
7
|
-
const
|
|
8
|
-
Cookies.get('campx_tenant')
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const openPaymentsKey = Cookies.get('campx_open_payments_key')
|
|
9
|
+
const tenantCode = isDevelopment
|
|
10
|
+
? Cookies.get('campx_tenant')
|
|
11
|
+
: window.location.hostname.split('.')[0]
|
|
12
|
+
const institutionCode = window.location.pathname.split('/')[1]
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
+
const openPaymentsKey = Cookies.get('campx_open_payments_key')
|
|
14
15
|
|
|
15
16
|
export const formatParams = (params) => {
|
|
16
17
|
return Object.fromEntries(
|
|
@@ -21,15 +22,16 @@ export const formatParams = (params) => {
|
|
|
21
22
|
)
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
console.log(institutionId, sessionKey, 'test')
|
|
25
|
-
|
|
26
25
|
let axios = Axios.create({
|
|
27
26
|
baseURL: process.env.REACT_APP_API_HOST,
|
|
28
27
|
withCredentials: true,
|
|
29
28
|
headers: {
|
|
30
|
-
'x-tenant-id':
|
|
31
|
-
'x-institution-code':
|
|
29
|
+
'x-tenant-id': tenantCode,
|
|
30
|
+
'x-institution-code': institutionCode,
|
|
32
31
|
campx_session_key: sessionKey,
|
|
32
|
+
...(openPaymentsKey && {
|
|
33
|
+
campx_open_payments_key: openPaymentsKey,
|
|
34
|
+
}),
|
|
33
35
|
},
|
|
34
36
|
})
|
|
35
37
|
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
export const isDevelopment =
|
|
2
|
-
process.env.NODE_ENV === 'development' ||
|
|
3
|
-
window.location.origin.split('campx')[1] === '.dev'
|
|
4
|
-
|
|
1
|
+
export const isDevelopment = process.env.NODE_ENV === 'development'
|
|
5
2
|
export const isSetup = window.location.hostname.split('.').includes('setup')
|
|
@@ -4,20 +4,53 @@ import MuiThemeProvider from '../theme/MuiThemeProvider'
|
|
|
4
4
|
import QueryClientProvider from './QueryClientProvider'
|
|
5
5
|
|
|
6
6
|
import Cookies from 'js-cookie'
|
|
7
|
-
import { ReactNode } from 'react'
|
|
7
|
+
import { ReactNode, useEffect } from 'react'
|
|
8
8
|
import { ToastContainer } from '../components'
|
|
9
9
|
import DialogProvider from '../components/DrawerWrapper/DrawerWrapper'
|
|
10
10
|
import GlobalNetworkLoadingIndicator from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
|
|
11
11
|
import ErrorModalProvider from '../components/ErrorModalWrapper/ErrorModalWrapper'
|
|
12
12
|
import RootModal from './RootModal'
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const
|
|
14
|
+
const isDevelopment = process.env.NODE_ENV == 'development'
|
|
15
|
+
|
|
16
|
+
export const campxTenantKey = isDevelopment
|
|
17
|
+
? Cookies.get('campx_tenant')
|
|
18
|
+
: window.location.hostname.split('.')[0]
|
|
19
|
+
export const urlTenantKey = isDevelopment
|
|
20
|
+
? Cookies.get('campx_tenant')
|
|
21
|
+
: window.location.hostname.split('.')[0]
|
|
22
|
+
export const instituitionKey =
|
|
23
|
+
Cookies.get('campx_institution') ?? window.location.pathname.split('/')[1]
|
|
17
24
|
|
|
18
25
|
export default function Providers({ children }: { children: ReactNode }) {
|
|
26
|
+
var baseName = '/'
|
|
27
|
+
var tenantCode
|
|
28
|
+
var institutionCode =
|
|
29
|
+
Cookies.get('campx_institution') ?? window.location.pathname.split('/')[1]
|
|
30
|
+
|
|
31
|
+
if (isDevelopment) {
|
|
32
|
+
tenantCode = Cookies.get('campx_tenant')
|
|
33
|
+
if (
|
|
34
|
+
tenantCode &&
|
|
35
|
+
institutionCode &&
|
|
36
|
+
window.location.pathname !== '/auth/login'
|
|
37
|
+
) {
|
|
38
|
+
baseName = `/${institutionCode}`
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
tenantCode = window.location.hostname.split('.')[0]
|
|
42
|
+
if (institutionCode && window.location.pathname !== '/auth/login') {
|
|
43
|
+
baseName = `/${institutionCode}`
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (location.pathname === '/' && institutionCode && tenantCode) {
|
|
49
|
+
window.location.replace(window.location.origin + `/${institutionCode}`)
|
|
50
|
+
}
|
|
51
|
+
}, [])
|
|
19
52
|
return (
|
|
20
|
-
<BrowserRouter>
|
|
53
|
+
<BrowserRouter basename={baseName}>
|
|
21
54
|
<QueryClientProvider>
|
|
22
55
|
<MuiThemeProvider>
|
|
23
56
|
<ConfirmContextProvider>
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Cookies from 'js-cookie'
|
|
2
1
|
import { useEffect, useState } from 'react'
|
|
3
2
|
import { useNavigate } from 'react-router-dom'
|
|
4
3
|
import { toast } from 'react-toastify'
|
|
@@ -98,18 +97,18 @@ const useAuth = ({
|
|
|
98
97
|
permissionsEndpoint,
|
|
99
98
|
loginUrl,
|
|
100
99
|
}: AuthParams): AuthResponse => {
|
|
101
|
-
const [loading, setLoading] = useState<boolean>(
|
|
100
|
+
const [loading, setLoading] = useState<boolean>(true)
|
|
102
101
|
const [data, setData] = useState<any>(null)
|
|
103
102
|
const { current } = InstitutionsStore.useState()
|
|
104
103
|
const navigate = useNavigate()
|
|
105
104
|
|
|
106
105
|
const appInit = async () => {
|
|
107
|
-
setLoading(true)
|
|
108
106
|
try {
|
|
109
107
|
const res = await axios.get(permissionsEndpoint)
|
|
110
108
|
const isAdmin = checkIsAdmin(res.data.user)
|
|
111
|
-
|
|
109
|
+
setLoading(false)
|
|
112
110
|
setData(res.data)
|
|
111
|
+
|
|
113
112
|
UserStore.update((s) => {
|
|
114
113
|
s.username = res.data?.user?.username
|
|
115
114
|
s.user = res.data?.user
|
|
@@ -143,17 +142,13 @@ const useAuth = ({
|
|
|
143
142
|
|
|
144
143
|
InstitutionsStore.update((s) => {
|
|
145
144
|
s.institutions = res.data?.institutions
|
|
146
|
-
s.current = res.data?.institutions
|
|
147
|
-
(item) => item.code === Cookies.get('campx_institution'),
|
|
148
|
-
)
|
|
145
|
+
s.current = res.data?.institutions[0]
|
|
149
146
|
})
|
|
150
147
|
|
|
151
148
|
AssetsStore.update((s) => {
|
|
152
149
|
s.logo = res.data?.assets.logo
|
|
153
150
|
s.logo_square = res.data?.assets.logo_square
|
|
154
151
|
})
|
|
155
|
-
|
|
156
|
-
setLoading(false)
|
|
157
152
|
} catch (err: any) {
|
|
158
153
|
setLoading(false)
|
|
159
154
|
const origin = window.location.origin
|
|
@@ -176,10 +171,11 @@ const useAuth = ({
|
|
|
176
171
|
}
|
|
177
172
|
}
|
|
178
173
|
}
|
|
179
|
-
|
|
174
|
+
console.log(loading, !data?.permissions, !current, 'abc1')
|
|
180
175
|
useEffect(() => {
|
|
181
176
|
appInit()
|
|
182
177
|
}, [])
|
|
178
|
+
console.log(loading, !data?.permissions, !current, 'abc2')
|
|
183
179
|
|
|
184
180
|
return {
|
|
185
181
|
loading: loading || !data?.permissions || !current,
|
|
@@ -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',
|