@campxdev/shared 1.11.7-0.aplha.30 → 1.11.7-1.alpha.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 CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.11.7-0.aplha.30",
3
+ "version": "1.11.7-1.alpha.2",
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
- "@mui/icons-material": "^5.15.18",
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.18",
36
+ "@mui/material": "^5.15.20",
37
37
  "@mui/x-date-pickers": "^6.16.0",
38
- "axios": "^0.27.2",
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.1",
43
+ "js-cookie": "^3.0.5",
44
44
  "moment": "^2.29.4",
45
45
  "pullstate": "^1.24.0",
46
- "react": "^18.2.0",
46
+ "react": "^18.3.1",
47
47
  "react-arrows": "^1.2.0",
48
- "react-dom": "^18.2.0",
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.0",
55
- "react-router-dom": "^6.4.2",
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.2",
74
+ "@types/js-cookie": "^3.0.6",
77
75
  "@types/node": "^18.11.8",
78
- "@types/react": "^18.0.25",
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",
@@ -66,26 +66,28 @@ export default function AppHeader({
66
66
  imageSx = {},
67
67
  }: AppHeaderProps) {
68
68
  return (
69
- <StyledHeader sx={headerSx}>
70
- <Box sx={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
71
- {showMenu && <AppsMenu />}
72
- <AppLogo clientLogo={clientLogo} imageSx={imageSx} />
73
- </Box>
74
- <Box className="actions">
75
- {customHeaderActions ? (
76
- customHeaderActions
77
- ) : (
78
- <HeaderActions
79
- cogWheelMenu={cogWheelMenu}
80
- fullName={fullName}
81
- userBoxActions={userBoxActions}
82
- profileUrl={profileUrl}
83
- actions={actions}
84
- profileSx={profileSx}
85
- />
86
- )}
87
- </Box>
88
- </StyledHeader>
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: '26px',
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}
@@ -57,7 +57,7 @@ const AppsMenu = () => {
57
57
  sx={{
58
58
  '& .MuiPaper-root': {
59
59
  left: '0 !important',
60
- top: '64px !important',
60
+ top: '96px !important',
61
61
  '&>:last-child': {
62
62
  paddingBottom: '0px',
63
63
  },
@@ -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
- Link,
10
- Avatar,
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: 24px;
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 MenuIcon from '@mui/icons-material/Menu'
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
- <ErrorBoundary>
32
- {window.innerWidth > 1024 && !permissions.isHomePageEnabled && (
33
- <StyledLeftNavContainer>
34
- <SideNav menuItems={menu as any[]} header={sideMenuHeader} />
35
- </StyledLeftNavContainer>
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
- </ErrorBoundary>
37
+ </Stack>
85
38
  )
86
39
  }
87
40
 
@@ -64,7 +64,7 @@ export function LoginForm({
64
64
  Cookies.set('campx_tenant', res?.data?.subDomain)
65
65
  Cookies.set('campx_session_key', res.data?.token)
66
66
  Cookies.set('campx_institution', res.data?.institutionCode)
67
- window.location.href = window.location.origin + `/${res?.data?.subDomain}`
67
+ window.location.reload();
68
68
  } catch (err) {
69
69
  // eslint-disable-next-line no-console
70
70
  console.log(err)
@@ -1,4 +1,4 @@
1
- import Axios, { AxiosRequestConfig } from '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'
@@ -10,6 +10,8 @@ const institutionId =
10
10
  Cookies.get('campx_institution') ?? window.location.pathname.split('/')[1]
11
11
  const openPaymentsKey = Cookies.get('campx_open_payments_key')
12
12
 
13
+ const isProduction = process.env.NODE_ENV === 'production'
14
+
13
15
  export const formatParams = (params) => {
14
16
  return Object.fromEntries(
15
17
  Object.entries(params ?? {})?.map((i) => [
@@ -19,16 +21,20 @@ export const formatParams = (params) => {
19
21
  )
20
22
  }
21
23
 
24
+ console.log(institutionId, sessionKey, 'test')
25
+
22
26
  let axios = Axios.create({
23
27
  baseURL: process.env.REACT_APP_API_HOST,
24
28
  withCredentials: true,
25
29
  headers: {
26
30
  'x-tenant-id': tenantId,
31
+ 'x-institution-code': institutionId,
32
+ campx_session_key: sessionKey,
27
33
  },
28
34
  })
29
35
 
30
36
  axios.interceptors.request.use(
31
- function (config: AxiosRequestConfig) {
37
+ function (config: InternalAxiosRequestConfig) {
32
38
  const params = formatParams(config?.params)
33
39
  NetworkStore.update((s) => {
34
40
  s.loading = true
@@ -4,3 +4,11 @@ export const isNumber = (value: string) => {
4
4
 
5
5
  return isNum
6
6
  }
7
+
8
+ export const isInteger = (value: string) => {
9
+ const regEx = /^[-+]?\d*\.?\d+$/
10
+
11
+ let isInt = regEx.test(value)
12
+
13
+ return isInt
14
+ }
@@ -1,9 +1,10 @@
1
1
  import { AxiosError } from 'axios'
2
+ import Cookies from 'js-cookie'
2
3
  import { useEffect, useState } from 'react'
4
+ import { useNavigate } from 'react-router-dom'
3
5
  import { toast } from 'react-toastify'
4
6
  import axios from '../config/axios'
5
7
  import { isDevelopment } from '../constants'
6
- import { urlTenantKey } from '../contexts/Providers'
7
8
  import { openRootModal } from '../contexts/RootModal'
8
9
  import { AssetsStore, PermissionsStore, UserStore } from '../shared-state'
9
10
  import { InstitutionsStore } from '../shared-state/InstitutionsStore'
@@ -40,7 +41,7 @@ const ApplicationObj = {
40
41
  people: 'hrms',
41
42
  commute: 'commute_x',
42
43
  }
43
- const checkIsAdmin = (user) => {
44
+ export const checkIsAdmin = (user) => {
44
45
  let subDomain = window.location.host.split('.')?.slice(-3)[0]
45
46
  const localSubDomain = process.env.REACT_APP_SUBDOMAIN
46
47
 
@@ -78,7 +79,6 @@ const getInstitutionKey = () => {
78
79
  }
79
80
 
80
81
  function handleInstitutions(institutions) {
81
- const insititutionKey = getInstitutionKey()
82
82
  if (institutions?.length === 0) {
83
83
  openRootModal({
84
84
  key: 'institutions-not-assigned',
@@ -87,51 +87,12 @@ function handleInstitutions(institutions) {
87
87
  onClose: () => {},
88
88
  },
89
89
  })
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
- }
90
+ } else {
102
91
  InstitutionsStore.update((s) => {
103
92
  s.current = institutions[0]
104
93
  s.institutions = institutions
105
94
  })
106
95
  }
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
96
  }
136
97
 
137
98
  const loginErrorHandler = ({
@@ -143,12 +104,12 @@ const loginErrorHandler = ({
143
104
  setLoading?: any
144
105
  err: AxiosError
145
106
  }) => {
107
+ const navigate = useNavigate()
146
108
  setLoading && setLoading(false)
147
109
  const origin = window.location.origin
148
110
  const isStaging = origin.split('campx')[1] === '.dev'
149
- const isSetup = window.location.hostname.split('.').includes('setup')
150
111
 
151
- if (isDevelopment || isStaging || isSetup) {
112
+ if (isDevelopment || isStaging) {
152
113
  openRootModal({
153
114
  key: 'login',
154
115
  contentData: {
@@ -161,15 +122,7 @@ const loginErrorHandler = ({
161
122
  })
162
123
  return
163
124
  } 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
- }
125
+ navigate('/auth/login')
173
126
  }
174
127
  }
175
128
 
@@ -183,30 +136,7 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
183
136
  axios
184
137
  .get(permissionsEndpoint)
185
138
  .then((res) => {
186
- const origin = window.location.origin
187
- const originSubdomain =
188
- window.location.host.split('.')?.slice(-3)[0] ?? 'ums'
189
- const isStaging = origin.split('campx')[1] === '.dev'
190
139
  const isAdmin = checkIsAdmin(res.data.user)
191
- const isSetup =
192
- window.location.hostname.split('.').includes('setup') && isAdmin
193
- const isMasterSlave = res.data?.institutionType === 'MASTER_CHILD'
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
- }
206
-
207
- if (res.data?.institutions) {
208
- handleInstitutions(res.data?.institutions)
209
- }
210
140
 
211
141
  setData(res.data)
212
142
  UserStore.update((s) => {
@@ -239,6 +169,14 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
239
169
  s.isMasterInstitution = res.data?.isMasterInstitution
240
170
  s.isHomePageEnabled = res.data?.isHomePageEnabled
241
171
  })
172
+
173
+ InstitutionsStore.update((s) => {
174
+ s.institutions = res.data?.institutions
175
+ s.current = res.data?.institutions.find(
176
+ (item) => item.code === Cookies.get('campx_institution'),
177
+ )
178
+ })
179
+
242
180
  AssetsStore.update((s) => {
243
181
  s.logo = res.data?.assets.logo
244
182
  s.logo_square = res.data?.assets.logo_square
@@ -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 = '64px'
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
- position: 'fixed',
31
- top: headerHeight,
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
- window.innerWidth > 1024
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
- import { PermissionsStore, Permission } from './PermissionsStore'
4
- export { AssetsStore, UserStore, Permission, PermissionsStore }
5
+ export {
6
+ AssetsStore,
7
+ InstitutionsStore,
8
+ Permission,
9
+ PermissionsStore,
10
+ UserStore,
11
+ }
@@ -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 = '64px'
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
  }