@campxdev/shared 1.11.72 → 2.0.0
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 +15 -15
- package/src/components/Image/Image.tsx +4 -1
- package/src/components/Institutions/InstitutionsDropdown.tsx +0 -2
- package/src/components/Layout/Header/AppHeader.tsx +24 -22
- package/src/components/Layout/Header/AppsMenu.tsx +1 -1
- package/src/components/Layout/Header/styles.tsx +6 -5
- package/src/components/Layout/LayoutWrapper.tsx +7 -54
- package/src/components/LoginForm.tsx +7 -2
- package/src/components/NoDataIllustration.tsx +11 -3
- package/src/config/axios.ts +13 -18
- package/src/constants/isDevelopment.ts +1 -5
- package/src/contexts/Providers.tsx +33 -34
- package/src/hooks/useAuth.ts +73 -151
- package/src/layouts/Components/styles.tsx +5 -36
- package/src/shared-state/index.ts +9 -2
- package/src/utils/logout.ts +4 -8
- package/styled-components.tsx +3 -3
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@campxdev/shared",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "./exports.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "react-scripts start",
|
|
7
7
|
"dev": "react-scripts start",
|
|
8
8
|
"build": "CI=false && react-scripts build",
|
|
9
|
-
"prepublish": "npm run build",
|
|
10
9
|
"test": "react-scripts test",
|
|
11
10
|
"eject": "react-scripts eject",
|
|
12
11
|
"lint": "eslint ./src/**/*.{js,jsx,ts,tsx,json}",
|
|
@@ -31,34 +30,33 @@
|
|
|
31
30
|
"@emotion/react": "^11.11.1",
|
|
32
31
|
"@emotion/styled": "^11.11.0",
|
|
33
32
|
"@hookform/resolvers": "^2.9.10",
|
|
34
|
-
"@
|
|
33
|
+
"@mongodb-js/charts-embed-dom": "3.2.1",
|
|
34
|
+
"@mui/icons-material": "^5.15.20",
|
|
35
35
|
"@mui/lab": "^5.0.0-alpha.146",
|
|
36
|
-
"@mui/material": "^5.15.
|
|
36
|
+
"@mui/material": "^5.15.20",
|
|
37
37
|
"@mui/x-date-pickers": "^6.16.0",
|
|
38
|
-
"axios": "^
|
|
38
|
+
"axios": "^1.7.2",
|
|
39
39
|
"date-fns": "^2.28.0",
|
|
40
40
|
"date-fns-tz": "^2.0.0",
|
|
41
41
|
"device-detector-js": "^3.0.3",
|
|
42
42
|
"fuse.js": "^6.6.2",
|
|
43
|
-
"js-cookie": "^3.0.
|
|
43
|
+
"js-cookie": "^3.0.5",
|
|
44
44
|
"moment": "^2.29.4",
|
|
45
45
|
"pullstate": "^1.24.0",
|
|
46
|
-
"react": "^18.
|
|
46
|
+
"react": "^18.3.1",
|
|
47
47
|
"react-arrows": "^1.2.0",
|
|
48
|
-
"react-dom": "^18.
|
|
48
|
+
"react-dom": "^18.3.1",
|
|
49
49
|
"react-error-boundary": "^3.1.4",
|
|
50
50
|
"react-flatpickr": "^3.10.13",
|
|
51
51
|
"react-helmet": "^6.1.0",
|
|
52
52
|
"react-hook-form": "^7.40.0",
|
|
53
53
|
"react-joyride": "^2.5.5",
|
|
54
|
-
"react-query": "^3.39.
|
|
55
|
-
"react-router-dom": "^6.
|
|
54
|
+
"react-query": "^3.39.3",
|
|
55
|
+
"react-router-dom": "^6.23.1",
|
|
56
56
|
"react-table": "^7.8.0",
|
|
57
57
|
"react-toastify": "^9.0.1",
|
|
58
58
|
"styled-components": "^5.3.5",
|
|
59
|
-
"@mongodb-js/charts-embed-dom": "3.2.1",
|
|
60
59
|
"swiper": "^8.1.5",
|
|
61
|
-
"typescript": "^5.2.2",
|
|
62
60
|
"use-immer": "^0.8.1",
|
|
63
61
|
"yup": "^0.32.11"
|
|
64
62
|
},
|
|
@@ -73,9 +71,10 @@
|
|
|
73
71
|
"@storybook/preset-create-react-app": "^4.0.0",
|
|
74
72
|
"@storybook/react": "^6.5.14",
|
|
75
73
|
"@storybook/testing-library": "^0.0.13",
|
|
76
|
-
"@types/js-cookie": "^3.0.
|
|
74
|
+
"@types/js-cookie": "^3.0.6",
|
|
77
75
|
"@types/node": "^18.11.8",
|
|
78
|
-
"@types/react": "^18.
|
|
76
|
+
"@types/react": "^18.3.3",
|
|
77
|
+
"@types/react-dom": "^18.3.0",
|
|
79
78
|
"@types/react-flatpickr": "^3.8.8",
|
|
80
79
|
"@types/react-helmet": "^6.1.6",
|
|
81
80
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
@@ -89,7 +88,8 @@
|
|
|
89
88
|
"eslint-plugin-storybook": "^0.6.8",
|
|
90
89
|
"prettier": "^2.5.0",
|
|
91
90
|
"react-scripts": "^5.0.1",
|
|
92
|
-
"storybook-addon-react-router-v6": "^0.2.1"
|
|
91
|
+
"storybook-addon-react-router-v6": "^0.2.1",
|
|
92
|
+
"typescript": "^5.5.2"
|
|
93
93
|
},
|
|
94
94
|
"resolutions": {
|
|
95
95
|
"react-dev-utils/fork-ts-checker-webpack-plugin": "^6.5.3",
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Box } from '@mui/material'
|
|
2
|
+
import { ReactElement } from 'react'
|
|
2
3
|
const brokenImage = require('./broken-image.png')
|
|
3
4
|
|
|
4
5
|
interface ImageProps {
|
|
5
|
-
src: string
|
|
6
|
+
src: string | ReactElement
|
|
6
7
|
alt: string
|
|
7
8
|
height: string | number
|
|
8
9
|
width: string | number
|
|
9
10
|
fit?: 'cover' | 'contain' | 'fill'
|
|
10
11
|
radius?: string | number
|
|
11
12
|
defaultImage?: any
|
|
13
|
+
svg?: boolean
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export default function Image({
|
|
@@ -19,6 +21,7 @@ export default function Image({
|
|
|
19
21
|
fit = 'contain',
|
|
20
22
|
radius = '10px',
|
|
21
23
|
defaultImage = null,
|
|
24
|
+
svg = false,
|
|
22
25
|
}: ImageProps) {
|
|
23
26
|
return (
|
|
24
27
|
<Box
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Cookies from 'js-cookie'
|
|
2
1
|
import { urlTenantKey } from '../../contexts/Providers'
|
|
3
2
|
import { InstitutionsStore } from '../../shared-state/InstitutionsStore'
|
|
4
3
|
import { SearchSingleSelect } from '../Input/SearchSingleSelect'
|
|
@@ -9,7 +8,6 @@ export default function SchoolSwitch() {
|
|
|
9
8
|
const handleChange = (value) => {
|
|
10
9
|
if (value) {
|
|
11
10
|
localStorage.setItem('institution_key', value?.value)
|
|
12
|
-
Cookies.set('campx_institution', value?.value)
|
|
13
11
|
window.location.replace(
|
|
14
12
|
`${window.location.origin}/${urlTenantKey}/${value?.value}`,
|
|
15
13
|
)
|
|
@@ -66,26 +66,28 @@ export default function AppHeader({
|
|
|
66
66
|
imageSx = {},
|
|
67
67
|
}: AppHeaderProps) {
|
|
68
68
|
return (
|
|
69
|
-
|
|
70
|
-
<
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
customHeaderActions
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
69
|
+
<>
|
|
70
|
+
<StyledHeader sx={headerSx}>
|
|
71
|
+
<Box sx={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
|
|
72
|
+
{showMenu && <AppsMenu />}
|
|
73
|
+
<AppLogo clientLogo={clientLogo} imageSx={imageSx} />
|
|
74
|
+
</Box>
|
|
75
|
+
<Box className="actions">
|
|
76
|
+
{customHeaderActions ? (
|
|
77
|
+
customHeaderActions
|
|
78
|
+
) : (
|
|
79
|
+
<HeaderActions
|
|
80
|
+
cogWheelMenu={cogWheelMenu}
|
|
81
|
+
fullName={fullName}
|
|
82
|
+
userBoxActions={userBoxActions}
|
|
83
|
+
profileUrl={profileUrl}
|
|
84
|
+
actions={actions}
|
|
85
|
+
profileSx={profileSx}
|
|
86
|
+
/>
|
|
87
|
+
)}
|
|
88
|
+
</Box>
|
|
89
|
+
</StyledHeader>
|
|
90
|
+
</>
|
|
89
91
|
)
|
|
90
92
|
}
|
|
91
93
|
|
|
@@ -103,14 +105,14 @@ const AppLogo = ({ clientLogo, imageSx }) => {
|
|
|
103
105
|
</StyledImageWrapper>
|
|
104
106
|
<Box
|
|
105
107
|
sx={{
|
|
106
|
-
height: '
|
|
108
|
+
height: '36px',
|
|
107
109
|
width: '2px',
|
|
108
110
|
background: 'gray',
|
|
109
111
|
}}
|
|
110
112
|
></Box>
|
|
111
113
|
<StyledImageWrapper>
|
|
112
114
|
{isDevelopment ? (
|
|
113
|
-
<Typography variant="h1">Developer</Typography>
|
|
115
|
+
<Typography variant="h1">Developer </Typography>
|
|
114
116
|
) : (
|
|
115
117
|
<img
|
|
116
118
|
src={clientLogo}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
alpha,
|
|
3
2
|
AppBar,
|
|
3
|
+
Avatar,
|
|
4
4
|
Box,
|
|
5
5
|
IconButton,
|
|
6
|
+
Link,
|
|
6
7
|
ListItemText,
|
|
7
|
-
styled,
|
|
8
8
|
Typography,
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
alpha,
|
|
10
|
+
styled,
|
|
11
11
|
} from '@mui/material'
|
|
12
12
|
import { Link as RouterLink } from 'react-router-dom'
|
|
13
13
|
|
|
14
14
|
export const StyledImageWrapper = styled('div')`
|
|
15
15
|
width: auto;
|
|
16
|
-
height:
|
|
16
|
+
height: 34px;
|
|
17
17
|
& img {
|
|
18
18
|
width: 100%;
|
|
19
19
|
height: 100%;
|
|
@@ -36,6 +36,7 @@ export const StyledHeader = styled(Box)(({ theme }) => ({
|
|
|
36
36
|
backgroundColor: 'white',
|
|
37
37
|
display: 'flex',
|
|
38
38
|
alignItems: 'center',
|
|
39
|
+
height: '96px',
|
|
39
40
|
justifyContent: 'space-between',
|
|
40
41
|
'& .actions': {
|
|
41
42
|
marginRight: '20px',
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Drawer, IconButton, styled } from '@mui/material'
|
|
1
|
+
import { Drawer, Stack, styled } from '@mui/material'
|
|
3
2
|
import { useState } from 'react'
|
|
4
3
|
import {
|
|
5
4
|
StyledLeftNavContainer,
|
|
@@ -28,60 +27,14 @@ export default function LayoutWrapper({
|
|
|
28
27
|
setOpen(!open)
|
|
29
28
|
}
|
|
30
29
|
return (
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)}
|
|
37
|
-
|
|
38
|
-
<StyledMainContentContainer
|
|
39
|
-
style={{
|
|
40
|
-
width: permissions.isHomePageEnabled
|
|
41
|
-
? 'inherit'
|
|
42
|
-
: 'calc(100% - 220px)',
|
|
43
|
-
position: permissions.isHomePageEnabled ? 'unset' : 'fixed',
|
|
44
|
-
marginTop: permissions.isHomePageEnabled ? '10px' : '0px',
|
|
45
|
-
borderRadius: permissions.isHomePageEnabled ? '10px' : '0px',
|
|
46
|
-
border: permissions.isHomePageEnabled ? '1px solid #1212' : 'none',
|
|
47
|
-
height: permissions.isHomePageEnabled
|
|
48
|
-
? 'calc(100vh - 74px)'
|
|
49
|
-
: 'calc(100vh - 64px)',
|
|
50
|
-
}}
|
|
51
|
-
>
|
|
52
|
-
{window.innerWidth < 1024 && (
|
|
53
|
-
<>
|
|
54
|
-
<IconButton
|
|
55
|
-
color="inherit"
|
|
56
|
-
aria-label="open drawer"
|
|
57
|
-
onClick={handleDrawer}
|
|
58
|
-
edge="start"
|
|
59
|
-
sx={{ mr: 0.5 }}
|
|
60
|
-
>
|
|
61
|
-
<MenuIcon />
|
|
62
|
-
</IconButton>
|
|
63
|
-
{/* <Button
|
|
64
|
-
onClick={() => {
|
|
65
|
-
console.log('hi')
|
|
66
|
-
}}
|
|
67
|
-
// edge="start"
|
|
68
|
-
// sx={{ mr: 0.5 }}
|
|
69
|
-
>
|
|
70
|
-
<MenuIcon />
|
|
71
|
-
</Button> */}
|
|
72
|
-
<StyledDrawer
|
|
73
|
-
variant={'temporary'}
|
|
74
|
-
anchor="left"
|
|
75
|
-
open={open}
|
|
76
|
-
onClose={handleDrawer}
|
|
77
|
-
>
|
|
78
|
-
<SideNav menuItems={menu as any[]} header={sideMenuHeader} />
|
|
79
|
-
</StyledDrawer>
|
|
80
|
-
</>
|
|
81
|
-
)}
|
|
30
|
+
<Stack direction="row" width="100%" height="calc(100vh - 96px)">
|
|
31
|
+
<StyledLeftNavContainer>
|
|
32
|
+
<SideNav menuItems={menu as any[]} header={sideMenuHeader} />
|
|
33
|
+
</StyledLeftNavContainer>
|
|
34
|
+
<StyledMainContentContainer>
|
|
82
35
|
<ErrorBoundary>{children}</ErrorBoundary>
|
|
83
36
|
</StyledMainContentContainer>
|
|
84
|
-
</
|
|
37
|
+
</Stack>
|
|
85
38
|
)
|
|
86
39
|
}
|
|
87
40
|
|
|
@@ -61,9 +61,14 @@ export function LoginForm({
|
|
|
61
61
|
...deviceState.deviceInformation,
|
|
62
62
|
},
|
|
63
63
|
})
|
|
64
|
-
Cookies.
|
|
64
|
+
Cookies.remove('campx_session_key')
|
|
65
|
+
Cookies.remove('campx_tenant')
|
|
66
|
+
Cookies.remove('campx_institution')
|
|
65
67
|
Cookies.set('campx_session_key', res.data?.token)
|
|
66
|
-
|
|
68
|
+
Cookies.set('campx_tenant', res.data?.subDomain)
|
|
69
|
+
Cookies.set('campx_institution', res.data?.institutionCode)
|
|
70
|
+
window.location.href = `/${res.data.institutionCode}`
|
|
71
|
+
//window.location.reload()
|
|
67
72
|
} catch (err) {
|
|
68
73
|
// eslint-disable-next-line no-console
|
|
69
74
|
console.log(err)
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { Box, Typography, styled } from '@mui/material'
|
|
2
|
-
import { ReactNode } from 'react'
|
|
2
|
+
import { ReactElement, ReactNode } from 'react'
|
|
3
3
|
import Image from './Image'
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
imageSrc: string
|
|
6
|
+
imageSrc: string | ReactElement
|
|
7
7
|
height?: string
|
|
8
8
|
message?: string | ReactNode
|
|
9
|
+
svg?: boolean
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export default function NoData({
|
|
12
13
|
imageSrc,
|
|
13
14
|
height = '300px',
|
|
14
15
|
message = 'No Data Found',
|
|
16
|
+
svg = false,
|
|
15
17
|
}: Props) {
|
|
16
18
|
return (
|
|
17
19
|
<Box
|
|
@@ -19,7 +21,13 @@ export default function NoData({
|
|
|
19
21
|
marginTop: '20px',
|
|
20
22
|
}}
|
|
21
23
|
>
|
|
22
|
-
<Image
|
|
24
|
+
<Image
|
|
25
|
+
alt="No Data Found"
|
|
26
|
+
height={height}
|
|
27
|
+
width="auto"
|
|
28
|
+
src={imageSrc}
|
|
29
|
+
svg={svg}
|
|
30
|
+
/>
|
|
23
31
|
{typeof message === 'string' ? (
|
|
24
32
|
<StyledTypography variant="h6">{message}</StyledTypography>
|
|
25
33
|
) : (
|
package/src/config/axios.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import Axios, {
|
|
1
|
+
import Axios, { InternalAxiosRequestConfig } from 'axios'
|
|
2
2
|
import Cookies from 'js-cookie'
|
|
3
3
|
import { toast } from 'react-toastify'
|
|
4
4
|
import { NetworkStore } from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
const isDevelopment = process.env.NODE_ENV == 'development'
|
|
7
7
|
|
|
8
8
|
const sessionKey = Cookies.get('campx_session_key')
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const tenantCode = isDevelopment
|
|
10
|
+
? Cookies.get('campx_tenant')
|
|
11
|
+
: window.location.hostname.split('.')[0]
|
|
12
|
+
const institutionCode = window.location.pathname.split('/')[1]
|
|
13
|
+
|
|
11
14
|
const openPaymentsKey = Cookies.get('campx_open_payments_key')
|
|
15
|
+
console.log(openPaymentsKey)
|
|
12
16
|
|
|
13
17
|
export const formatParams = (params) => {
|
|
14
18
|
return Object.fromEntries(
|
|
@@ -23,11 +27,9 @@ let axios = Axios.create({
|
|
|
23
27
|
baseURL: process.env.REACT_APP_API_HOST,
|
|
24
28
|
withCredentials: true,
|
|
25
29
|
headers: {
|
|
26
|
-
'x-tenant-id':
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
: {}),
|
|
30
|
-
|
|
30
|
+
'x-tenant-id': tenantCode,
|
|
31
|
+
'x-institution-code': institutionCode,
|
|
32
|
+
campx_session_key: sessionKey,
|
|
31
33
|
...(openPaymentsKey && {
|
|
32
34
|
campx_open_payments_key: openPaymentsKey,
|
|
33
35
|
}),
|
|
@@ -35,14 +37,7 @@ let axios = Axios.create({
|
|
|
35
37
|
})
|
|
36
38
|
|
|
37
39
|
axios.interceptors.request.use(
|
|
38
|
-
function (config:
|
|
39
|
-
const { current } = InstitutionsStore.getRawState()
|
|
40
|
-
if (current) {
|
|
41
|
-
config.headers['x-institution-code'] = current.code
|
|
42
|
-
} else {
|
|
43
|
-
config.headers['x-institution-code'] = institutionId
|
|
44
|
-
}
|
|
45
|
-
|
|
40
|
+
function (config: InternalAxiosRequestConfig) {
|
|
46
41
|
const params = formatParams(config?.params)
|
|
47
42
|
NetworkStore.update((s) => {
|
|
48
43
|
s.loading = true
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
const
|
|
2
|
-
export const isDevelopment =
|
|
3
|
-
process.env.NODE_ENV === 'development' ||
|
|
4
|
-
window.location.origin.split('campx')[1] === '.dev'
|
|
5
|
-
|
|
1
|
+
export const isDevelopment = process.env.NODE_ENV === 'development'
|
|
6
2
|
export const isSetup = window.location.hostname.split('.').includes('setup')
|
|
@@ -9,51 +9,50 @@ 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
|
-
import { isDevelopment } from '../constants'
|
|
13
12
|
import RootModal from './RootModal'
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
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
|
+
window.location.pathname.split('/')[1] != ''
|
|
24
|
+
? window.location.pathname.split('/')[1]
|
|
25
|
+
: Cookies.get('campx_institution')
|
|
18
26
|
|
|
19
27
|
export default function Providers({ children }: { children: ReactNode }) {
|
|
20
|
-
|
|
28
|
+
var baseName = '/'
|
|
29
|
+
var tenantCode
|
|
30
|
+
var institutionCode =
|
|
31
|
+
window.location.pathname.split('/')[1] != ''
|
|
32
|
+
? window.location.pathname.split('/')[1]
|
|
33
|
+
: Cookies.get('campx_institution')
|
|
21
34
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
if (isDevelopment) {
|
|
36
|
+
tenantCode = Cookies.get('campx_tenant')
|
|
37
|
+
if (
|
|
38
|
+
tenantCode &&
|
|
39
|
+
institutionCode &&
|
|
40
|
+
window.location.pathname !== '/auth/login'
|
|
41
|
+
) {
|
|
42
|
+
baseName = `/${institutionCode}`
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
tenantCode = window.location.hostname.split('.')[0]
|
|
46
|
+
if (institutionCode && window.location.pathname !== '/auth/login') {
|
|
47
|
+
baseName = `/${institutionCode}`
|
|
32
48
|
}
|
|
33
49
|
}
|
|
34
50
|
|
|
35
51
|
useEffect(() => {
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
window.location.replace(window.location.origin + `/aupulse`)
|
|
39
|
-
}
|
|
40
|
-
if (campxTenantKey)
|
|
41
|
-
window.location.replace(window.location.origin + `/${campxTenantKey}`)
|
|
42
|
-
} else {
|
|
43
|
-
if (!instituitionKey) {
|
|
44
|
-
if (localInstituitionKey) {
|
|
45
|
-
window.location.replace(
|
|
46
|
-
window.location.origin + `/${urlTenantKey}/${localInstituitionKey}`,
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
52
|
+
if (location.pathname === '/' && institutionCode && tenantCode) {
|
|
53
|
+
window.location.replace(window.location.origin + `/${institutionCode}`)
|
|
50
54
|
}
|
|
51
55
|
}, [])
|
|
52
|
-
|
|
53
|
-
const baseName = getInstituitionKey()
|
|
54
|
-
? `${urlTenantKey}/${getInstituitionKey()}`
|
|
55
|
-
: urlTenantKey
|
|
56
|
-
|
|
57
56
|
return (
|
|
58
57
|
<BrowserRouter basename={baseName}>
|
|
59
58
|
<QueryClientProvider>
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AxiosError } from 'axios'
|
|
2
1
|
import { useEffect, useState } from 'react'
|
|
2
|
+
import { useNavigate } from 'react-router-dom'
|
|
3
3
|
import { toast } from 'react-toastify'
|
|
4
4
|
import axios from '../config/axios'
|
|
5
5
|
import { isDevelopment } from '../constants'
|
|
6
|
-
import { urlTenantKey } from '../contexts/Providers'
|
|
7
6
|
import { openRootModal } from '../contexts/RootModal'
|
|
8
7
|
import { AssetsStore, PermissionsStore, UserStore } from '../shared-state'
|
|
9
8
|
import { InstitutionsStore } from '../shared-state/InstitutionsStore'
|
|
@@ -40,7 +39,7 @@ const ApplicationObj = {
|
|
|
40
39
|
people: 'hrms',
|
|
41
40
|
commute: 'commute_x',
|
|
42
41
|
}
|
|
43
|
-
const checkIsAdmin = (user) => {
|
|
42
|
+
export const checkIsAdmin = (user) => {
|
|
44
43
|
let subDomain = window.location.host.split('.')?.slice(-3)[0]
|
|
45
44
|
const localSubDomain = process.env.REACT_APP_SUBDOMAIN
|
|
46
45
|
|
|
@@ -78,7 +77,6 @@ const getInstitutionKey = () => {
|
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
function handleInstitutions(institutions) {
|
|
81
|
-
const insititutionKey = getInstitutionKey()
|
|
82
80
|
if (institutions?.length === 0) {
|
|
83
81
|
openRootModal({
|
|
84
82
|
key: 'institutions-not-assigned',
|
|
@@ -87,173 +85,97 @@ function handleInstitutions(institutions) {
|
|
|
87
85
|
onClose: () => {},
|
|
88
86
|
},
|
|
89
87
|
})
|
|
90
|
-
}
|
|
91
|
-
if (institutions?.length === 1) {
|
|
92
|
-
if (!insititutionKey) {
|
|
93
|
-
window.location.replace(
|
|
94
|
-
`${window.location.origin}/${urlTenantKey}/${institutions[0]?.code}`,
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
if (insititutionKey !== institutions[0]?.code) {
|
|
98
|
-
window.location.replace(
|
|
99
|
-
`${window.location.origin}/${urlTenantKey}/${institutions[0]?.code}`,
|
|
100
|
-
)
|
|
101
|
-
}
|
|
88
|
+
} else {
|
|
102
89
|
InstitutionsStore.update((s) => {
|
|
103
90
|
s.current = institutions[0]
|
|
104
91
|
s.institutions = institutions
|
|
105
92
|
})
|
|
106
93
|
}
|
|
107
|
-
if (institutions?.length > 1) {
|
|
108
|
-
if (!insititutionKey) {
|
|
109
|
-
openRootModal({
|
|
110
|
-
key: 'institutions',
|
|
111
|
-
dialogProps: {
|
|
112
|
-
disableEscapeKeyDown: true,
|
|
113
|
-
onClose: () => {},
|
|
114
|
-
maxWidth: 'md',
|
|
115
|
-
},
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
if (
|
|
119
|
-
insititutionKey &&
|
|
120
|
-
!institutions?.find((item) => item.code === insititutionKey)
|
|
121
|
-
) {
|
|
122
|
-
openRootModal({
|
|
123
|
-
key: 'institutions',
|
|
124
|
-
dialogProps: {
|
|
125
|
-
disableEscapeKeyDown: true,
|
|
126
|
-
onClose: () => {},
|
|
127
|
-
},
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
InstitutionsStore.update((s) => {
|
|
131
|
-
s.institutions = institutions
|
|
132
|
-
s.current = institutions.find((item) => item.code === insititutionKey)
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
94
|
}
|
|
136
95
|
|
|
137
|
-
const
|
|
96
|
+
const useAuth = ({
|
|
97
|
+
permissionsEndpoint,
|
|
138
98
|
loginUrl,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
loginUrl: string
|
|
143
|
-
setLoading?: any
|
|
144
|
-
err: AxiosError
|
|
145
|
-
}) => {
|
|
146
|
-
setLoading && setLoading(false)
|
|
147
|
-
const origin = window.location.origin
|
|
148
|
-
const isStaging = origin.split('campx')[1] === '.dev'
|
|
149
|
-
const isSetup = window.location.hostname.split('.').includes('setup')
|
|
150
|
-
|
|
151
|
-
if (isDevelopment || isStaging || isSetup) {
|
|
152
|
-
openRootModal({
|
|
153
|
-
key: 'login',
|
|
154
|
-
contentData: {
|
|
155
|
-
loginUrl,
|
|
156
|
-
},
|
|
157
|
-
dialogProps: {
|
|
158
|
-
disableEscapeKeyDown: true,
|
|
159
|
-
onClose: () => {},
|
|
160
|
-
},
|
|
161
|
-
})
|
|
162
|
-
return
|
|
163
|
-
} else {
|
|
164
|
-
window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (err.response.status !== 401) {
|
|
168
|
-
if (err.response.status > 400 && err.response.status < 500) {
|
|
169
|
-
window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
|
|
170
|
-
} else {
|
|
171
|
-
toast.error('Server Error')
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
177
|
-
const [loading, setLoading] = useState<boolean>(false)
|
|
178
|
-
const [data, setData] = useState(null)
|
|
99
|
+
}: AuthParams): AuthResponse => {
|
|
100
|
+
const [loading, setLoading] = useState<boolean>(true)
|
|
101
|
+
const [data, setData] = useState<any>(null)
|
|
179
102
|
const { current } = InstitutionsStore.useState()
|
|
103
|
+
const navigate = useNavigate()
|
|
180
104
|
|
|
181
105
|
const appInit = async () => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// eslint-disable-next-line no-console
|
|
196
|
-
|
|
197
|
-
if (isDevelopment == false && isStaging == false && !isSetup) {
|
|
198
|
-
if (
|
|
199
|
-
!res.data.applications.includes(ApplicationObj[originSubdomain])
|
|
200
|
-
) {
|
|
201
|
-
window.location.replace(
|
|
202
|
-
`https://www.id.campx.in/apps?redirect_to=${url}`,
|
|
203
|
-
)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
106
|
+
try {
|
|
107
|
+
const res = await axios.get(permissionsEndpoint)
|
|
108
|
+
const isAdmin = checkIsAdmin(res.data.user)
|
|
109
|
+
setLoading(false)
|
|
110
|
+
setData(res.data)
|
|
111
|
+
|
|
112
|
+
UserStore.update((s) => {
|
|
113
|
+
s.username = res.data?.user?.username
|
|
114
|
+
s.user = res.data?.user
|
|
115
|
+
s.roles = res.data?.roles
|
|
116
|
+
s.globalUserId = res.data?.globalUserId
|
|
117
|
+
s.fullName = res.data?.fullName
|
|
118
|
+
})
|
|
206
119
|
|
|
207
|
-
|
|
208
|
-
|
|
120
|
+
PermissionsStore.update((s) => {
|
|
121
|
+
s.permissions = {
|
|
122
|
+
...res.data?.permissions,
|
|
123
|
+
can_settings_view: 1,
|
|
124
|
+
can_dashboard_view: 1,
|
|
125
|
+
can_individual_pages_view: 1,
|
|
126
|
+
can_analatics_view: isAdmin,
|
|
127
|
+
can_admin_view: isAdmin,
|
|
128
|
+
can_my_mentees_view:
|
|
129
|
+
res.data?.user?.isMentor &&
|
|
130
|
+
res.data?.permissions.can_my_mentees_view,
|
|
209
131
|
}
|
|
132
|
+
s.applications = res.data?.applications ?? []
|
|
133
|
+
s.institutionType = res.data?.institutionType
|
|
134
|
+
s.masterInstitutionUniqueId = res.data?.masterInstitutionUniqueId
|
|
135
|
+
s.masterInstitutionId = res.data?.masterInstitutionId
|
|
136
|
+
s.isMasterInstitutionUser = res.data?.institutions
|
|
137
|
+
?.map((institution) => institution?.id)
|
|
138
|
+
?.includes(res?.data?.masterInstitutionUniqueId)
|
|
139
|
+
s.isMasterInstitution = res.data?.isMasterInstitution
|
|
140
|
+
s.isHomePageEnabled = res.data?.isHomePageEnabled
|
|
141
|
+
})
|
|
210
142
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
s.user = res.data?.user
|
|
215
|
-
s.roles = res.data?.roles
|
|
216
|
-
s.globalUserId = res.data?.globalUserId
|
|
217
|
-
s.fullName = res.data?.fullName
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
PermissionsStore.update((s) => {
|
|
221
|
-
s.permissions = {
|
|
222
|
-
...res.data?.permissions,
|
|
223
|
-
can_settings_view: 1,
|
|
224
|
-
can_dashboard_view: 1,
|
|
225
|
-
can_individual_pages_view: 1,
|
|
226
|
-
can_analatics_view: isAdmin,
|
|
227
|
-
can_admin_view: isAdmin,
|
|
228
|
-
can_my_mentees_view:
|
|
229
|
-
res.data?.user?.isMentor &&
|
|
230
|
-
res.data?.permissions.can_my_mentees_view,
|
|
231
|
-
} as any
|
|
232
|
-
s.applications = res.data?.applications ?? []
|
|
233
|
-
s.institutionType = res.data?.institutionType
|
|
234
|
-
s.masterInstitutionUniqueId = res.data?.masterInstitutionUniqueId
|
|
235
|
-
s.masterInstitutionId = res.data?.masterInstitutionId
|
|
236
|
-
s.isMasterInstitutionUser = res.data?.institutions
|
|
237
|
-
?.map((institution) => institution?.id)
|
|
238
|
-
?.includes(res?.data?.masterInstitutionUniqueId)
|
|
239
|
-
s.isMasterInstitution = res.data?.isMasterInstitution
|
|
240
|
-
s.isHomePageEnabled = res.data?.isHomePageEnabled
|
|
241
|
-
})
|
|
242
|
-
AssetsStore.update((s) => {
|
|
243
|
-
s.logo = res.data?.assets.logo
|
|
244
|
-
s.logo_square = res.data?.assets.logo_square
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
setLoading(false)
|
|
143
|
+
InstitutionsStore.update((s) => {
|
|
144
|
+
s.institutions = res.data?.institutions
|
|
145
|
+
s.current = res.data?.institutions[0]
|
|
248
146
|
})
|
|
249
|
-
|
|
250
|
-
|
|
147
|
+
|
|
148
|
+
AssetsStore.update((s) => {
|
|
149
|
+
s.logo = res.data?.assets.logo
|
|
150
|
+
s.logo_square = res.data?.assets.logo_square
|
|
251
151
|
})
|
|
152
|
+
} catch (err: any) {
|
|
153
|
+
setLoading(false)
|
|
154
|
+
const origin = window.location.origin
|
|
155
|
+
const isStaging = origin.split('campx')[1] === '.dev'
|
|
156
|
+
|
|
157
|
+
if (isDevelopment || isStaging) {
|
|
158
|
+
openRootModal({
|
|
159
|
+
key: 'login',
|
|
160
|
+
contentData: {
|
|
161
|
+
loginUrl,
|
|
162
|
+
},
|
|
163
|
+
dialogProps: {
|
|
164
|
+
disableEscapeKeyDown: true,
|
|
165
|
+
onClose: () => {},
|
|
166
|
+
},
|
|
167
|
+
})
|
|
168
|
+
return
|
|
169
|
+
} else {
|
|
170
|
+
navigate('/auth/login')
|
|
171
|
+
}
|
|
172
|
+
}
|
|
252
173
|
}
|
|
253
|
-
|
|
174
|
+
console.log(loading, !data?.permissions, !current, 'abc1')
|
|
254
175
|
useEffect(() => {
|
|
255
176
|
appInit()
|
|
256
177
|
}, [])
|
|
178
|
+
console.log(loading, !data?.permissions, !current, 'abc2')
|
|
257
179
|
|
|
258
180
|
return {
|
|
259
181
|
loading: loading || !data?.permissions || !current,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { styled as muiStyled } from '@mui/material'
|
|
2
2
|
import styled from 'styled-components'
|
|
3
3
|
|
|
4
|
-
export const headerHeight = '
|
|
4
|
+
export const headerHeight = '96px'
|
|
5
5
|
export const sideNavWidth = '220px'
|
|
6
6
|
|
|
7
7
|
export const StyledLayoutContainer = styled.div`
|
|
@@ -27,17 +27,12 @@ export const StyledLeftNavContainer = muiStyled('aside')(({ theme }) => ({
|
|
|
27
27
|
width: sideNavWidth,
|
|
28
28
|
background: theme.palette.secondary.main,
|
|
29
29
|
color: 'white',
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
left: 0,
|
|
33
|
-
height: `calc(100vh - ${headerHeight})`,
|
|
34
|
-
overflowY: 'auto',
|
|
35
|
-
|
|
30
|
+
borderRadius: '8px 0px 0px 8px',
|
|
31
|
+
overflowY: 'scroll',
|
|
36
32
|
'&::-webkit-scrollbar': {
|
|
37
33
|
width: '0.5em',
|
|
38
34
|
height: '0.5em',
|
|
39
35
|
},
|
|
40
|
-
|
|
41
36
|
'&::-webkit-scrollbar-thumb': {
|
|
42
37
|
backgroundColor: 'rgba(255, 255, 255, 0.3)',
|
|
43
38
|
borderRadius: '3px',
|
|
@@ -46,23 +41,11 @@ export const StyledLeftNavContainer = muiStyled('aside')(({ theme }) => ({
|
|
|
46
41
|
background: 'rgba(255, 255, 255, 0.4)',
|
|
47
42
|
},
|
|
48
43
|
},
|
|
49
|
-
|
|
50
|
-
zIndex: 100,
|
|
51
44
|
}))
|
|
52
45
|
|
|
53
46
|
export const StyledMainContentContainer = muiStyled('main')(() => ({
|
|
54
|
-
width:
|
|
55
|
-
|
|
56
|
-
? `calc(100% - ${sideNavWidth})`
|
|
57
|
-
: '100% !important',
|
|
58
|
-
height: `calc(100vh - ${headerHeight})`,
|
|
59
|
-
position: 'fixed',
|
|
60
|
-
top: headerHeight,
|
|
61
|
-
left: window.innerWidth > 1024 ? sideNavWidth : 0,
|
|
62
|
-
right: window.innerWidth > 1024 ? 'unset' : 0,
|
|
63
|
-
bottom: window.innerWidth > 1024 ? 'unset' : 0,
|
|
64
|
-
overflowY: 'auto',
|
|
65
|
-
|
|
47
|
+
width: '100%',
|
|
48
|
+
overflowY: 'scroll',
|
|
66
49
|
'&::-webkit-scrollbar': {
|
|
67
50
|
width: '0.4em',
|
|
68
51
|
height: '0.4em',
|
|
@@ -75,18 +58,4 @@ export const StyledMainContentContainer = muiStyled('main')(() => ({
|
|
|
75
58
|
background: 'rgba(0,0,0, 0.4)',
|
|
76
59
|
},
|
|
77
60
|
},
|
|
78
|
-
|
|
79
|
-
// '&::-webkit-scrollbar': {
|
|
80
|
-
// width: '0.6em',
|
|
81
|
-
// height: '0.6em',
|
|
82
|
-
// },
|
|
83
|
-
|
|
84
|
-
// '&::-webkit-scrollbar-thumb': {
|
|
85
|
-
// backgroundColor: 'rgba(0,0,0, 0.3)',
|
|
86
|
-
// borderRadius: '3px',
|
|
87
|
-
|
|
88
|
-
// '&:hover': {
|
|
89
|
-
// background: 'rgba(0,0,0, 0.4)',
|
|
90
|
-
// },
|
|
91
|
-
// },
|
|
92
61
|
}))
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { AssetsStore } from './AssetsStore'
|
|
2
|
+
import { InstitutionsStore } from './InstitutionsStore'
|
|
3
|
+
import { Permission, PermissionsStore } from './PermissionsStore'
|
|
2
4
|
import { UserStore } from './UserStore'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
export {
|
|
6
|
+
AssetsStore,
|
|
7
|
+
InstitutionsStore,
|
|
8
|
+
Permission,
|
|
9
|
+
PermissionsStore,
|
|
10
|
+
UserStore,
|
|
11
|
+
}
|
package/src/utils/logout.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Cookies from 'js-cookie'
|
|
2
2
|
import axios, { axiosErrorToast } from '../config/axios'
|
|
3
|
-
import { isDevelopment, isSetup } from '../constants'
|
|
4
3
|
|
|
5
4
|
export default function logout() {
|
|
6
5
|
axios({
|
|
@@ -9,13 +8,10 @@ export default function logout() {
|
|
|
9
8
|
url: '/auth-server/auth/logout',
|
|
10
9
|
})
|
|
11
10
|
.then((res) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} else {
|
|
17
|
-
window.location.href = 'https://id.campx.in'
|
|
18
|
-
}
|
|
11
|
+
Cookies.remove('campx_tenant')
|
|
12
|
+
Cookies.remove('campx_session_key')
|
|
13
|
+
Cookies.remove('campx_institution')
|
|
14
|
+
window.location.href = '/'
|
|
19
15
|
})
|
|
20
16
|
.catch((err) => {
|
|
21
17
|
axiosErrorToast('Unable To Logout.')
|
package/styled-components.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import styled from 'styled-components'
|
|
2
1
|
import { styled as muiStyled } from '@mui/material'
|
|
2
|
+
import styled from 'styled-components'
|
|
3
3
|
|
|
4
|
-
export const headerHeight = '
|
|
4
|
+
export const headerHeight = '96px'
|
|
5
5
|
export const sideNavWidth = '220px'
|
|
6
6
|
|
|
7
7
|
export const StyledLayoutContainer = styled.div`
|
|
@@ -12,11 +12,11 @@ export const StyledLayoutContainer = styled.div`
|
|
|
12
12
|
export const StyledHeaderContainer = styled.header`
|
|
13
13
|
z-index: 300;
|
|
14
14
|
width: 100%;
|
|
15
|
-
position: fixed;
|
|
16
15
|
top: 0;
|
|
17
16
|
left: 0;
|
|
18
17
|
min-height: ${headerHeight};
|
|
19
18
|
background: #fff;
|
|
19
|
+
|
|
20
20
|
& > div {
|
|
21
21
|
height: ${headerHeight};
|
|
22
22
|
}
|