@campxdev/shared 1.8.0 → 1.8.2
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/ExcelToJsonInput/ExcelJsonUpload.tsx +2 -2
- package/src/components/LoginForm.tsx +137 -34
- package/src/constants/isDevelopment.ts +2 -1
- package/src/contexts/LoginFormProvider.tsx +7 -2
- package/src/contexts/Providers.tsx +8 -2
- package/src/shared-state/PermissionsStore.ts +4 -0
- package/src/utils/adminAxios.ts +15 -0
- package/src/utils/logout.ts +5 -8
package/package.json
CHANGED
|
@@ -18,8 +18,16 @@ import { FormTextField } from './HookForm'
|
|
|
18
18
|
import axios from '../config/axios'
|
|
19
19
|
import ResetPassword from './ResetPassword'
|
|
20
20
|
import { Link } from 'react-router-dom'
|
|
21
|
+
import { DialogButton } from './ModalButtons'
|
|
22
|
+
import adminAxios from '../utils/adminAxios'
|
|
21
23
|
|
|
22
|
-
export function LoginForm({
|
|
24
|
+
export function LoginForm({
|
|
25
|
+
loginUrl,
|
|
26
|
+
showSuperAdminForm,
|
|
27
|
+
}: {
|
|
28
|
+
loginUrl?: string
|
|
29
|
+
showSuperAdminForm?: boolean
|
|
30
|
+
}) {
|
|
23
31
|
const [showPassword, setShowPassword] = useState(false)
|
|
24
32
|
const [forgotMail, setForgotMail] = useState(null)
|
|
25
33
|
const [forgotPassword, setForgotPassword] = useState(true)
|
|
@@ -72,7 +80,7 @@ export function LoginForm({ loginUrl }: { loginUrl?: string }) {
|
|
|
72
80
|
}, [])
|
|
73
81
|
|
|
74
82
|
return (
|
|
75
|
-
|
|
83
|
+
<Box sx={{ position: 'relative', height: '100%' }}>
|
|
76
84
|
{resetPassword ? (
|
|
77
85
|
<>
|
|
78
86
|
<ResetPassword />
|
|
@@ -80,37 +88,33 @@ export function LoginForm({ loginUrl }: { loginUrl?: string }) {
|
|
|
80
88
|
) : forgotPassword ? (
|
|
81
89
|
<form onSubmit={handleSubmit(onSubmit)}>
|
|
82
90
|
<Stack gap={'30px'} sx={{ display: resetPassword ? 'none' : 'flex' }}>
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
),
|
|
111
|
-
}}
|
|
112
|
-
/>
|
|
113
|
-
</Box>
|
|
91
|
+
<FormTextField
|
|
92
|
+
control={control}
|
|
93
|
+
name="username"
|
|
94
|
+
label="User ID"
|
|
95
|
+
required
|
|
96
|
+
/>
|
|
97
|
+
<FormTextField
|
|
98
|
+
control={control}
|
|
99
|
+
name="password"
|
|
100
|
+
label="Password"
|
|
101
|
+
type={showPassword ? 'text' : 'password'}
|
|
102
|
+
required
|
|
103
|
+
InputProps={{
|
|
104
|
+
endAdornment: (
|
|
105
|
+
<InputAdornment position="end">
|
|
106
|
+
<IconButton
|
|
107
|
+
size="small"
|
|
108
|
+
aria-label="toggle password visibility"
|
|
109
|
+
onClick={() => setShowPassword((prev) => !prev)}
|
|
110
|
+
edge="end"
|
|
111
|
+
>
|
|
112
|
+
{showPassword ? <VisibilityOff /> : <Visibility />}
|
|
113
|
+
</IconButton>
|
|
114
|
+
</InputAdornment>
|
|
115
|
+
),
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
114
118
|
<ActionButton type="submit">Login</ActionButton>
|
|
115
119
|
<Typography
|
|
116
120
|
variant="h6"
|
|
@@ -159,7 +163,27 @@ export function LoginForm({ loginUrl }: { loginUrl?: string }) {
|
|
|
159
163
|
{error}
|
|
160
164
|
</Alert>
|
|
161
165
|
)}
|
|
162
|
-
|
|
166
|
+
|
|
167
|
+
{showSuperAdminForm && (
|
|
168
|
+
<Box
|
|
169
|
+
sx={{
|
|
170
|
+
position: 'absolute',
|
|
171
|
+
bottom: '20px',
|
|
172
|
+
right: '20px',
|
|
173
|
+
}}
|
|
174
|
+
>
|
|
175
|
+
<DialogButton
|
|
176
|
+
title="Super Admin Login"
|
|
177
|
+
anchor={({ open }) => (
|
|
178
|
+
<Button onClick={open} size="small" variant="text">
|
|
179
|
+
Super Admin Login
|
|
180
|
+
</Button>
|
|
181
|
+
)}
|
|
182
|
+
content={({ close }) => <SuperAdminLoginForm close={close} />}
|
|
183
|
+
/>
|
|
184
|
+
</Box>
|
|
185
|
+
)}
|
|
186
|
+
</Box>
|
|
163
187
|
)
|
|
164
188
|
}
|
|
165
189
|
|
|
@@ -169,3 +193,82 @@ export const StyledLink = styled(Link)({
|
|
|
169
193
|
})
|
|
170
194
|
|
|
171
195
|
export default LoginForm
|
|
196
|
+
|
|
197
|
+
const SuperAdminLoginForm = ({ close }) => {
|
|
198
|
+
const [showPassword, setShowPassword] = useState(false)
|
|
199
|
+
const [loading, setLoading] = useState(false)
|
|
200
|
+
const { handleSubmit, control } = useForm({
|
|
201
|
+
defaultValues: null,
|
|
202
|
+
})
|
|
203
|
+
const [error, setError] = useState('')
|
|
204
|
+
|
|
205
|
+
const onSubmit = async (values) => {
|
|
206
|
+
setLoading(true)
|
|
207
|
+
try {
|
|
208
|
+
const res = await adminAxios.post(`/auth/login`, values)
|
|
209
|
+
Cookies.set('campx_admin_session_key', res?.data?.cookie)
|
|
210
|
+
|
|
211
|
+
setLoading(false)
|
|
212
|
+
window.location.href = '/campx'
|
|
213
|
+
} catch (err) {
|
|
214
|
+
setLoading(false)
|
|
215
|
+
setError(err.response.data.message ?? 'Server Error')
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const onError = (e) => {
|
|
220
|
+
console.log(e)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return (
|
|
224
|
+
<Box width={'100%'} marginTop="20px">
|
|
225
|
+
<form onSubmit={handleSubmit(onSubmit, onError)}>
|
|
226
|
+
<Stack gap={'40px'}>
|
|
227
|
+
<Typography variant="h6" textAlign={'center'}>
|
|
228
|
+
Sign in to Super Admin Account
|
|
229
|
+
</Typography>
|
|
230
|
+
<FormTextField
|
|
231
|
+
control={control}
|
|
232
|
+
name="username"
|
|
233
|
+
label="Username/Email"
|
|
234
|
+
required
|
|
235
|
+
/>
|
|
236
|
+
<FormTextField
|
|
237
|
+
control={control}
|
|
238
|
+
name="password"
|
|
239
|
+
label="Password"
|
|
240
|
+
type={showPassword ? 'text' : 'password'}
|
|
241
|
+
required
|
|
242
|
+
InputProps={{
|
|
243
|
+
endAdornment: (
|
|
244
|
+
<InputAdornment position="end">
|
|
245
|
+
<IconButton
|
|
246
|
+
size="small"
|
|
247
|
+
aria-label="toggle password visibility"
|
|
248
|
+
onClick={() => setShowPassword((prev) => !prev)}
|
|
249
|
+
edge="end"
|
|
250
|
+
>
|
|
251
|
+
{showPassword ? <VisibilityOff /> : <Visibility />}
|
|
252
|
+
</IconButton>
|
|
253
|
+
</InputAdornment>
|
|
254
|
+
),
|
|
255
|
+
}}
|
|
256
|
+
/>
|
|
257
|
+
<ActionButton
|
|
258
|
+
type="submit"
|
|
259
|
+
fullWidth
|
|
260
|
+
disabled={loading}
|
|
261
|
+
loading={loading}
|
|
262
|
+
>
|
|
263
|
+
Login
|
|
264
|
+
</ActionButton>
|
|
265
|
+
</Stack>
|
|
266
|
+
</form>
|
|
267
|
+
{error && (
|
|
268
|
+
<Alert severity="error" sx={{ marginTop: '20px' }}>
|
|
269
|
+
{error}
|
|
270
|
+
</Alert>
|
|
271
|
+
)}
|
|
272
|
+
</Box>
|
|
273
|
+
)
|
|
274
|
+
}
|
|
@@ -8,14 +8,19 @@ const LoginContext = createContext<{
|
|
|
8
8
|
openLoginForm: (loginUrl: string) => {},
|
|
9
9
|
})
|
|
10
10
|
|
|
11
|
-
export default function LoginFormProvider({ children }) {
|
|
11
|
+
export default function LoginFormProvider({ children, showSuperAdminForm }) {
|
|
12
12
|
const modal = useModal()
|
|
13
13
|
|
|
14
14
|
const onLogin = (loginUrl: string) => {
|
|
15
15
|
modal({
|
|
16
16
|
title: 'Developer Login',
|
|
17
17
|
content({ close }) {
|
|
18
|
-
return
|
|
18
|
+
return (
|
|
19
|
+
<LoginForm
|
|
20
|
+
loginUrl={loginUrl}
|
|
21
|
+
showSuperAdminForm={showSuperAdminForm}
|
|
22
|
+
/>
|
|
23
|
+
)
|
|
19
24
|
},
|
|
20
25
|
})
|
|
21
26
|
}
|
|
@@ -13,7 +13,13 @@ import LoginFormProvider from './LoginFormProvider'
|
|
|
13
13
|
export const campxTenantKey = Cookies.get('campx_tenant')
|
|
14
14
|
export const urlTenantKey = window.location.pathname.split('/')[1]
|
|
15
15
|
|
|
16
|
-
export default function Providers({
|
|
16
|
+
export default function Providers({
|
|
17
|
+
children,
|
|
18
|
+
showSuperAdminLoginForm = false,
|
|
19
|
+
}: {
|
|
20
|
+
children: ReactNode
|
|
21
|
+
showSuperAdminLoginForm?: boolean
|
|
22
|
+
}) {
|
|
17
23
|
useEffect(() => {
|
|
18
24
|
if (!urlTenantKey) {
|
|
19
25
|
if (campxTenantKey) {
|
|
@@ -30,7 +36,7 @@ export default function Providers({ children }: { children: ReactNode }) {
|
|
|
30
36
|
<MuiThemeProvider>
|
|
31
37
|
<ConfirmContextProvider>
|
|
32
38
|
<DialogProvider>
|
|
33
|
-
<LoginFormProvider>
|
|
39
|
+
<LoginFormProvider showSuperAdminForm={showSuperAdminLoginForm}>
|
|
34
40
|
{children}
|
|
35
41
|
<GlobalNetworkLoadingIndicator />
|
|
36
42
|
</LoginFormProvider>
|
|
@@ -21,6 +21,8 @@ export enum Permission {
|
|
|
21
21
|
CLASSROOM_EDIT = 'can_classroom_edit',
|
|
22
22
|
CLASSROOM_DELETE = 'can_classroom_delete',
|
|
23
23
|
CLASSROOM_ADD = 'can_classroom_add',
|
|
24
|
+
CAN_CLASSROOM_SUBJECTS_VIEW = 'can_classroom_subjects_view',
|
|
25
|
+
CAN_CLASSROOM_SUBJECT_ATTENDANCE_EDIT = 'can_classroom_subject_attendance_edit',
|
|
24
26
|
|
|
25
27
|
// Tasks
|
|
26
28
|
|
|
@@ -341,6 +343,8 @@ export interface IPermissions {
|
|
|
341
343
|
can_tasks_edit: boolean
|
|
342
344
|
can_tasks_change_status: boolean
|
|
343
345
|
can_tasks_delete: boolean
|
|
346
|
+
can_classroom_subject_attendance_edit: boolean
|
|
347
|
+
can_classroom_subjects_view: boolean
|
|
344
348
|
}
|
|
345
349
|
|
|
346
350
|
interface IPermissionsStore {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Axios from 'axios'
|
|
2
|
+
import Cookies from 'js-cookie'
|
|
3
|
+
|
|
4
|
+
const sessionKey = Cookies.get('campx_admin_session_key')
|
|
5
|
+
let adminAxios = Axios.create({
|
|
6
|
+
baseURL: process.env.REACT_APP_TENANT_API_HOST,
|
|
7
|
+
withCredentials: true,
|
|
8
|
+
headers: {
|
|
9
|
+
...(sessionKey && {
|
|
10
|
+
campx_admin_session_key: sessionKey,
|
|
11
|
+
}),
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export default adminAxios
|
package/src/utils/logout.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import Cookies from 'js-cookie'
|
|
2
2
|
import axios, { axiosErrorToast } from '../config/axios'
|
|
3
3
|
|
|
4
|
-
const urlTenantKey = window.location.pathname.split('/')[1]
|
|
5
|
-
|
|
6
4
|
export default function logout() {
|
|
7
5
|
axios({
|
|
8
6
|
method: 'POST',
|
|
@@ -10,14 +8,13 @@ export default function logout() {
|
|
|
10
8
|
url: '/auth-server/auth/logout',
|
|
11
9
|
})
|
|
12
10
|
.then((res) => {
|
|
13
|
-
if (
|
|
11
|
+
if (
|
|
12
|
+
process.env.NODE_ENV === 'development' ||
|
|
13
|
+
window.location.origin.split('campx')[1] === '.dev'
|
|
14
|
+
) {
|
|
14
15
|
Cookies.remove('campx_tenant')
|
|
15
16
|
Cookies.remove('campx_session_key')
|
|
16
|
-
|
|
17
|
-
window.location.href = window.location.origin + 'campx_dev'
|
|
18
|
-
} else {
|
|
19
|
-
window.location.href = window.location.origin + `/${urlTenantKey}`
|
|
20
|
-
}
|
|
17
|
+
window.location.href = window.location.origin
|
|
21
18
|
} else {
|
|
22
19
|
window.location.href = 'https://id.campx.in'
|
|
23
20
|
}
|