@campxdev/shared 0.3.8 → 0.3.9
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 +103 -0
- package/src/components/index.ts +2 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/logout.ts +20 -24
package/package.json
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {Visibility, VisibilityOff} from '@mui/icons-material'
|
|
2
|
+
import {
|
|
3
|
+
Alert,
|
|
4
|
+
Box,
|
|
5
|
+
Button,
|
|
6
|
+
IconButton,
|
|
7
|
+
InputAdornment,
|
|
8
|
+
Stack,
|
|
9
|
+
styled,
|
|
10
|
+
} from '@mui/material'
|
|
11
|
+
import axiosBase from 'axios'
|
|
12
|
+
import Cookies from 'js-cookie'
|
|
13
|
+
import {useState} from 'react'
|
|
14
|
+
import {useForm} from 'react-hook-form'
|
|
15
|
+
import {FormTextField} from './HookForm'
|
|
16
|
+
|
|
17
|
+
export const StyledTextField = styled(FormTextField)(({theme}) => ({
|
|
18
|
+
'& .MuiInputBase-root': {
|
|
19
|
+
minHeight: '60px',
|
|
20
|
+
},
|
|
21
|
+
'& .MuiOutlinedInput-input': {
|
|
22
|
+
padding: '18.5px 14px',
|
|
23
|
+
},
|
|
24
|
+
}))
|
|
25
|
+
|
|
26
|
+
export const StyledButton = styled(Button)(({theme}) => ({
|
|
27
|
+
borderRadius: '10px',
|
|
28
|
+
height: '60px',
|
|
29
|
+
fontSize: '18px',
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
export function LoginForm() {
|
|
33
|
+
const [showPassword, setShowPassword] = useState(false)
|
|
34
|
+
const {handleSubmit, control} = useForm()
|
|
35
|
+
const [error, setError] = useState('')
|
|
36
|
+
|
|
37
|
+
const onSubmit = async (values) => {
|
|
38
|
+
try {
|
|
39
|
+
const res = await axiosBase({
|
|
40
|
+
method: 'POST',
|
|
41
|
+
url: 'https://ums-api.campx.dev/auth/login',
|
|
42
|
+
data: {
|
|
43
|
+
values,
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
Cookies.set('campx_session_key', res.data.cookie)
|
|
47
|
+
window.location.href = '/'
|
|
48
|
+
} catch (err) {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.log(err)
|
|
51
|
+
setError(err.response.data.message ?? 'Server Error')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Box sx={{maxWidth: '500px'}} margin='0 auto' padding={'0 1rem'}>
|
|
57
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
58
|
+
<Stack gap={'40px'}>
|
|
59
|
+
<Box>
|
|
60
|
+
<StyledTextField
|
|
61
|
+
size='medium'
|
|
62
|
+
control={control}
|
|
63
|
+
name='username'
|
|
64
|
+
label='User ID'
|
|
65
|
+
required
|
|
66
|
+
/>
|
|
67
|
+
</Box>
|
|
68
|
+
<Box>
|
|
69
|
+
<StyledTextField
|
|
70
|
+
control={control}
|
|
71
|
+
name='password'
|
|
72
|
+
label='Password'
|
|
73
|
+
type={showPassword ? 'text' : 'password'}
|
|
74
|
+
required
|
|
75
|
+
InputProps={{
|
|
76
|
+
endAdornment: (
|
|
77
|
+
<InputAdornment position='end'>
|
|
78
|
+
<IconButton
|
|
79
|
+
size='small'
|
|
80
|
+
aria-label='toggle password visibility'
|
|
81
|
+
onClick={() => setShowPassword((prev) => !prev)}
|
|
82
|
+
edge='end'
|
|
83
|
+
>
|
|
84
|
+
{showPassword ? <VisibilityOff /> : <Visibility />}
|
|
85
|
+
</IconButton>
|
|
86
|
+
</InputAdornment>
|
|
87
|
+
),
|
|
88
|
+
}}
|
|
89
|
+
/>
|
|
90
|
+
</Box>
|
|
91
|
+
<StyledButton type='submit'>Login</StyledButton>
|
|
92
|
+
</Stack>
|
|
93
|
+
</form>
|
|
94
|
+
{error && (
|
|
95
|
+
<Alert severity='error' sx={{marginTop: '20px'}}>
|
|
96
|
+
{error}
|
|
97
|
+
</Alert>
|
|
98
|
+
)}
|
|
99
|
+
</Box>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default LoginForm
|
package/src/components/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import UploadDocument from './UploadDocument'
|
|
|
14
14
|
import {Table as StyledTable} from './Table'
|
|
15
15
|
import ErrorBoundary from './ErrorBoundary'
|
|
16
16
|
import FullScreenLoader from './FullScreenLoader'
|
|
17
|
+
import LoginForm from './LoginForm'
|
|
17
18
|
|
|
18
19
|
export {default as Image} from './Image'
|
|
19
20
|
export {default as PageHeader} from './PageHeader'
|
|
@@ -57,6 +58,7 @@ export {
|
|
|
57
58
|
StyledTable,
|
|
58
59
|
ErrorBoundary,
|
|
59
60
|
FullScreenLoader,
|
|
61
|
+
LoginForm,
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
export * from './UploadButton/types'
|
package/src/utils/index.ts
CHANGED
|
@@ -5,3 +5,4 @@ export {default as romanize} from './romanize'
|
|
|
5
5
|
export {default as withRouteWrapper} from './withRouteWrapper'
|
|
6
6
|
export {default as withSuspense} from './withSuspense'
|
|
7
7
|
export {default as withLocalization} from './withLocalization'
|
|
8
|
+
export {default as onLogout} from './logout'
|
package/src/utils/logout.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import Cookies from
|
|
2
|
-
import axios, {
|
|
1
|
+
import Cookies from 'js-cookie'
|
|
2
|
+
import axios, {axiosErrorToast} from '../config/axios'
|
|
3
|
+
import {isDevelopment} from '../constants'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export default function logout() {
|
|
6
|
+
if (isDevelopment) {
|
|
7
|
+
Cookies.remove('campx_session_key')
|
|
8
|
+
window.location.href = '/'
|
|
9
|
+
return
|
|
10
|
+
}
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
.then((res) => {
|
|
22
|
-
window.location.href = "/";
|
|
23
|
-
})
|
|
24
|
-
.catch((err) => {
|
|
25
|
-
axiosErrorToast("Unable To Logout.");
|
|
26
|
-
});
|
|
12
|
+
axios({
|
|
13
|
+
method: 'POST',
|
|
14
|
+
baseURL: 'https://auth-api.campx.in',
|
|
15
|
+
url: '/auth/logout',
|
|
16
|
+
})
|
|
17
|
+
.then((res) => {
|
|
18
|
+
window.location.href = '/'
|
|
19
|
+
})
|
|
20
|
+
.catch((err) => {
|
|
21
|
+
axiosErrorToast('Unable To Logout.')
|
|
22
|
+
})
|
|
27
23
|
}
|