@campxdev/shared 2.0.0 → 2.0.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.
- package/package.json +1 -1
- package/src/components/ErrorBoundary/ErrorFallback.tsx +8 -33
- package/src/components/LoginForm.tsx +9 -6
- package/src/config/axios.ts +15 -9
- package/src/hooks/useAuth.ts +1 -2
- package/yarn-error.log +15782 -0
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Alert, Box, Button, styled, Typography } from '@mui/material'
|
|
2
2
|
import Cookies from 'js-cookie'
|
|
3
|
-
import {
|
|
3
|
+
import { useState } from 'react'
|
|
4
|
+
import { useNavigate } from 'react-router-dom'
|
|
4
5
|
import {
|
|
5
6
|
internalserver,
|
|
6
7
|
nointernet,
|
|
@@ -11,7 +12,6 @@ import {
|
|
|
11
12
|
import axios from '../../config/axios'
|
|
12
13
|
import { openRootModal } from '../../contexts/RootModal'
|
|
13
14
|
import { PermissionsStore } from '../../shared-state'
|
|
14
|
-
import { useModal } from '../DrawerWrapper/DrawerWrapper'
|
|
15
15
|
|
|
16
16
|
const StyledAlert = styled(Alert)(({ theme }) => ({
|
|
17
17
|
height: '60px',
|
|
@@ -26,13 +26,12 @@ const StyledAlert = styled(Alert)(({ theme }) => ({
|
|
|
26
26
|
},
|
|
27
27
|
position: 'relative',
|
|
28
28
|
'& .retryBtn': {
|
|
29
|
-
color: '#
|
|
29
|
+
color: '#661B2A',
|
|
30
30
|
position: 'absolute',
|
|
31
31
|
right: 8,
|
|
32
32
|
top: 8,
|
|
33
33
|
},
|
|
34
34
|
}))
|
|
35
|
-
|
|
36
35
|
const StyledBox = styled(Box)(({ theme }) => ({
|
|
37
36
|
width: '100%',
|
|
38
37
|
display: 'flex',
|
|
@@ -40,32 +39,26 @@ const StyledBox = styled(Box)(({ theme }) => ({
|
|
|
40
39
|
alignItems: 'center',
|
|
41
40
|
justifyContent: 'center',
|
|
42
41
|
}))
|
|
43
|
-
|
|
44
42
|
export default function ErrorFallback({ error, resetErrorBoundary }) {
|
|
45
43
|
if (error?.response?.status) {
|
|
46
44
|
switch (error?.response?.status) {
|
|
47
45
|
case 401:
|
|
48
46
|
return <UnAuth resetBoundary={resetErrorBoundary} />
|
|
49
|
-
|
|
50
47
|
case 500:
|
|
51
48
|
return (
|
|
52
49
|
<InternalServer resetBoundary={resetErrorBoundary} error={error} />
|
|
53
50
|
)
|
|
54
|
-
|
|
55
51
|
case 403:
|
|
56
52
|
return <PemissionDenied resetBoundary={resetErrorBoundary} />
|
|
57
|
-
|
|
58
53
|
default:
|
|
59
54
|
return (
|
|
60
55
|
<InternalServer resetBoundary={resetErrorBoundary} error={error} />
|
|
61
56
|
)
|
|
62
57
|
}
|
|
63
58
|
}
|
|
64
|
-
|
|
65
59
|
if (error?.message === 'Network Error') {
|
|
66
60
|
return <NoInternet resetBoundary={resetErrorBoundary} />
|
|
67
61
|
}
|
|
68
|
-
|
|
69
62
|
return (
|
|
70
63
|
<Box sx={{ marginTop: '16px', padding: '20px' }}>
|
|
71
64
|
<StyledAlert severity="error">
|
|
@@ -83,7 +76,6 @@ export default function ErrorFallback({ error, resetErrorBoundary }) {
|
|
|
83
76
|
</Box>
|
|
84
77
|
)
|
|
85
78
|
}
|
|
86
|
-
|
|
87
79
|
export function PageNotFound({ resetBoundary }) {
|
|
88
80
|
return (
|
|
89
81
|
<>
|
|
@@ -102,7 +94,6 @@ export function PageNotFound({ resetBoundary }) {
|
|
|
102
94
|
</>
|
|
103
95
|
)
|
|
104
96
|
}
|
|
105
|
-
|
|
106
97
|
export function NoInternet({ resetBoundary }) {
|
|
107
98
|
return (
|
|
108
99
|
<>
|
|
@@ -116,7 +107,6 @@ export function NoInternet({ resetBoundary }) {
|
|
|
116
107
|
</>
|
|
117
108
|
)
|
|
118
109
|
}
|
|
119
|
-
|
|
120
110
|
export function PemissionDenied({ resetBoundary }) {
|
|
121
111
|
return (
|
|
122
112
|
<>
|
|
@@ -130,7 +120,6 @@ export function PemissionDenied({ resetBoundary }) {
|
|
|
130
120
|
</>
|
|
131
121
|
)
|
|
132
122
|
}
|
|
133
|
-
|
|
134
123
|
export function InternalServer({ resetBoundary, error }) {
|
|
135
124
|
return (
|
|
136
125
|
<>
|
|
@@ -158,20 +147,18 @@ export function InternalServer({ resetBoundary, error }) {
|
|
|
158
147
|
</>
|
|
159
148
|
)
|
|
160
149
|
}
|
|
161
|
-
|
|
162
150
|
export function UnAuth({ resetBoundary }) {
|
|
163
|
-
const
|
|
151
|
+
const navigate = useNavigate()
|
|
164
152
|
const [username, setUsername] = useState('')
|
|
165
153
|
const [loading, setLoading] = useState(false)
|
|
166
|
-
|
|
167
154
|
const url = window.location.origin
|
|
168
155
|
const origin = window?.location?.origin?.split('.')
|
|
169
156
|
const isDevelopment =
|
|
170
157
|
process.env.NODE_ENV === 'development' ||
|
|
171
158
|
origin?.slice(-2).join('.') === 'campx.dev'
|
|
159
|
+
console.log(isDevelopment, 'hii')
|
|
172
160
|
const isSetup = window.location.hostname.split('.').includes('setup')
|
|
173
161
|
const sessionCookie = Cookies.get('campx_session_key')
|
|
174
|
-
|
|
175
162
|
const appinit = async () => {
|
|
176
163
|
setLoading(true)
|
|
177
164
|
await axios
|
|
@@ -194,7 +181,7 @@ export function UnAuth({ resetBoundary }) {
|
|
|
194
181
|
})
|
|
195
182
|
})
|
|
196
183
|
}
|
|
197
|
-
function
|
|
184
|
+
function handleLoginClick() {
|
|
198
185
|
if (isDevelopment) {
|
|
199
186
|
if (!sessionCookie) {
|
|
200
187
|
openRootModal({
|
|
@@ -204,20 +191,9 @@ export function UnAuth({ resetBoundary }) {
|
|
|
204
191
|
appinit()
|
|
205
192
|
}
|
|
206
193
|
} else {
|
|
207
|
-
|
|
208
|
-
window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
|
|
209
|
-
} else {
|
|
210
|
-
appinit()
|
|
211
|
-
}
|
|
194
|
+
navigate('/auth/login')
|
|
212
195
|
}
|
|
213
196
|
}
|
|
214
|
-
|
|
215
|
-
useEffect(() => {
|
|
216
|
-
if (!isDevelopment && !isSetup) {
|
|
217
|
-
window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
|
|
218
|
-
}
|
|
219
|
-
}, [isDevelopment])
|
|
220
|
-
|
|
221
197
|
return (
|
|
222
198
|
<>
|
|
223
199
|
<StyledBox>
|
|
@@ -238,8 +214,7 @@ export function UnAuth({ resetBoundary }) {
|
|
|
238
214
|
>
|
|
239
215
|
Try Again
|
|
240
216
|
</Button>
|
|
241
|
-
|
|
242
|
-
<Button onClick={() => LoginPage()}>Click here to Login</Button>
|
|
217
|
+
<Button onClick={handleLoginClick}>Click here to Login</Button>
|
|
243
218
|
</Box>
|
|
244
219
|
</StyledBox>
|
|
245
220
|
</>
|
|
@@ -23,6 +23,7 @@ import ActionButton from './ActionButton'
|
|
|
23
23
|
import { FormTextField } from './HookForm'
|
|
24
24
|
import Image from './Image/Image'
|
|
25
25
|
import ResetPassword from './ResetPassword'
|
|
26
|
+
const isDevelopment = process.env.NODE_ENV == 'development'
|
|
26
27
|
|
|
27
28
|
export function LoginForm({
|
|
28
29
|
loginUrl,
|
|
@@ -61,12 +62,14 @@ export function LoginForm({
|
|
|
61
62
|
...deviceState.deviceInformation,
|
|
62
63
|
},
|
|
63
64
|
})
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
if (isDevelopment) {
|
|
66
|
+
Cookies.remove('campx_session_key')
|
|
67
|
+
Cookies.remove('campx_tenant')
|
|
68
|
+
Cookies.remove('campx_institution')
|
|
69
|
+
Cookies.set('campx_session_key', res.data?.token)
|
|
70
|
+
Cookies.set('campx_tenant', res.data?.subDomain)
|
|
71
|
+
Cookies.set('campx_institution', res.data?.institutionCode)
|
|
72
|
+
}
|
|
70
73
|
window.location.href = `/${res.data.institutionCode}`
|
|
71
74
|
//window.location.reload()
|
|
72
75
|
} catch (err) {
|
package/src/config/axios.ts
CHANGED
|
@@ -5,15 +5,11 @@ import { NetworkStore } from '../components/ErrorBoundary/GlobalNetworkLoadingIn
|
|
|
5
5
|
|
|
6
6
|
const isDevelopment = process.env.NODE_ENV == 'development'
|
|
7
7
|
|
|
8
|
-
const sessionKey = Cookies.get('campx_session_key')
|
|
9
8
|
const tenantCode = isDevelopment
|
|
10
9
|
? Cookies.get('campx_tenant')
|
|
11
10
|
: window.location.hostname.split('.')[0]
|
|
12
11
|
const institutionCode = window.location.pathname.split('/')[1]
|
|
13
12
|
|
|
14
|
-
const openPaymentsKey = Cookies.get('campx_open_payments_key')
|
|
15
|
-
console.log(openPaymentsKey)
|
|
16
|
-
|
|
17
13
|
export const formatParams = (params) => {
|
|
18
14
|
return Object.fromEntries(
|
|
19
15
|
Object.entries(params ?? {})?.map((i) => [
|
|
@@ -29,10 +25,6 @@ let axios = Axios.create({
|
|
|
29
25
|
headers: {
|
|
30
26
|
'x-tenant-id': tenantCode,
|
|
31
27
|
'x-institution-code': institutionCode,
|
|
32
|
-
campx_session_key: sessionKey,
|
|
33
|
-
...(openPaymentsKey && {
|
|
34
|
-
campx_open_payments_key: openPaymentsKey,
|
|
35
|
-
}),
|
|
36
28
|
},
|
|
37
29
|
})
|
|
38
30
|
|
|
@@ -42,7 +34,21 @@ axios.interceptors.request.use(
|
|
|
42
34
|
NetworkStore.update((s) => {
|
|
43
35
|
s.loading = true
|
|
44
36
|
})
|
|
45
|
-
|
|
37
|
+
const sessionKey = Cookies.get('campx_session_key')
|
|
38
|
+
const openPaymentsKey = Cookies.get('campx_open_payments_key')
|
|
39
|
+
|
|
40
|
+
if (isDevelopment && sessionKey) {
|
|
41
|
+
config.headers.set('campx_session_key', sessionKey)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (openPaymentsKey) {
|
|
45
|
+
config.headers.set('campx_open_payments_key', openPaymentsKey)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
...config,
|
|
50
|
+
params,
|
|
51
|
+
}
|
|
46
52
|
},
|
|
47
53
|
function (error) {
|
|
48
54
|
NetworkStore.update((s) => {
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -171,11 +171,10 @@ const useAuth = ({
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
|
|
175
175
|
useEffect(() => {
|
|
176
176
|
appInit()
|
|
177
177
|
}, [])
|
|
178
|
-
console.log(loading, !data?.permissions, !current, 'abc2')
|
|
179
178
|
|
|
180
179
|
return {
|
|
181
180
|
loading: loading || !data?.permissions || !current,
|