@campxdev/shared 0.2.13 → 0.2.14

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -1,4 +1,5 @@
1
1
  import {Box, styled, Typography} from '@mui/material'
2
+ import {ReactNode} from 'react'
2
3
  import {Link} from 'react-router-dom'
3
4
  import {campxLogoPrimary} from '../../../assets/images'
4
5
  import {applications} from './applications'
@@ -39,7 +40,13 @@ interface AppHeaderProps {
39
40
  clientLogo: string
40
41
  username: string
41
42
  profileIcon: string
42
- permissions: any
43
+ permissions?: any
44
+ userBoxActions: {
45
+ label: ReactNode
46
+ icon?: ReactNode
47
+ onClick: any
48
+ }[]
49
+ cogWheelMenu?: {label: string; path: string}[]
43
50
  }
44
51
 
45
52
  const isDev = process.env.NODE_ENV === 'development'
@@ -49,6 +56,8 @@ export default function AppHeader({
49
56
  username,
50
57
  profileIcon,
51
58
  permissions,
59
+ userBoxActions = [],
60
+ cogWheelMenu = [],
52
61
  }: AppHeaderProps) {
53
62
  return (
54
63
  <StyledHeader>
@@ -59,8 +68,12 @@ export default function AppHeader({
59
68
  <Box className='actions'>
60
69
  <FreshDeskHelpButton />
61
70
  <Notification />
62
- <CogWheelMenu />
63
- <UserBox username={username} profileIcon={profileIcon} />
71
+ {cogWheelMenu?.length && <CogWheelMenu menu={cogWheelMenu} />}
72
+ <UserBox
73
+ username={username}
74
+ profileIcon={profileIcon}
75
+ actions={userBoxActions}
76
+ />
64
77
  </Box>
65
78
  </StyledHeader>
66
79
  )
@@ -1,35 +1,26 @@
1
- import { SettingsOutlined } from '@mui/icons-material'
2
- import { IconButton } from '@mui/material'
3
- import { useHistory } from '../../../hooks/useRouter'
1
+ import {SettingsOutlined} from '@mui/icons-material'
2
+ import {IconButton} from '@mui/material'
3
+ import {useHistory} from '../../../hooks/useRouter'
4
4
  import MenuButton from '../../MenuButton'
5
5
 
6
- const profileMenu = [
7
- { label: 'Roles and Permissions', value: '/roles-and-permissions' },
8
- { label: 'Audit Logs', value: '/audit-logs' },
9
- { label: 'Careers', value: '/careers' },
10
- { label: 'PHD Applications', value: '/phd' },
11
- { label: 'Anurag CET', value: '/applications' },
12
- { label: 'Agri CET', value: '/agricet' },
13
- ]
6
+ const CogWheelMenu = ({menu}) => {
7
+ const history = useHistory()
14
8
 
15
- const CogWheelMenu = () => {
16
- const history = useHistory()
17
-
18
- return (
19
- <MenuButton
20
- anchor={
21
- <IconButton color="secondary">
22
- <SettingsOutlined />
23
- </IconButton>
24
- }
25
- menu={profileMenu?.map((item) => ({
26
- label: item?.label,
27
- onClick: () => {
28
- history.push(item?.value)
29
- },
30
- }))}
31
- />
32
- )
9
+ return (
10
+ <MenuButton
11
+ anchor={
12
+ <IconButton color='secondary'>
13
+ <SettingsOutlined />
14
+ </IconButton>
15
+ }
16
+ menu={menu?.map((item) => ({
17
+ label: item?.label,
18
+ onClick: () => {
19
+ history.push(item?.path)
20
+ },
21
+ }))}
22
+ />
23
+ )
33
24
  }
34
25
 
35
26
  export default CogWheelMenu
@@ -12,14 +12,16 @@ import axios from 'axios'
12
12
  import {axiosErrorToast} from '../../../config/axios'
13
13
  import {isDevelopment} from '../../../constants/isDevelopment'
14
14
  import Cookies from 'js-cookie'
15
- import {useState} from 'react'
15
+ import {ReactNode, useState} from 'react'
16
16
 
17
17
  export default function UserBox({
18
18
  username,
19
19
  profileIcon,
20
+ actions,
20
21
  }: {
21
22
  username: string
22
23
  profileIcon: string
24
+ actions: {label: ReactNode; icon?: ReactNode; onClick: any}[]
23
25
  }) {
24
26
  const history = useHistory()
25
27
  const [posting, setPosting] = useState(false)
@@ -34,15 +36,13 @@ export default function UserBox({
34
36
  setPosting(true)
35
37
  axios({
36
38
  method: 'POST',
37
- baseURL: process.env.REACT_APP_API_HOST,
39
+ baseURL: process.env.REACT_APP_AUTH_HOST,
38
40
  url: '/auth/logout',
39
41
  })
40
42
  .then((res) => {
41
- setPosting(false)
42
43
  window.location.href = '/'
43
44
  })
44
45
  .catch((err) => {
45
- setPosting(false)
46
46
  axiosErrorToast('Unable To Logout.')
47
47
  })
48
48
  }
@@ -66,25 +66,7 @@ export default function UserBox({
66
66
  )}
67
67
  </Box>
68
68
  }
69
- menu={[
70
- {
71
- label: 'Profile',
72
- icon: <PermIdentityOutlined />,
73
- onClick: () => {
74
- history.push('/profile')
75
- },
76
- },
77
- {
78
- label: 'Change Password',
79
- icon: <HttpsOutlined />,
80
- onClick: () => {},
81
- },
82
- {
83
- label: 'Logout',
84
- icon: <ExitToAppOutlined />,
85
- onClick: logout,
86
- },
87
- ]}
69
+ menu={actions}
88
70
  />
89
71
  )
90
72
  }
@@ -2,7 +2,8 @@ import {BoxProps, styled, Box, LinearProgress} from '@mui/material'
2
2
  import {globalStore} from '../../shared-state/GlobalStore'
3
3
 
4
4
  export default function LinearIndeterminate() {
5
- const loading = globalStore.useState((s) => s).loading
5
+ // const loading = globalStore.useState((s) => s).loading
6
+ const loading = false
6
7
 
7
8
  if (!loading) return null
8
9
  return <StyledLinearProgress />
@@ -31,48 +31,48 @@ 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
+ // globalStore.update((s) => {
35
+ // s.loading = true
36
+ // s.error.message = ''
37
+ // s.error.statusCode = null
38
+ // s.error.description = ''
39
+ // })
40
40
  return {...config, params}
41
41
  },
42
42
  function (error) {
43
- globalStore.update((s) => {
44
- s.loading = true
45
- })
43
+ // globalStore.update((s) => {
44
+ // s.loading = true
45
+ // })
46
46
  return Promise.reject(error)
47
47
  }
48
48
  )
49
49
 
50
50
  axios.interceptors.response.use(
51
51
  function (response) {
52
- globalStore.update((s) => {
53
- s.loading = false
54
- })
52
+ // globalStore.update((s) => {
53
+ // s.loading = false
54
+ // })
55
55
  return response
56
56
  },
57
57
  function (err) {
58
- globalStore.update((s) => {
59
- s.loading = false
60
- })
58
+ // globalStore.update((s) => {
59
+ // s.loading = false
60
+ // })
61
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
- }
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
76
 
77
77
  return Promise.reject(err)
78
78
  }
@@ -17,24 +17,23 @@ export default function PageWithPermission({
17
17
  component?: any
18
18
  children?: any
19
19
  }) {
20
- const history = useHistory()
21
- const errorState = globalStore.useState((s) => s.error)
20
+ // const history = useHistory()
21
+ // const errorState = globalStore.useState((s) => s.error)
22
22
 
23
23
  const permissions = PermissionsStore.useState((s) => s).permissions
24
24
  const hasAccess = permissionKey ? permissions[permissionKey] : accessIfNoKey
25
25
 
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 />
26
+ // useEffect(() => {
27
+ // globalStore.update((s) => {
28
+ // s.error = {
29
+ // message: '',
30
+ // statusCode: null,
31
+ // description: '',
32
+ // }
33
+ // })
34
+ // }, [history])
37
35
 
36
+ // if (errorState.statusCode) return <ErrorPage />
38
37
  // if (hasAccess) return Component
39
38
  if (hasAccess) return children
40
39
  return <PermissionDeniedPage />