@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
package/exports.ts CHANGED
@@ -1,16 +1,15 @@
1
1
  export * from './src/components'
2
2
  export * from './src/constants'
3
- export { default as axios, axiosErrorToast } from './src/config/axios'
3
+ export {default as axios, axiosErrorToast} from './src/config/axios'
4
4
 
5
5
  export * from './src/permissions'
6
6
  export * from './src/utils'
7
7
  export * from './src/hooks'
8
- export * from './src/pages'
9
- export { useModal } from './src/components/DrawerWrapper/DrawerWrapper'
10
- export { default as MuiThemeProvider } from './src/theme/MuiThemeProvider'
11
- export { default as ConfirmContextProvider } from './src/components/PopupConfirm/ConfirmContextProvider'
12
- export { default as DialogProvider } from './src/components/DrawerWrapper/DrawerWrapper'
13
- export { default as Providers } from './src/contexts/Providers'
8
+ export {useModal} from './src/components/DrawerWrapper/DrawerWrapper'
9
+ export {default as MuiThemeProvider} from './src/theme/MuiThemeProvider'
10
+ export {default as ConfirmContextProvider} from './src/components/PopupConfirm/ConfirmContextProvider'
11
+ export {default as DialogProvider} from './src/components/DrawerWrapper/DrawerWrapper'
12
+ export {default as Providers} from './src/contexts/Providers'
14
13
 
15
14
  export * from './src/shared-state'
16
15
  export * from './src/assets/images'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "0.2.15",
3
+ "version": "0.3.1",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -35,6 +35,7 @@
35
35
  "pullstate": "^1.24.0",
36
36
  "react": "^18.2.0",
37
37
  "react-dom": "^18.2.0",
38
+ "react-error-boundary": "^3.1.4",
38
39
  "react-hook-form": "^7.31.1",
39
40
  "react-query": "^3.39.0",
40
41
  "react-router-dom": "^6.4.2",
Binary file
@@ -1,21 +1,3 @@
1
- const attachmentImage = require('./attachment.svg')
2
1
  const avatarImage = require('./avatar.png')
3
- const welcomeImage = require('./welcomeimage.jpg')
4
- const taskAttachmentImage = require('./taskAttachment.png')
5
- const pdfImage = require('./pdf.png')
6
- const NoPart = require('./NoPart.png')
7
- const FileBundleImage = require('./Filebundle.png')
8
- const resultProcessingImage = require('./ResultProcess.png')
9
2
  const campxLogoPrimary = require('./campx_logo__full_primary.png')
10
-
11
- export {
12
- attachmentImage,
13
- avatarImage,
14
- welcomeImage,
15
- taskAttachmentImage,
16
- pdfImage,
17
- NoPart,
18
- resultProcessingImage,
19
- FileBundleImage,
20
- campxLogoPrimary,
21
- }
3
+ export {avatarImage, campxLogoPrimary}
@@ -0,0 +1,15 @@
1
+ import {ErrorBoundary as ReactErrorBoundary} from 'react-error-boundary'
2
+ import {QueryErrorResetBoundary} from 'react-query'
3
+ import ErrorFallback from './ErrorFallback'
4
+
5
+ export default function ErrorBoundary({children}) {
6
+ return (
7
+ <QueryErrorResetBoundary>
8
+ {({reset}) => (
9
+ <ReactErrorBoundary fallbackRender={ErrorFallback} onReset={reset}>
10
+ {children}
11
+ </ReactErrorBoundary>
12
+ )}
13
+ </QueryErrorResetBoundary>
14
+ )
15
+ }
@@ -0,0 +1,39 @@
1
+ import {Alert, Box, Button, styled, Typography} from '@mui/material'
2
+
3
+ const StyledAlert = styled(Alert)(({theme}) => ({
4
+ border: `1px solid ${theme.palette.error.main}`,
5
+ display: 'flex',
6
+ alignItems: 'center',
7
+ '& .MuiAlert-message': {
8
+ padding: 0,
9
+ },
10
+ '& .MuiTypography-root': {
11
+ margin: 0,
12
+ },
13
+ position: 'relative',
14
+ '& .retryBtn': {
15
+ color: '#661b2a',
16
+ position: 'absolute',
17
+ right: 8,
18
+ top: 8,
19
+ },
20
+ }))
21
+
22
+ export default function ErrorFallback({error, resetErrorBoundary}) {
23
+ return (
24
+ <Box sx={{padding: '16px'}}>
25
+ <StyledAlert severity='error'>
26
+ {error?.message}
27
+ <Button
28
+ className='retryBtn'
29
+ onClick={() => resetErrorBoundary()}
30
+ size='small'
31
+ color='error'
32
+ variant='outlined'
33
+ >
34
+ Try Again
35
+ </Button>
36
+ </StyledAlert>
37
+ </Box>
38
+ )
39
+ }
@@ -0,0 +1,13 @@
1
+ import {Store} from 'pullstate'
2
+ import {LinearProgress} from '../LinearProgress'
3
+
4
+ export const NetworkStore = new Store({
5
+ loading: false,
6
+ })
7
+
8
+ export default function GlobalNetworkLoadingIndicator() {
9
+ const {loading} = NetworkStore.useState()
10
+
11
+ if (loading) return <LinearProgress />
12
+ if (loading) return null
13
+ }
@@ -0,0 +1 @@
1
+ export {default} from './ErrorBoundary'
@@ -19,6 +19,13 @@ const CogWheelMenu = ({menu}) => {
19
19
  history.push(item?.path)
20
20
  },
21
21
  }))}
22
+ menuProps={{
23
+ PaperProps: {sx: {top: '64px !important'}},
24
+ transformOrigin: {
25
+ horizontal: 'center',
26
+ vertical: 'bottom',
27
+ },
28
+ }}
22
29
  />
23
30
  )
24
31
  }
@@ -1,18 +1,8 @@
1
- import {
2
- ExitToAppOutlined,
3
- HttpsOutlined,
4
- PermIdentityOutlined,
5
- } from '@mui/icons-material'
6
- import {Avatar, Box, CircularProgress, Typography} from '@mui/material'
7
- import {useHistory} from '../../../hooks/useRouter'
1
+ import {Box, Typography} from '@mui/material'
2
+ import {ReactNode} from 'react'
8
3
  import {avatarImage} from '../../../assets/images'
9
4
  import MenuButton from '../../MenuButton'
10
5
  import {StyledUser} from './styles'
11
- import axios from 'axios'
12
- import {axiosErrorToast} from '../../../config/axios'
13
- import {isDevelopment} from '../../../constants/isDevelopment'
14
- import Cookies from 'js-cookie'
15
- import {ReactNode, useState} from 'react'
16
6
 
17
7
  export default function UserBox({
18
8
  username,
@@ -23,50 +13,30 @@ export default function UserBox({
23
13
  profileIcon: string
24
14
  actions: {label: ReactNode; icon?: ReactNode; onClick: any}[]
25
15
  }) {
26
- const history = useHistory()
27
- const [posting, setPosting] = useState(false)
28
-
29
- async function logout() {
30
- if (isDevelopment) {
31
- Cookies.remove('campx_session_key')
32
- window.location.href = '/'
33
- return
34
- }
35
-
36
- setPosting(true)
37
- axios({
38
- method: 'POST',
39
- baseURL: process.env.REACT_APP_AUTH_HOST,
40
- url: '/auth/logout',
41
- })
42
- .then((res) => {
43
- window.location.href = '/'
44
- })
45
- .catch((err) => {
46
- axiosErrorToast('Unable To Logout.')
47
- })
48
- }
49
-
50
16
  return (
51
17
  <MenuButton
52
18
  anchor={
53
19
  <Box minWidth={'80px'} textAlign='center'>
54
- {!posting ? (
55
- <StyledUser>
56
- <Avatar src={profileIcon ?? avatarImage} />
57
- <Typography variant='h6'>{username}</Typography>
58
- </StyledUser>
59
- ) : (
60
- <CircularProgress
61
- size={16}
62
- sx={{
63
- color: ({palette}) => palette.primary.main,
20
+ <StyledUser>
21
+ <img
22
+ src={profileIcon ?? avatarImage}
23
+ style={{
24
+ height: '32px',
25
+ width: '32px',
26
+ objectFit: 'contain',
27
+ }}
28
+ onError={(e: any) => {
29
+ e.target.src = avatarImage
64
30
  }}
65
31
  />
66
- )}
32
+ <Typography variant='h6'>{username}</Typography>
33
+ </StyledUser>
67
34
  </Box>
68
35
  }
69
36
  menu={actions}
37
+ menuProps={{
38
+ PaperProps: {sx: {top: '64px !important'}},
39
+ }}
70
40
  />
71
41
  )
72
42
  }
@@ -29,7 +29,6 @@ export const StyledAppBar = styled(AppBar)(({theme}) => ({
29
29
 
30
30
  export const StyledHeader = styled(Box)(({theme}) => ({
31
31
  boxShadow: '0px 2px 10px #0000001a',
32
- // padding: '0 1rem',
33
32
  backgroundColor: 'white',
34
33
  display: 'flex',
35
34
  alignItems: 'center',
@@ -46,10 +45,10 @@ export const StyledUser = styled(Box)(({theme}) => ({
46
45
  cursor: 'pointer',
47
46
  borderRadius: '5px',
48
47
  transition: 'background 0.2s ease',
49
- padding: '5px 10px',
48
+ padding: '5px 16px',
50
49
  display: 'flex',
51
50
  alignItems: 'center',
52
- gap: '10px',
51
+ gap: '8px',
53
52
  '&:hover': {
54
53
  background: theme.palette.secondary.light,
55
54
  },
@@ -0,0 +1,19 @@
1
+ import {
2
+ BoxProps,
3
+ styled,
4
+ Box,
5
+ LinearProgress as MuiLinearProgress,
6
+ } from '@mui/material'
7
+
8
+ export const LinearProgress = styled((props: BoxProps) => (
9
+ <Box {...props}>
10
+ <MuiLinearProgress color={'inherit'} sx={{height: '4px'}} />
11
+ </Box>
12
+ ))(({theme}) => ({
13
+ width: '100%',
14
+ position: 'fixed',
15
+ top: 0,
16
+ left: 0,
17
+ zIndex: 400,
18
+ color: theme.palette.primary.main,
19
+ }))
@@ -1,105 +1,103 @@
1
1
  import {
2
- ListItemIcon,
3
- ListItemText,
4
- Menu,
5
- MenuItem,
6
- MenuListProps,
7
- MenuProps,
8
- styled,
2
+ ListItemIcon,
3
+ ListItemText,
4
+ Menu,
5
+ MenuItem,
6
+ MenuListProps,
7
+ MenuProps,
8
+ styled,
9
9
  } from '@mui/material'
10
- import { cloneElement, ReactNode, useState } from 'react'
10
+ import {cloneElement, ReactNode, useState} from 'react'
11
11
 
12
12
  interface Props {
13
- anchor: any
14
- loading?: boolean
15
- menu: {
16
- label: string | ReactNode
17
- icon?: ReactNode
18
- onClick: (props?: any) => any
19
- component?: ReactNode
20
- }[]
21
- menuProps?: Omit<MenuProps, 'open'>
22
- menuListProps?: MenuListProps
13
+ anchor: any
14
+ loading?: boolean
15
+ menu: {
16
+ label: string | ReactNode
17
+ icon?: ReactNode
18
+ onClick: (props?: any) => any
19
+ component?: ReactNode
20
+ }[]
21
+ menuProps?: Omit<MenuProps, 'open'>
22
+ menuListProps?: MenuListProps
23
23
  }
24
24
 
25
25
  export default function MenuButton({
26
- menu,
27
- menuProps,
28
- menuListProps,
29
- loading = false,
30
- anchor,
26
+ menu,
27
+ menuProps,
28
+ menuListProps,
29
+ loading = false,
30
+ anchor,
31
31
  }: Props) {
32
- const [anchorEl, setAnchorEl] = useState<any>(null)
33
- const open = Boolean(anchorEl)
32
+ const [anchorEl, setAnchorEl] = useState<any>(null)
33
+ const open = Boolean(anchorEl)
34
34
 
35
- const handleClick = (event) => {
36
- setAnchorEl(event.currentTarget)
37
- }
35
+ const handleClick = (event) => {
36
+ setAnchorEl(event.currentTarget)
37
+ }
38
38
 
39
- const handleClose = () => {
40
- setAnchorEl(null)
41
- }
39
+ const handleClose = () => {
40
+ setAnchorEl(null)
41
+ }
42
42
 
43
- const AnchorEl = cloneElement(anchor, {
44
- onClick: handleClick,
45
- })
43
+ const AnchorEl = cloneElement(anchor, {
44
+ onClick: handleClick,
45
+ })
46
46
 
47
- return (
48
- <>
49
- {AnchorEl}
50
- <Menu
51
- elevation={2}
52
- id="basic-menu"
53
- anchorEl={anchorEl}
54
- open={open}
55
- onClose={handleClose}
56
- MenuListProps={{
57
- sx: {
58
- padding: 0,
59
- },
60
- ...menuListProps,
61
- }}
62
- anchorOrigin={{
63
- vertical: 'bottom',
64
- horizontal: 'right',
65
- }}
66
- transformOrigin={{
67
- vertical: 'top',
68
- horizontal: 'right',
69
- }}
70
- {...menuProps}
71
- >
72
- {menu.map((item, index) => (
73
- <StyledMenuItem
74
- sx={{ minWidth: '120px', width: '100%' }}
75
- key={index}
76
- onClick={() => {
77
- handleClose()
78
- item.onClick()
79
- }}
80
- >
81
- {item?.icon && <ListItemIcon>{item.icon}</ListItemIcon>}
82
- <ListItemText>{item.label}</ListItemText>
83
- </StyledMenuItem>
84
- ))}
85
- </Menu>
86
- </>
87
- )
47
+ return (
48
+ <>
49
+ {AnchorEl}
50
+ <Menu
51
+ elevation={2}
52
+ id='basic-menu'
53
+ anchorEl={anchorEl}
54
+ open={open}
55
+ onClose={handleClose}
56
+ MenuListProps={{
57
+ sx: {padding: 0},
58
+ ...menuListProps,
59
+ }}
60
+ anchorOrigin={{
61
+ vertical: 'bottom',
62
+ horizontal: 'right',
63
+ }}
64
+ transformOrigin={{
65
+ vertical: 'top',
66
+ horizontal: 'right',
67
+ }}
68
+ {...menuProps}
69
+ >
70
+ {menu.map((item, index) => (
71
+ <StyledMenuItem
72
+ sx={{minWidth: '120px', width: '100%'}}
73
+ key={index}
74
+ onClick={() => {
75
+ handleClose()
76
+ item.onClick()
77
+ }}
78
+ >
79
+ {item?.icon && <ListItemIcon>{item.icon}</ListItemIcon>}
80
+ <ListItemText>{item.label}</ListItemText>
81
+ </StyledMenuItem>
82
+ ))}
83
+ </Menu>
84
+ </>
85
+ )
88
86
  }
89
87
 
90
- const StyledMenuItem = styled(MenuItem)(({ theme }) => ({
91
- padding: '10px 20px',
92
- display: 'flex',
93
- alignItems: 'center',
94
- '& .MuiListItemIcon-root': {
95
- minWidth: '24px',
96
- },
97
- '& .MuiSvgIcon-root': {
98
- height: '18px',
99
- width: '18px',
100
- },
101
- '& .MuiTypography-root': {
102
- fontWeight: 600,
103
- },
104
- borderBottom: theme.borders.grayLight,
88
+ const StyledMenuItem = styled(MenuItem)(({theme}) => ({
89
+ padding: '10px 20px',
90
+ display: 'flex',
91
+ alignItems: 'center',
92
+ '& .MuiListItemIcon-root': {
93
+ minWidth: '24px',
94
+ },
95
+ '& .MuiSvgIcon-root': {
96
+ height: '18px',
97
+ width: '18px',
98
+ },
99
+ '& .MuiTypography-root': {
100
+ fontWeight: 600,
101
+ },
102
+ borderBottom: theme.borders.grayLight,
105
103
  }))
@@ -1,18 +1,18 @@
1
- import { CircularProgress } from '@mui/material'
1
+ import {CircularProgress} from '@mui/material'
2
2
 
3
- function Spinner() {
4
- return (
5
- <div
6
- style={{
7
- justifyContent: 'center',
8
- alignItems: 'center',
9
- height: '200px',
10
- display: 'flex',
11
- }}
12
- >
13
- <CircularProgress />
14
- </div>
15
- )
3
+ function Spinner({height = '200px'}: {height?: string | number}) {
4
+ return (
5
+ <div
6
+ style={{
7
+ justifyContent: 'center',
8
+ alignItems: 'center',
9
+ height,
10
+ display: 'flex',
11
+ }}
12
+ >
13
+ <CircularProgress />
14
+ </div>
15
+ )
16
16
  }
17
17
 
18
18
  export default Spinner
@@ -3,56 +3,58 @@ import Chips from './Chips'
3
3
  import ImageUpload from './ImageUpload'
4
4
  import FloatingContainer from './FloatingContainer'
5
5
  import TabsContainer from './Tabs/TabsContainer'
6
- import { StyledTableContainer } from './StyledTableContainer'
7
- import { SearchBar } from './SearchBar'
8
- import { DrawerButton, DialogButton } from './ModalButtons'
6
+ import {StyledTableContainer} from './StyledTableContainer'
7
+ import {SearchBar} from './SearchBar'
8
+ import {DrawerButton, DialogButton} from './ModalButtons'
9
9
  import DetailsGrid from './DetailsGrid'
10
10
  import AppHeader from './Layout/Header'
11
11
  import MenuButton from './MenuButton'
12
12
  import StepsHeader from './StepsHeader'
13
13
  import UploadDocument from './UploadDocument'
14
- import { Table as StyledTable } from './Table'
14
+ import {Table as StyledTable} from './Table'
15
+ import ErrorBoundary from './ErrorBoundary'
15
16
 
16
- export { default as Image } from './Image'
17
- export { default as PageHeader } from './PageHeader'
18
- export { PageContent } from './PageContent'
19
- export { default as ActionButton } from './ActionButton'
20
- export { default as Breadcrumbs } from './Breadcrumbs'
21
- export { default as Table } from './TableComponent'
22
- export { default as Spinner } from './Spinner'
23
- export { default as AutocompleteSearch } from './AutocompleteSearch'
24
- export { FullCalendarWrapper } from './FullCalendar/FullCalendarWrapper'
25
- export { default as JsonPreview } from './JsonPreview'
26
- export { default as LabelValue } from './LabelValue'
27
- export { default as LinearProgress } from './LinearProgress'
28
- export { default as MediaRow } from './MediaRow'
29
- export { default as NoDataIllustration } from './NoDataIllustration'
30
- export { default as SwitchButton } from './SwitchButton'
31
- export { default as Tabs } from './Tabs'
32
- export { default as ToastContainer } from './ToastContainer'
33
- export { default as Card } from './Card'
34
- export { default as CardsGrid } from './CardsGrid'
35
- export { default as DividerHeading } from './DividerHeading'
36
- export { default as ReactTable } from './TableComponent/ReactTable'
37
- export { default as TableFooter } from './TableComponent/TableFooter'
38
- export { default as DropDownButton } from './DropDownButton'
39
- export { default as useConfirm } from './PopupConfirm/useConfirm'
17
+ export {default as Image} from './Image'
18
+ export {default as PageHeader} from './PageHeader'
19
+ export {PageContent} from './PageContent'
20
+ export {default as ActionButton} from './ActionButton'
21
+ export {default as Breadcrumbs} from './Breadcrumbs'
22
+ export {default as Table} from './TableComponent'
23
+ export {default as Spinner} from './Spinner'
24
+ export {default as AutocompleteSearch} from './AutocompleteSearch'
25
+ export {FullCalendarWrapper} from './FullCalendar/FullCalendarWrapper'
26
+ export {default as JsonPreview} from './JsonPreview'
27
+ export {default as LabelValue} from './LabelValue'
28
+ export {LinearProgress} from './LinearProgress'
29
+ export {default as MediaRow} from './MediaRow'
30
+ export {default as NoDataIllustration} from './NoDataIllustration'
31
+ export {default as SwitchButton} from './SwitchButton'
32
+ export {default as Tabs} from './Tabs'
33
+ export {default as ToastContainer} from './ToastContainer'
34
+ export {default as Card} from './Card'
35
+ export {default as CardsGrid} from './CardsGrid'
36
+ export {default as DividerHeading} from './DividerHeading'
37
+ export {default as ReactTable} from './TableComponent/ReactTable'
38
+ export {default as TableFooter} from './TableComponent/TableFooter'
39
+ export {default as DropDownButton} from './DropDownButton'
40
+ export {default as useConfirm} from './PopupConfirm/useConfirm'
40
41
  export {
41
- UploadFileDialog,
42
- Chips,
43
- ImageUpload,
44
- FloatingContainer,
45
- TabsContainer,
46
- StyledTableContainer,
47
- SearchBar,
48
- DrawerButton,
49
- DialogButton,
50
- DetailsGrid,
51
- AppHeader,
52
- MenuButton,
53
- StepsHeader,
54
- UploadDocument,
55
- StyledTable,
42
+ UploadFileDialog,
43
+ Chips,
44
+ ImageUpload,
45
+ FloatingContainer,
46
+ TabsContainer,
47
+ StyledTableContainer,
48
+ SearchBar,
49
+ DrawerButton,
50
+ DialogButton,
51
+ DetailsGrid,
52
+ AppHeader,
53
+ MenuButton,
54
+ StepsHeader,
55
+ UploadDocument,
56
+ StyledTable,
57
+ ErrorBoundary,
56
58
  }
57
59
 
58
60
  export * from './UploadButton/types'