@campxdev/shared 0.5.21 → 0.5.23

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
@@ -0,0 +1,57 @@
1
+ import Axios from 'axios'
2
+ import Cookies from 'js-cookie'
3
+ import { NetworkStore } from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
4
+ import { isDevelopment } from '../constants'
5
+ import { formatParams } from './axios'
6
+
7
+ const sessionKey = Cookies.get('campx_session_key')
8
+ const clientId = window.location.pathname.split('/')[1] ?? 'campx_dev'
9
+ const evaluatorKey = Cookies.get('campx_evaluator_key')
10
+
11
+ const axiosTenant = Axios.create({
12
+ baseURL: process.env.REACT_APP_API_HOST,
13
+ withCredentials: true,
14
+ headers: {
15
+ 'x-tenant-id': isDevelopment ? 'campx_dev' : clientId,
16
+ ...(isDevelopment &&
17
+ sessionKey && {
18
+ campx_session_key: sessionKey,
19
+ }),
20
+ ...(evaluatorKey && {
21
+ campx_evaluator_key: evaluatorKey,
22
+ }),
23
+ },
24
+ })
25
+
26
+ axiosTenant.interceptors.request.use(
27
+ function (config) {
28
+ const params = formatParams(config?.params)
29
+ NetworkStore.update((s) => {
30
+ s.loading = true
31
+ })
32
+ return { ...config, params }
33
+ },
34
+ function (error) {
35
+ NetworkStore.update((s) => {
36
+ s.loading = false
37
+ })
38
+ return Promise.reject(error)
39
+ },
40
+ )
41
+
42
+ axiosTenant.interceptors.response.use(
43
+ function (response) {
44
+ NetworkStore.update((s) => {
45
+ s.loading = false
46
+ })
47
+ return response
48
+ },
49
+ function (err) {
50
+ NetworkStore.update((s) => {
51
+ s.loading = false
52
+ })
53
+ return Promise.reject(err)
54
+ },
55
+ )
56
+
57
+ export default axiosTenant
@@ -1,3 +1,3 @@
1
1
  export const isDevelopment =
2
- process.env.NODE_ENV === 'development' ||
3
- window.location.origin.split('.').slice(-2).join('.') === 'campx.dev'
2
+ process.env.NODE_ENV === 'development' ||
3
+ window.location.origin.split('.').slice(-2).join('.') === 'campx.dev'
@@ -1,39 +1,39 @@
1
- import {createContext, useContext} from 'react'
2
- import {LoginForm} from '../components'
3
- import {useModal} from '../components/DrawerWrapper/DrawerWrapper'
1
+ import { createContext, useContext } from 'react'
2
+ import { LoginForm } from '../components'
3
+ import { useModal } from '../components/DrawerWrapper/DrawerWrapper'
4
4
 
5
5
  const LoginContext = createContext<{
6
- openLoginForm: () => void
6
+ openLoginForm: () => void
7
7
  }>({
8
- openLoginForm: () => {},
8
+ openLoginForm: () => {},
9
9
  })
10
10
 
11
- export default function LoginFormProvider({children}) {
12
- const modal = useModal()
11
+ export default function LoginFormProvider({ children }) {
12
+ const modal = useModal()
13
13
 
14
- const onLogin = () => {
15
- modal({
16
- title: 'Developer Login',
17
- content({close}) {
18
- return <LoginForm />
19
- },
20
- })
21
- }
14
+ const onLogin = () => {
15
+ modal({
16
+ title: 'Developer Login',
17
+ content({ close }) {
18
+ return <LoginForm />
19
+ },
20
+ })
21
+ }
22
22
 
23
- return (
24
- <LoginContext.Provider
25
- value={{
26
- openLoginForm: onLogin,
27
- }}
28
- >
29
- {children}
30
- </LoginContext.Provider>
31
- )
23
+ return (
24
+ <LoginContext.Provider
25
+ value={{
26
+ openLoginForm: onLogin,
27
+ }}
28
+ >
29
+ {children}
30
+ </LoginContext.Provider>
31
+ )
32
32
  }
33
33
 
34
34
  export const useLoginForm = () => {
35
- const context = useContext(LoginContext)
36
- return {
37
- openLoginForm: context.openLoginForm,
38
- }
35
+ const context = useContext(LoginContext)
36
+ return {
37
+ openLoginForm: context.openLoginForm,
38
+ }
39
39
  }
@@ -1,57 +1,57 @@
1
1
  import MuiThemeProvider from '../theme/MuiThemeProvider'
2
2
  import ConfirmContextProvider from '../components/PopupConfirm/ConfirmContextProvider'
3
- import {CssBaseline} from '@mui/material'
4
- import {BrowserRouter} from 'react-router-dom'
3
+ import { CssBaseline } from '@mui/material'
4
+ import { BrowserRouter } from 'react-router-dom'
5
5
  import QueryClientProvider from './QueryClientProvider'
6
6
 
7
7
  import DialogProvider from '../components/DrawerWrapper/DrawerWrapper'
8
- import {ToastContainer} from '../components'
8
+ import { ToastContainer } from '../components'
9
9
  import LoginFormProvider from './LoginFormProvider'
10
- import {ReactNode} from 'react'
11
- import {isDevelopment} from '../constants'
10
+ import { ReactNode } from 'react'
11
+ import { isDevelopment } from '../constants'
12
12
  import useAppInit from '../hooks/useAppInit'
13
13
  import Cookies from 'js-cookie'
14
14
 
15
15
  export const campxTenantKey = Cookies.get('campx_tenant')
16
16
  export const urlTenantKey = window.location.pathname.split('/')[1]
17
17
 
18
- export default function Providers({children}: {children: ReactNode}) {
19
- const {isInvalid} = useAppInit()
18
+ export default function Providers({ children }: { children: ReactNode }) {
19
+ const { isInvalid } = useAppInit()
20
20
 
21
- return (
22
- <BrowserRouter basename={isDevelopment ? 'campx_dev' : campxTenantKey}>
23
- <QueryClientProvider>
24
- <MuiThemeProvider>
25
- <DialogProvider>
26
- <LoginFormProvider>
27
- <ConfirmContextProvider>{children}</ConfirmContextProvider>
28
- <CssBaseline />
29
- </LoginFormProvider>
30
- <ToastContainer />
31
- </DialogProvider>
32
- </MuiThemeProvider>
33
- </QueryClientProvider>
34
- </BrowserRouter>
35
- )
21
+ return (
22
+ <BrowserRouter basename={isDevelopment ? 'campx_dev' : campxTenantKey}>
23
+ <QueryClientProvider>
24
+ <MuiThemeProvider>
25
+ <DialogProvider>
26
+ <LoginFormProvider>
27
+ <ConfirmContextProvider>{children}</ConfirmContextProvider>
28
+ <CssBaseline />
29
+ </LoginFormProvider>
30
+ <ToastContainer />
31
+ </DialogProvider>
32
+ </MuiThemeProvider>
33
+ </QueryClientProvider>
34
+ </BrowserRouter>
35
+ )
36
36
  }
37
37
 
38
38
  const InvalidClientKey = () => {
39
- return (
40
- <div
41
- style={{
42
- height: '95vh',
43
- width: '95vw',
44
- display: 'grid',
45
- placeItems: 'center',
46
- fontFamily: 'sans-serif',
47
- }}
48
- >
49
- <h1>Invalid Tenant Key</h1>
50
- {!isDevelopment && (
51
- <a href='https://id.campx.in'>
52
- <p>Login to continue</p>
53
- </a>
54
- )}
55
- </div>
56
- )
39
+ return (
40
+ <div
41
+ style={{
42
+ height: '95vh',
43
+ width: '95vw',
44
+ display: 'grid',
45
+ placeItems: 'center',
46
+ fontFamily: 'sans-serif',
47
+ }}
48
+ >
49
+ <h1>Invalid Tenant Key</h1>
50
+ {!isDevelopment && (
51
+ <a href="https://id.campx.in">
52
+ <p>Login to continue</p>
53
+ </a>
54
+ )}
55
+ </div>
56
+ )
57
57
  }
@@ -1,22 +1,22 @@
1
1
  import {
2
- QueryClient,
3
- QueryClientProvider as ReactQueryClientProvider,
2
+ QueryClient,
3
+ QueryClientProvider as ReactQueryClientProvider,
4
4
  } from 'react-query'
5
5
 
6
6
  export const queryClient = new QueryClient({
7
- defaultOptions: {
8
- queries: {
9
- refetchOnWindowFocus: false,
10
- retry: false,
11
- useErrorBoundary: true,
12
- },
13
- },
7
+ defaultOptions: {
8
+ queries: {
9
+ refetchOnWindowFocus: false,
10
+ retry: false,
11
+ useErrorBoundary: true,
12
+ },
13
+ },
14
14
  })
15
15
 
16
- export default function QueryClientProvider({children}) {
17
- return (
18
- <ReactQueryClientProvider client={queryClient}>
19
- {children}
20
- </ReactQueryClientProvider>
21
- )
16
+ export default function QueryClientProvider({ children }) {
17
+ return (
18
+ <ReactQueryClientProvider client={queryClient}>
19
+ {children}
20
+ </ReactQueryClientProvider>
21
+ )
22
22
  }
@@ -1,3 +1,3 @@
1
- export {default as useFetch} from './useFetch'
1
+ export { default as useFetch } from './useFetch'
2
2
  export * from './useRouter'
3
- export {default as useAuth} from './useAuth'
3
+ export { default as useAuth } from './useAuth'
@@ -1,33 +1,33 @@
1
1
  import Cookies from 'js-cookie'
2
- import {useEffect, useState} from 'react'
3
- import {isDevelopment} from '../constants'
4
- import {campxTenantKey} from '../contexts/Providers'
2
+ import { useEffect, useState } from 'react'
3
+ import { isDevelopment } from '../constants'
4
+ import { campxTenantKey } from '../contexts/Providers'
5
5
 
6
6
  const urlTenantKey = window.location.pathname.split('/')[1]
7
7
 
8
8
  export default function useAppInit() {
9
- const [isInvalid, setIsInvalid] = useState(false)
9
+ const [isInvalid, setIsInvalid] = useState(false)
10
10
 
11
- useEffect(() => {
12
- if (!isDevelopment) {
13
- if (!campxTenantKey) {
14
- return window.location.replace('https://id.campx.in')
15
- }
11
+ useEffect(() => {
12
+ if (!isDevelopment) {
13
+ if (!campxTenantKey) {
14
+ return window.location.replace('https://id.campx.in')
15
+ }
16
16
 
17
- if (!urlTenantKey) {
18
- return window.location.replace(
19
- window.location.origin + `/${campxTenantKey}`
20
- )
21
- }
22
- }
17
+ if (!urlTenantKey) {
18
+ return window.location.replace(
19
+ window.location.origin + `/${campxTenantKey}`,
20
+ )
21
+ }
22
+ }
23
23
 
24
- if (window.location.pathname === '/' && isDevelopment) {
25
- Cookies.set('campx_tenant', 'campx_dev')
26
- window.location.href = window.location.origin + '/campx_dev'
27
- }
28
- }, [])
24
+ if (window.location.pathname === '/' && isDevelopment) {
25
+ Cookies.set('campx_tenant', 'campx_dev')
26
+ window.location.href = window.location.origin + '/campx_dev'
27
+ }
28
+ }, [])
29
29
 
30
- return {
31
- isInvalid,
32
- }
30
+ return {
31
+ isInvalid,
32
+ }
33
33
  }
@@ -1,90 +1,91 @@
1
- import {useEffect, useState} from 'react'
2
- import {useQuery} from 'react-query'
3
- import {toast} from 'react-toastify'
1
+ import { useEffect, useState } from 'react'
2
+ import { useQuery } from 'react-query'
3
+ import { toast } from 'react-toastify'
4
4
  import axios from '../config/axios'
5
- import {isDevelopment} from '../constants'
6
- import {useLoginForm} from '../contexts/LoginFormProvider'
7
- import {PermissionsStore} from '../permissions'
8
- import {AssetsStore, UserStore} from '../shared-state'
5
+ import { isDevelopment } from '../constants'
6
+ import { useLoginForm } from '../contexts/LoginFormProvider'
7
+ import { PermissionsStore } from '../permissions'
8
+ import { AssetsStore, UserStore } from '../shared-state'
9
9
 
10
10
  const url = window.location.origin
11
11
 
12
12
  function useAuth(): {
13
- loading: boolean
14
- data: {
15
- user?: any
16
- roles?: any
17
- username?: any
18
- permissions?: any
19
- assets?: {
20
- logo: string
21
- logo_square: string
22
- }
23
- }
13
+ loading: boolean
14
+ data: {
15
+ user?: any
16
+ roles?: any
17
+ username?: any
18
+ permissions?: any
19
+ assets?: {
20
+ logo: string
21
+ logo_square: string
22
+ }
23
+ }
24
24
  } {
25
- const {openLoginForm} = useLoginForm()
26
- const [loading, setLoading] = useState<boolean>(false)
27
- const [data, setData] = useState(null)
28
- const appInit = async () => {
29
- setLoading(true)
25
+ const { openLoginForm } = useLoginForm()
26
+ const [loading, setLoading] = useState<boolean>(false)
27
+ const [data, setData] = useState(null)
28
+ const appInit = async () => {
29
+ setLoading(true)
30
30
 
31
- axios
32
- .get('/auth/my-permissions')
33
- .then((res) => {
34
- console.log(res.data)
35
- setLoading(false)
36
- setData(res.data)
37
- UserStore.update((s) => {
38
- s.username = res.data?.username
39
- s.user = res.data?.user
40
- s.roles = res.data?.roles
41
- })
31
+ axios
32
+ .get('/auth/my-permissions')
33
+ .then((res) => {
34
+ console.log(res.data)
35
+ setLoading(false)
36
+ setData(res.data)
37
+ UserStore.update((s) => {
38
+ s.username = res.data?.username
39
+ s.user = res.data?.user
40
+ s.roles = res.data?.roles
41
+ })
42
42
 
43
- PermissionsStore.update((s) => {
44
- s.permissions = {
45
- ...res.data?.permissions,
46
- can_settings_view: 1,
47
- can_dashboard_view: 1,
48
- can_individual_pages_view: 1,
49
- } as any
50
- })
51
- AssetsStore.update((s) => {
52
- s.logo = res.data?.assets.logo
53
- s.logo_square = res.data?.assets.logo_square
54
- })
55
- })
56
- .catch((err) => {
57
- setLoading(false)
58
- if (err.response.status !== 401) {
59
- if (err.response.status > 400 && err.response.status < 500) {
60
- window.location.replace(
61
- `https://www.id.campx.in/?redirect_to=${url}`
62
- )
63
- } else {
64
- toast.error('Server Error')
65
- }
66
- }
67
- if (isDevelopment) {
68
- openLoginForm()
69
- } else {
70
- window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
71
- }
72
- })
73
- }
43
+ PermissionsStore.update((s) => {
44
+ s.permissions = {
45
+ ...res.data?.permissions,
46
+ can_settings_view: 1,
47
+ can_dashboard_view: 1,
48
+ can_individual_pages_view: 1,
49
+ } as any
50
+ })
51
+ AssetsStore.update((s) => {
52
+ s.logo = res.data?.assets.logo
53
+ s.logo_square = res.data?.assets.logo_square
54
+ })
55
+ })
56
+ .catch((err) => {
57
+ setLoading(false)
58
+ if (isDevelopment) {
59
+ openLoginForm()
60
+ return
61
+ } else {
62
+ window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
63
+ }
64
+ if (err.response.status !== 401) {
65
+ if (err.response.status > 400 && err.response.status < 500) {
66
+ window.location.replace(
67
+ `https://www.id.campx.in/?redirect_to=${url}`,
68
+ )
69
+ } else {
70
+ toast.error('Server Error')
71
+ }
72
+ }
73
+ })
74
+ }
74
75
 
75
- useEffect(() => {
76
- if (window.location.pathname === '/') {
77
- if (isDevelopment) {
78
- window.location.replace(window.location.origin + '/campx_dev')
79
- }
80
- }
81
- appInit()
82
- }, [])
76
+ useEffect(() => {
77
+ if (window.location.pathname === '/') {
78
+ if (isDevelopment) {
79
+ window.location.replace(window.location.origin + '/campx_dev')
80
+ }
81
+ }
82
+ appInit()
83
+ }, [])
83
84
 
84
- return {
85
- loading: loading || !data?.permissions,
86
- data,
87
- }
85
+ return {
86
+ loading: loading || !data?.permissions,
87
+ data,
88
+ }
88
89
  }
89
90
 
90
91
  export default useAuth