@campxdev/shared 0.5.21 → 0.5.22

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.
Files changed (69) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +34 -0
  3. package/.prettierrc +10 -0
  4. package/exports.ts +7 -6
  5. package/package.json +64 -50
  6. package/publish.sh +2 -0
  7. package/src/assets/images/index.ts +8 -8
  8. package/src/components/Breadcrumbs.tsx +3 -3
  9. package/src/components/ChangePassword.tsx +147 -147
  10. package/src/components/DropDownButton.tsx +167 -163
  11. package/src/components/ErrorBoundary/ErrorBoundary.tsx +22 -22
  12. package/src/components/ErrorBoundary/ErrorFallback.tsx +215 -215
  13. package/src/components/ErrorBoundary/GlobalNetworkLoadingIndicator.tsx +6 -6
  14. package/src/components/ErrorBoundary/index.tsx +1 -1
  15. package/src/components/FullScreenLoader.tsx +15 -15
  16. package/src/components/HookForm/AutoCompleteSearch.tsx +0 -30
  17. package/src/components/HookForm/RadioGroup.tsx +1 -1
  18. package/src/components/IconButtons/Icons.tsx +1 -2
  19. package/src/components/Input/AutoCompleteSearch.tsx +0 -30
  20. package/src/components/Input/SingleSelect.tsx +0 -15
  21. package/src/components/Layout/Header/AppHeader.tsx +89 -89
  22. package/src/components/Layout/Header/AppsMenu.tsx +79 -79
  23. package/src/components/Layout/Header/CogWheelMenu.tsx +27 -27
  24. package/src/components/Layout/Header/UserBox.tsx +25 -25
  25. package/src/components/Layout/Header/applications.ts +79 -79
  26. package/src/components/Layout/Header/assets/index.ts +10 -10
  27. package/src/components/Layout/Header/styles.tsx +72 -72
  28. package/src/components/LayoutWrapper.tsx +6 -6
  29. package/src/components/LinearProgress.tsx +14 -14
  30. package/src/components/ListItemButton.tsx +79 -79
  31. package/src/components/LoginForm.tsx +86 -86
  32. package/src/components/MenuButton.tsx +88 -88
  33. package/src/components/ModalButtons/DialogButton.tsx +66 -66
  34. package/src/components/PageContent.tsx +10 -10
  35. package/src/components/PageNotFound.tsx +12 -12
  36. package/src/components/PopupConfirm/ConfirmContextProvider.tsx +28 -28
  37. package/src/components/PopupConfirm/PopupConfirm.tsx +27 -27
  38. package/src/components/PopupConfirm/useConfirm.ts +41 -41
  39. package/src/components/SideMenuHeader.tsx +15 -15
  40. package/src/components/SideNav.tsx +119 -119
  41. package/src/components/Spinner.tsx +14 -14
  42. package/src/components/TableComponent/ReactTable.tsx +256 -256
  43. package/src/components/TableComponent/RenderTableBody.tsx +56 -56
  44. package/src/components/TableComponent/index.tsx +171 -171
  45. package/src/components/TableComponent/react-table-config.d.ts +2 -3
  46. package/src/components/index.ts +54 -54
  47. package/src/config/axios.ts +50 -50
  48. package/src/config/axiosXTenant.ts +57 -0
  49. package/src/constants/isDevelopment.ts +2 -2
  50. package/src/contexts/LoginFormProvider.tsx +28 -28
  51. package/src/contexts/Providers.tsx +40 -40
  52. package/src/contexts/QueryClientProvider.tsx +15 -15
  53. package/src/hooks/index.ts +2 -2
  54. package/src/hooks/useAppInit.ts +23 -23
  55. package/src/hooks/useAuth.ts +78 -77
  56. package/src/layouts/Components/DashBoardMenu.tsx +77 -77
  57. package/src/layouts/Components/icons/index.tsx +32 -32
  58. package/src/layouts/Components/styles.tsx +23 -23
  59. package/src/permissions/PageWithPermission.tsx +9 -9
  60. package/src/permissions/PermissionDeniedPage.tsx +13 -13
  61. package/src/permissions/PermissionsStore.ts +303 -303
  62. package/src/shared-state/index.ts +3 -3
  63. package/src/theme/MuiThemeProvider.tsx +9 -9
  64. package/src/theme/theme.d.ts +72 -72
  65. package/src/utils/index.ts +7 -7
  66. package/src/utils/logout.ts +19 -19
  67. package/src/utils/withLocalization.tsx +8 -8
  68. package/src/utils/withRouteWrapper.tsx +20 -20
  69. package/src/utils/withSuspense.tsx +3 -3
@@ -1,236 +1,236 @@
1
- import {Alert, Box, Button, Divider, styled, Typography} from '@mui/material'
2
- import {useEffect, useState} from 'react'
1
+ import { Alert, Box, Button, Divider, styled, Typography } from '@mui/material'
2
+ import { useEffect, useState } from 'react'
3
3
  import {
4
- nointernet,
5
- pagenotfound,
6
- permissiondenied,
7
- unauth,
8
- internalserver,
4
+ nointernet,
5
+ pagenotfound,
6
+ permissiondenied,
7
+ unauth,
8
+ internalserver,
9
9
  } from '../../assets/images'
10
10
  import Cookies from 'js-cookie'
11
11
  import LoginForm from '../LoginForm'
12
- import {useModal} from '../DrawerWrapper/DrawerWrapper'
13
- import {PermissionsStore} from '../../permissions'
12
+ import { useModal } from '../DrawerWrapper/DrawerWrapper'
13
+ import { PermissionsStore } from '../../permissions'
14
14
  import axios from '../../config/axios'
15
15
 
16
- const StyledAlert = styled(Alert)(({theme}) => ({
17
- border: `1px solid ${theme.palette.error.main}`,
18
- display: 'flex',
19
- alignItems: 'center',
20
- '& .MuiAlert-message': {
21
- padding: 0,
22
- },
23
- '& .MuiTypography-root': {
24
- margin: 0,
25
- },
26
- position: 'relative',
27
- '& .retryBtn': {
28
- color: '#661b2a',
29
- position: 'absolute',
30
- right: 8,
31
- top: 8,
32
- },
16
+ const StyledAlert = styled(Alert)(({ theme }) => ({
17
+ border: `1px solid ${theme.palette.error.main}`,
18
+ display: 'flex',
19
+ alignItems: 'center',
20
+ '& .MuiAlert-message': {
21
+ padding: 0,
22
+ },
23
+ '& .MuiTypography-root': {
24
+ margin: 0,
25
+ },
26
+ position: 'relative',
27
+ '& .retryBtn': {
28
+ color: '#661b2a',
29
+ position: 'absolute',
30
+ right: 8,
31
+ top: 8,
32
+ },
33
33
  }))
34
34
 
35
- const StyledBox = styled(Box)(({theme}) => ({
36
- width: '100%',
37
- display: 'flex',
38
- flexDirection: 'column',
39
- alignItems: 'center',
40
- justifyContent: 'center',
35
+ const StyledBox = styled(Box)(({ theme }) => ({
36
+ width: '100%',
37
+ display: 'flex',
38
+ flexDirection: 'column',
39
+ alignItems: 'center',
40
+ justifyContent: 'center',
41
41
  }))
42
42
 
43
- export default function ErrorFallback({error, resetErrorBoundary}) {
44
- if (error?.response?.status) {
45
- switch (error?.response?.status) {
46
- case 401:
47
- return <UnAuth resetBoundary={resetErrorBoundary} />
48
-
49
- case 500:
50
- return (
51
- <InternalServer resetBoundary={resetErrorBoundary} error={error} />
52
- )
53
-
54
- case 403:
55
- return <PemissionDenied resetBoundary={resetErrorBoundary} />
56
-
57
- default:
58
- return (
59
- <InternalServer resetBoundary={resetErrorBoundary} error={error} />
60
- )
61
- }
62
- }
63
-
64
- if (error?.message === 'Network Error') {
65
- return <NoInternet resetBoundary={resetErrorBoundary} />
66
- }
67
-
68
- return (
69
- <Box sx={{marginTop: '16px', padding: '16px'}}>
70
- <StyledAlert severity='error'>
71
- {error?.response?.data?.message ?? error?.message}
72
- <Button
73
- className='retryBtn'
74
- onClick={() => resetErrorBoundary()}
75
- size='small'
76
- color='error'
77
- variant='outlined'
78
- >
79
- Try Again
80
- </Button>
81
- </StyledAlert>
82
- </Box>
83
- )
43
+ export default function ErrorFallback({ error, resetErrorBoundary }) {
44
+ if (error?.response?.status) {
45
+ switch (error?.response?.status) {
46
+ case 401:
47
+ return <UnAuth resetBoundary={resetErrorBoundary} />
48
+
49
+ case 500:
50
+ return (
51
+ <InternalServer resetBoundary={resetErrorBoundary} error={error} />
52
+ )
53
+
54
+ case 403:
55
+ return <PemissionDenied resetBoundary={resetErrorBoundary} />
56
+
57
+ default:
58
+ return (
59
+ <InternalServer resetBoundary={resetErrorBoundary} error={error} />
60
+ )
61
+ }
62
+ }
63
+
64
+ if (error?.message === 'Network Error') {
65
+ return <NoInternet resetBoundary={resetErrorBoundary} />
66
+ }
67
+
68
+ return (
69
+ <Box sx={{ marginTop: '16px', padding: '16px' }}>
70
+ <StyledAlert severity="error">
71
+ {error?.response?.data?.message ?? error?.message}
72
+ <Button
73
+ className="retryBtn"
74
+ onClick={() => resetErrorBoundary()}
75
+ size="small"
76
+ color="error"
77
+ variant="outlined"
78
+ >
79
+ Try Again
80
+ </Button>
81
+ </StyledAlert>
82
+ </Box>
83
+ )
84
84
  }
85
85
 
86
- export function PageNotFound({resetBoundary}) {
87
- return (
88
- <>
89
- <StyledBox>
90
- <img
91
- src={pagenotfound}
92
- alt='page not found'
93
- width={470}
94
- style={{marginTop: '20px'}}
95
- />
96
- <Typography variant='h1'>Page Not Found.</Typography>
97
- <Button sx={{marginTop: '20px'}} onClick={() => resetBoundary()}>
98
- Try Again
99
- </Button>
100
- </StyledBox>
101
- </>
102
- )
86
+ export function PageNotFound({ resetBoundary }) {
87
+ return (
88
+ <>
89
+ <StyledBox>
90
+ <img
91
+ src={pagenotfound}
92
+ alt="page not found"
93
+ width={470}
94
+ style={{ marginTop: '20px' }}
95
+ />
96
+ <Typography variant="h1">Page Not Found.</Typography>
97
+ <Button sx={{ marginTop: '20px' }} onClick={() => resetBoundary()}>
98
+ Try Again
99
+ </Button>
100
+ </StyledBox>
101
+ </>
102
+ )
103
103
  }
104
104
 
105
- export function NoInternet({resetBoundary}) {
106
- return (
107
- <>
108
- <StyledBox>
109
- <img src={nointernet} alt='No Internet Found' width={470} />
110
- <Typography variant='h1'>No Internet Found.</Typography>
111
- <Button sx={{marginTop: '20px'}} onClick={() => resetBoundary()}>
112
- Try Again
113
- </Button>
114
- </StyledBox>
115
- </>
116
- )
105
+ export function NoInternet({ resetBoundary }) {
106
+ return (
107
+ <>
108
+ <StyledBox>
109
+ <img src={nointernet} alt="No Internet Found" width={470} />
110
+ <Typography variant="h1">No Internet Found.</Typography>
111
+ <Button sx={{ marginTop: '20px' }} onClick={() => resetBoundary()}>
112
+ Try Again
113
+ </Button>
114
+ </StyledBox>
115
+ </>
116
+ )
117
117
  }
118
118
 
119
- export function PemissionDenied({resetBoundary}) {
120
- return (
121
- <>
122
- <StyledBox>
123
- <img src={permissiondenied} alt='permission denied' width={470} />
124
- <Typography variant='h1'>Permission Denied.</Typography>
125
- <Button sx={{marginTop: '20px'}} onClick={() => resetBoundary()}>
126
- Try Again
127
- </Button>
128
- </StyledBox>
129
- </>
130
- )
119
+ export function PemissionDenied({ resetBoundary }) {
120
+ return (
121
+ <>
122
+ <StyledBox>
123
+ <img src={permissiondenied} alt="permission denied" width={470} />
124
+ <Typography variant="h1">Permission Denied.</Typography>
125
+ <Button sx={{ marginTop: '20px' }} onClick={() => resetBoundary()}>
126
+ Try Again
127
+ </Button>
128
+ </StyledBox>
129
+ </>
130
+ )
131
131
  }
132
132
 
133
- export function InternalServer({resetBoundary, error}) {
134
- return (
135
- <>
136
- <StyledBox>
137
- <img src={internalserver} alt='internal server error' width={470} />
138
- <Typography variant='h1' marginTop={'20px'}>
139
- Internal Server Error.
140
- </Typography>
141
- <Typography variant='body1'>
142
- {error?.response?.data?.message}
143
- </Typography>
144
- <Button
145
- size='small'
146
- variant='outlined'
147
- sx={{marginTop: '20px'}}
148
- onClick={() => resetBoundary()}
149
- >
150
- Try Again
151
- </Button>
152
- </StyledBox>
153
- </>
154
- )
133
+ export function InternalServer({ resetBoundary, error }) {
134
+ return (
135
+ <>
136
+ <StyledBox>
137
+ <img src={internalserver} alt="internal server error" width={470} />
138
+ <Typography variant="h1" marginTop={'20px'}>
139
+ Internal Server Error.
140
+ </Typography>
141
+ <Typography variant="body1">
142
+ {error?.response?.data?.message}
143
+ </Typography>
144
+ <Button
145
+ size="small"
146
+ variant="outlined"
147
+ sx={{ marginTop: '20px' }}
148
+ onClick={() => resetBoundary()}
149
+ >
150
+ Try Again
151
+ </Button>
152
+ </StyledBox>
153
+ </>
154
+ )
155
155
  }
156
156
 
157
- export function UnAuth({resetBoundary}) {
158
- const modal = useModal()
159
- const [username, setUsername] = useState('')
160
- const [loading, setLoading] = useState(false)
161
-
162
- const url = window.location.origin
163
- const origin = window?.location?.origin?.split('.')
164
- const isLocalHost =
165
- process.env.NODE_ENV === 'development' ||
166
- origin?.slice(-2).join('.') === 'campx.dev'
167
- const sessionCookie = Cookies.get('campx_session_key')
168
- const appinit = async () => {
169
- setLoading(true)
170
- await axios
171
- .get('/auth/my-permissions')
172
- .then((res) => {
173
- setUsername(res.data.user.fullName)
174
- PermissionsStore.update((s) => {
175
- s.permissions = {
176
- ...res.data?.permissions,
177
- can_settings_view: 1,
178
- can_dashboard_view: 1,
179
- can_individual_pages_view: 1,
180
- } as any
181
- })
182
- setLoading(false)
183
- })
184
- .catch((e) => {
185
- modal({
186
- title: 'Login',
187
- content: () => <LoginForm />,
188
- })
189
- })
190
- }
191
- function LoginPage() {
192
- if (isLocalHost) {
193
- if (!sessionCookie) {
194
- modal({
195
- title: 'Login',
196
- content: () => <LoginForm />,
197
- })
198
- } else {
199
- appinit()
200
- }
201
- } else {
202
- if (!sessionCookie) {
203
- window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
204
- } else {
205
- appinit()
206
- }
207
- }
208
- }
209
-
210
- return (
211
- <>
212
- <StyledBox>
213
- <img src={unauth} alt='unauthorized' width={470} />
214
- <Typography variant='h1' marginTop={'20px'}>
215
- UnAuthorized.
216
- </Typography>
217
- <Box
218
- sx={{
219
- display: 'flex',
220
- marginTop: '20px',
221
- }}
222
- >
223
- <Button
224
- variant='outlined'
225
- sx={{marginRight: '10px'}}
226
- onClick={() => resetBoundary()}
227
- >
228
- Try Again
229
- </Button>
230
-
231
- <Button onClick={() => LoginPage()}>Click here to Login</Button>
232
- </Box>
233
- </StyledBox>
234
- </>
235
- )
157
+ export function UnAuth({ resetBoundary }) {
158
+ const modal = useModal()
159
+ const [username, setUsername] = useState('')
160
+ const [loading, setLoading] = useState(false)
161
+
162
+ const url = window.location.origin
163
+ const origin = window?.location?.origin?.split('.')
164
+ const isLocalHost =
165
+ process.env.NODE_ENV === 'development' ||
166
+ origin?.slice(-2).join('.') === 'campx.dev'
167
+ const sessionCookie = Cookies.get('campx_session_key')
168
+ const appinit = async () => {
169
+ setLoading(true)
170
+ await axios
171
+ .get('/auth/my-permissions')
172
+ .then((res) => {
173
+ setUsername(res.data.user.fullName)
174
+ PermissionsStore.update((s) => {
175
+ s.permissions = {
176
+ ...res.data?.permissions,
177
+ can_settings_view: 1,
178
+ can_dashboard_view: 1,
179
+ can_individual_pages_view: 1,
180
+ } as any
181
+ })
182
+ setLoading(false)
183
+ })
184
+ .catch((e) => {
185
+ modal({
186
+ title: 'Login',
187
+ content: () => <LoginForm />,
188
+ })
189
+ })
190
+ }
191
+ function LoginPage() {
192
+ if (isLocalHost) {
193
+ if (!sessionCookie) {
194
+ modal({
195
+ title: 'Login',
196
+ content: () => <LoginForm />,
197
+ })
198
+ } else {
199
+ appinit()
200
+ }
201
+ } else {
202
+ if (!sessionCookie) {
203
+ window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
204
+ } else {
205
+ appinit()
206
+ }
207
+ }
208
+ }
209
+
210
+ return (
211
+ <>
212
+ <StyledBox>
213
+ <img src={unauth} alt="unauthorized" width={470} />
214
+ <Typography variant="h1" marginTop={'20px'}>
215
+ UnAuthorized.
216
+ </Typography>
217
+ <Box
218
+ sx={{
219
+ display: 'flex',
220
+ marginTop: '20px',
221
+ }}
222
+ >
223
+ <Button
224
+ variant="outlined"
225
+ sx={{ marginRight: '10px' }}
226
+ onClick={() => resetBoundary()}
227
+ >
228
+ Try Again
229
+ </Button>
230
+
231
+ <Button onClick={() => LoginPage()}>Click here to Login</Button>
232
+ </Box>
233
+ </StyledBox>
234
+ </>
235
+ )
236
236
  }
@@ -1,13 +1,13 @@
1
- import {Store} from 'pullstate'
2
- import {LinearProgress} from '../LinearProgress'
1
+ import { Store } from 'pullstate'
2
+ import { LinearProgress } from '../LinearProgress'
3
3
 
4
4
  export const NetworkStore = new Store({
5
- loading: false,
5
+ loading: false,
6
6
  })
7
7
 
8
8
  export default function GlobalNetworkLoadingIndicator() {
9
- const {loading} = NetworkStore.useState()
9
+ const { loading } = NetworkStore.useState()
10
10
 
11
- if (loading) return <LinearProgress />
12
- if (loading) return null
11
+ if (loading) return <LinearProgress />
12
+ if (loading) return null
13
13
  }
@@ -1 +1 @@
1
- export {default} from './ErrorBoundary'
1
+ export { default } from './ErrorBoundary'
@@ -1,19 +1,19 @@
1
- import {Box, CircularProgress} from '@mui/material'
1
+ import { Box, CircularProgress } from '@mui/material'
2
2
 
3
3
  const FullScreenLoader = () => {
4
- return (
5
- <Box
6
- sx={{
7
- margin: 0,
8
- padding: 0,
9
- height: '100vh',
10
- width: '100vw',
11
- display: 'grid',
12
- placeItems: 'center',
13
- }}
14
- >
15
- <CircularProgress size={60} />
16
- </Box>
17
- )
4
+ return (
5
+ <Box
6
+ sx={{
7
+ margin: 0,
8
+ padding: 0,
9
+ height: '100vh',
10
+ width: '100vw',
11
+ display: 'grid',
12
+ placeItems: 'center',
13
+ }}
14
+ >
15
+ <CircularProgress size={60} />
16
+ </Box>
17
+ )
18
18
  }
19
19
  export default FullScreenLoader
@@ -111,33 +111,3 @@ export default function FormAutoCompleteSearch({
111
111
  />
112
112
  )
113
113
  }
114
-
115
- export function MyAutoComplete({
116
- value,
117
- onChange,
118
- options,
119
- label,
120
- loading,
121
- ...props
122
- }) {
123
- return (
124
- <Autocomplete
125
- loading={loading}
126
- value={value}
127
- fullWidth
128
- freeSolo
129
- onChange={(e, value) => {
130
- onChange(value.value)
131
- }}
132
- options={options || []}
133
- getOptionLabel={(option: Option) => option?.label || ''}
134
- renderInput={(params) => (
135
- <TextField
136
- {...params}
137
- variant="outlined"
138
- label={<FormLabel label={label} required={props.required} />}
139
- />
140
- )}
141
- />
142
- )
143
- }
@@ -110,4 +110,4 @@ const RadioComponent = ({ label, required, row, options, name, field }) => {
110
110
  </Box>
111
111
  </>
112
112
  )
113
- }
113
+ }
@@ -245,7 +245,6 @@ export const PrintIcon = () => {
245
245
  )
246
246
  }
247
247
 
248
-
249
248
  export const DateRangeIcon = () => {
250
249
  return (
251
250
  <svg
@@ -266,4 +265,4 @@ export const DateRangeIcon = () => {
266
265
  </g>
267
266
  </svg>
268
267
  )
269
- }
268
+ }
@@ -111,33 +111,3 @@ export default function AutoCompleteSearch({
111
111
  />
112
112
  )
113
113
  }
114
-
115
- export function MyAutoComplete({
116
- value,
117
- onChange,
118
- options,
119
- label,
120
- loading,
121
- ...props
122
- }) {
123
- return (
124
- <Autocomplete
125
- loading={loading}
126
- value={value}
127
- fullWidth
128
- freeSolo
129
- onChange={(e, value) => {
130
- onChange(value.value)
131
- }}
132
- options={options || []}
133
- getOptionLabel={(option: Option) => option?.label || ''}
134
- renderInput={(params) => (
135
- <TextField
136
- {...params}
137
- variant="outlined"
138
- label={<FormLabel label={label} required={props.required} />}
139
- />
140
- )}
141
- />
142
- )
143
- }
@@ -122,18 +122,3 @@ export default function SingleSelect(props: Props) {
122
122
  />
123
123
  )
124
124
  }
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-