@campxdev/shared 0.2.15 → 0.3.1

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 (42) hide show
  1. package/exports.ts +6 -7
  2. package/package.json +2 -1
  3. package/src/assets/images/avatar.png +0 -0
  4. package/src/assets/images/index.ts +1 -19
  5. package/src/components/ErrorBoundary/ErrorBoundary.tsx +15 -0
  6. package/src/components/ErrorBoundary/ErrorFallback.tsx +39 -0
  7. package/src/components/ErrorBoundary/GlobalNetworkLoadingIndicator.tsx +13 -0
  8. package/src/components/ErrorBoundary/index.tsx +1 -0
  9. package/src/components/Layout/Header/CogWheelMenu.tsx +7 -0
  10. package/src/components/Layout/Header/UserBox.tsx +17 -47
  11. package/src/components/Layout/Header/styles.tsx +2 -3
  12. package/src/components/LinearProgress.tsx +19 -0
  13. package/src/components/MenuButton.tsx +88 -90
  14. package/src/components/Spinner.tsx +14 -14
  15. package/src/components/index.ts +45 -43
  16. package/src/config/axios.ts +13 -80
  17. package/src/constants/index.ts +1 -0
  18. package/src/contexts/QueryClientProvider.tsx +15 -15
  19. package/src/permissions/PageWithPermission.tsx +0 -39
  20. package/src/permissions/PermissionDeniedPage.tsx +14 -21
  21. package/src/shared-state/index.ts +1 -2
  22. package/src/theme/MuiThemeProvider.tsx +10 -8
  23. package/src/theme/theme.d.ts +72 -72
  24. package/src/utils/withRouteWrapper.tsx +21 -20
  25. package/src/utils/withSuspense.tsx +3 -3
  26. package/src/assets/images/File bundle-bro.svg +0 -122
  27. package/src/assets/images/Filebundle.png +0 -0
  28. package/src/assets/images/NoPart.png +0 -0
  29. package/src/assets/images/ResultProcess.png +0 -0
  30. package/src/assets/images/ResultProcess.svg +0 -99
  31. package/src/assets/images/attachment.svg +0 -1
  32. package/src/assets/images/pdf.png +0 -0
  33. package/src/assets/images/taskAttachment.png +0 -0
  34. package/src/assets/images/welcomeimage.jpg +0 -0
  35. package/src/components/ErrorBoundary.js +0 -45
  36. package/src/components/LinearProgress/LinearProgress.tsx +0 -28
  37. package/src/components/LinearProgress/index.tsx +0 -1
  38. package/src/pages/LoginPage/LoginPage.tsx +0 -168
  39. package/src/pages/LoginPage/index.ts +0 -1
  40. package/src/pages/LoginPage/styles.tsx +0 -121
  41. package/src/pages/index.ts +0 -4
  42. package/src/shared-state/GlobalStore.ts +0 -10
@@ -1,8 +1,8 @@
1
1
  import Axios from 'axios'
2
2
  import _ from 'lodash'
3
3
  import {toast} from 'react-toastify'
4
- import {globalStore} from '../shared-state/GlobalStore'
5
4
  import Cookies from 'js-cookie'
5
+ import {NetworkStore} from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
6
6
 
7
7
  const isDevelopment =
8
8
  process.env.NODE_ENV === 'development' ||
@@ -31,49 +31,30 @@ let axios = Axios.create({
31
31
  axios.interceptors.request.use(
32
32
  function (config) {
33
33
  const params = formatParams(config?.params)
34
- // globalStore.update((s) => {
35
- // s.loading = true
36
- // s.error.message = ''
37
- // s.error.statusCode = null
38
- // s.error.description = ''
39
- // })
34
+ NetworkStore.update((s) => {
35
+ s.loading = true
36
+ })
40
37
  return {...config, params}
41
38
  },
42
39
  function (error) {
43
- // globalStore.update((s) => {
44
- // s.loading = true
45
- // })
40
+ NetworkStore.update((s) => {
41
+ s.loading = false
42
+ })
46
43
  return Promise.reject(error)
47
44
  }
48
45
  )
49
46
 
50
47
  axios.interceptors.response.use(
51
48
  function (response) {
52
- // globalStore.update((s) => {
53
- // s.loading = false
54
- // })
49
+ NetworkStore.update((s) => {
50
+ s.loading = false
51
+ })
55
52
  return response
56
53
  },
57
54
  function (err) {
58
- // globalStore.update((s) => {
59
- // s.loading = false
60
- // })
61
-
62
- // if (err.message == 'Network Error') {
63
- // // globalStore.update((s) => {
64
- // // s.error = {
65
- // // message: err.message,
66
- // // statusCode: 999,
67
- // // description: 'Please check your network connection',
68
- // // }
69
- // // })
70
- // } else {
71
- // // const method = err.response.config.method
72
- // // if (method === 'get' || method === 'GET') {
73
- // // // setError(err.response.status, err.response.data.message)
74
- // // }
75
- // }
76
-
55
+ NetworkStore.update((s) => {
56
+ s.loading = false
57
+ })
77
58
  return Promise.reject(err)
78
59
  }
79
60
  )
@@ -89,51 +70,3 @@ export const axiosErrorToast = (error: any, fallback?: string) => {
89
70
 
90
71
  return toast.error(errorMessage)
91
72
  }
92
-
93
- const setError = (statusCode: number, message: string) => {
94
- switch (statusCode) {
95
- case 401:
96
- localStorage.removeItem('token')
97
- globalStore.update((s) => {
98
- s.error.message = message ?? 'Session Expired!'
99
- s.error.statusCode = statusCode
100
- s.error.description =
101
- 'Your session has been expired, Please login to continue'
102
- })
103
- break
104
- case 404:
105
- // globalStore.update((s) => {
106
- // s.error.message = message ?? 'Not Found!'
107
- // s.error.statusCode = statusCode
108
- // s.error.description =
109
- // 'The resource you are trying to access is not found.'
110
- // })
111
- toast.error('The resource you are trying to access is not found.')
112
-
113
- break
114
- case 403:
115
- globalStore.update((s) => {
116
- s.error.message = message ?? 'Forbidden!'
117
- s.error.statusCode = statusCode
118
- s.error.description =
119
- 'The resource you are trying to access is forbidden.'
120
- })
121
- break
122
-
123
- case 400:
124
- case 422:
125
- globalStore.update((s) => {
126
- s.error.message = ''
127
- s.error.description = ''
128
- s.error.statusCode = null
129
- })
130
- break
131
-
132
- default:
133
- globalStore.update((s) => {
134
- s.error.message = 'Unknown Network Error!'
135
- s.error.statusCode = 999
136
- s.error.description = 'Unknown network error occurred!'
137
- })
138
- }
139
- }
@@ -2,3 +2,4 @@ export * from './UIConstants'
2
2
  export * from './formValidations'
3
3
  export * from './permissions'
4
4
  export * from './validateMessages'
5
+ export * from './isDevelopment'
@@ -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: (error: AxiosError) => error.response?.status >= 400,
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,57 +1,18 @@
1
1
  import PermissionDeniedPage from './PermissionDeniedPage'
2
2
  import {PermissionsStore} from './PermissionsStore'
3
- import React, {ReactNode, useEffect} from 'react'
4
- import {globalStore} from '../shared-state/GlobalStore'
5
- import {Box, Typography} from '@mui/material'
6
- import {useHistory} from '../hooks/useRouter'
7
3
 
8
4
  const accessIfNoKey = process.env.NODE_ENV === 'development' ? true : false
9
5
 
10
6
  export default function PageWithPermission({
11
7
  permissionKey,
12
- component: Component,
13
8
  children,
14
- ...props
15
9
  }: {
16
10
  permissionKey: string
17
- component?: any
18
11
  children?: any
19
12
  }) {
20
- // const history = useHistory()
21
- // const errorState = globalStore.useState((s) => s.error)
22
-
23
13
  const permissions = PermissionsStore.useState((s) => s).permissions
24
14
  const hasAccess = permissionKey ? permissions[permissionKey] : accessIfNoKey
25
15
 
26
- // useEffect(() => {
27
- // globalStore.update((s) => {
28
- // s.error = {
29
- // message: '',
30
- // statusCode: null,
31
- // description: '',
32
- // }
33
- // })
34
- // }, [history])
35
-
36
- // if (errorState.statusCode) return <ErrorPage />
37
- // if (hasAccess) return Component
38
16
  if (hasAccess) return children
39
17
  return <PermissionDeniedPage />
40
18
  }
41
-
42
- const ErrorPage = () => {
43
- const globalState = globalStore.useState((s) => s).error
44
- return (
45
- <Box
46
- sx={{
47
- display: 'flex',
48
- alignItems: 'center',
49
- justifyContent: 'center',
50
- }}
51
- >
52
- <Typography variant='h1' marginTop={'100px'}>
53
- {globalState.description}
54
- </Typography>
55
- </Box>
56
- )
57
- }
@@ -1,23 +1,16 @@
1
- import { Typography } from '@mui/material'
2
- import React from 'react'
3
- import { Link } from 'react-router-dom'
4
- import styled from 'styled-components'
1
+ import {Box, Typography} from '@mui/material'
2
+
5
3
  export default function PermissionDeniedPage() {
6
- return (
7
- <StyledPageContainer>
8
- <div>
9
- <Typography>Permission Denied</Typography>
10
- {/* <Link to={'/'}>Go Back</Link> */}
11
- </div>
12
- </StyledPageContainer>
13
- )
4
+ return (
5
+ <Box
6
+ sx={{
7
+ height: '100vh',
8
+ width: '100%',
9
+ display: 'grid',
10
+ placeItems: 'center',
11
+ }}
12
+ >
13
+ <Typography variant='h6'>Permission Denied</Typography>
14
+ </Box>
15
+ )
14
16
  }
15
-
16
- const StyledPageContainer = styled.div`
17
- height: 100vh;
18
- width: 100%;
19
- center: #233659;
20
- display: flex;
21
- justify-content: center;
22
- align-items: center;
23
- `
@@ -1,4 +1,3 @@
1
1
  import {AssetsStore} from './AssetsStore'
2
2
  import {UserStore} from './UserStore'
3
- import {globalStore} from './GlobalStore'
4
- export {AssetsStore, UserStore, globalStore as GlobalStore}
3
+ export {AssetsStore, UserStore}
@@ -1,11 +1,13 @@
1
- import { CssBaseline, ThemeProvider } from '@mui/material'
1
+ import {CssBaseline, ThemeProvider} from '@mui/material'
2
+ import GlobalNetworkLoadingIndicator from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
2
3
  import muiTheme from './muiTheme'
3
4
 
4
- export default function MuiThemeProvider({ children }) {
5
- return (
6
- <ThemeProvider theme={muiTheme}>
7
- {children}
8
- <CssBaseline />
9
- </ThemeProvider>
10
- )
5
+ export default function MuiThemeProvider({children}) {
6
+ return (
7
+ <ThemeProvider theme={muiTheme}>
8
+ {children}
9
+ <CssBaseline />
10
+ <GlobalNetworkLoadingIndicator />
11
+ </ThemeProvider>
12
+ )
11
13
  }
@@ -1,75 +1,75 @@
1
- import { ThemeOptions as MuiThemeOptions } from '@mui/material/styles'
1
+ import {ThemeOptions as MuiThemeOptions} from '@mui/material/styles'
2
2
 
3
3
  declare module '@mui/material/styles' {
4
- interface Theme {
5
- borders: {
6
- grayLight: string
7
- primary: string
8
- }
9
- palette: {
10
- primary: {
11
- dark: string
12
- main: string
13
- light: string
14
- lighter: string
15
- }
16
- secondary: {
17
- main: string
18
- light: string
19
- dark: string
20
- lighter: string
21
- }
22
- common: {
23
- black: string
24
- white: string
25
- green: string
26
- yellow: string
27
- blue: string
28
- }
29
- error: {
30
- main: string
31
- }
32
- text: {
33
- primary: string
34
- secondary: string
35
- disabled: string
36
- }
37
- }
38
- }
39
- // allow configuration using `createTheme`
40
- interface CustomThemeOptions extends MuiThemeOptions {
41
- borders?: {
42
- grayLight?: string
43
- }
44
- palette: {
45
- secondary?: {
46
- main?: string
47
- light?: string
48
- dark?: string
49
- lighter?: string
50
- }
51
- primary?: {
52
- dark?: string
53
- main?: string
54
- light?: string
55
- lighter?: string
56
- }
57
- common?: {
58
- black?: string
59
- white?: string
60
- green?: string
61
- yellow?: string
62
- blue?: string
63
- }
64
- error?: {
65
- main?: string
66
- }
67
- text?: {
68
- primary?: string
69
- secondary?: string
70
- disabled?: string
71
- }
72
- }
73
- }
74
- export function createTheme(options?: CustomThemeOptions): CustomTheme
4
+ interface Theme {
5
+ borders: {
6
+ grayLight: string
7
+ primary: string
8
+ }
9
+ palette: {
10
+ primary: {
11
+ dark: string
12
+ main: string
13
+ light: string
14
+ lighter: string
15
+ }
16
+ secondary: {
17
+ main: string
18
+ light: string
19
+ dark: string
20
+ lighter: string
21
+ }
22
+ common: {
23
+ black: string
24
+ white: string
25
+ green: string
26
+ yellow: string
27
+ blue: string
28
+ }
29
+ error: {
30
+ main: string
31
+ }
32
+ text: {
33
+ primary: string
34
+ secondary: string
35
+ disabled: string
36
+ }
37
+ }
38
+ }
39
+ // allow configuration using `createTheme`
40
+ interface CustomThemeOptions extends MuiThemeOptions {
41
+ borders?: {
42
+ grayLight?: string
43
+ }
44
+ palette: {
45
+ secondary?: {
46
+ main?: string
47
+ light?: string
48
+ dark?: string
49
+ lighter?: string
50
+ }
51
+ primary?: {
52
+ dark?: string
53
+ main?: string
54
+ light?: string
55
+ lighter?: string
56
+ }
57
+ common?: {
58
+ black?: string
59
+ white?: string
60
+ green?: string
61
+ yellow?: string
62
+ blue?: string
63
+ }
64
+ error?: {
65
+ main?: string
66
+ }
67
+ text?: {
68
+ primary?: string
69
+ secondary?: string
70
+ disabled?: string
71
+ }
72
+ }
73
+ }
74
+ export function createTheme(options?: CustomThemeOptions): CustomTheme
75
75
  }
@@ -1,25 +1,26 @@
1
- import { Spinner } from '../components'
2
- import { Suspense } from 'react'
1
+ import {Spinner} from '../components'
2
+ import {Suspense} from 'react'
3
3
  import PageWithPermission from '../permissions/PageWithPermission'
4
+ import {LinearProgress} from '../components/LinearProgress'
4
5
 
5
6
  const withRouteWrapper = (routes) => {
6
- return routes?.map((item, index) => {
7
- if (item?.children) {
8
- return {
9
- ...item,
10
- children: withRouteWrapper(item.children),
11
- }
12
- }
13
- return {
14
- ...item,
15
- element: item?.element ? (
16
- <Suspense fallback={<Spinner />} key={index}>
17
- <PageWithPermission permissionKey={item?.permissionKey}>
18
- {item.element}
19
- </PageWithPermission>
20
- </Suspense>
21
- ) : undefined,
22
- }
23
- })
7
+ return routes?.map((item, index) => {
8
+ if (item?.children) {
9
+ return {
10
+ ...item,
11
+ children: withRouteWrapper(item.children),
12
+ }
13
+ }
14
+ return {
15
+ ...item,
16
+ element: item?.element ? (
17
+ <Suspense fallback={<LinearProgress />} key={index}>
18
+ <PageWithPermission permissionKey={item?.permissionKey}>
19
+ {item.element}
20
+ </PageWithPermission>
21
+ </Suspense>
22
+ ) : undefined,
23
+ }
24
+ })
24
25
  }
25
26
  export default withRouteWrapper
@@ -1,6 +1,6 @@
1
- import { Spinner } from '../components'
2
- import { ReactNode, Suspense } from 'react'
1
+ import {LinearProgress, Spinner} from '../components'
2
+ import {ReactNode, Suspense} from 'react'
3
3
 
4
4
  export default function withSuspense(component: ReactNode) {
5
- return <Suspense fallback={<Spinner />}>{component}</Suspense>
5
+ return <Suspense fallback={<LinearProgress />}>{component}</Suspense>
6
6
  }