@campxdev/shared 1.11.30 → 1.11.32-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.11.30",
3
+ "version": "1.11.32-alpha.1",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -2,6 +2,7 @@ import {
2
2
  StyledLeftNavContainer,
3
3
  StyledMainContentContainer,
4
4
  } from '../../layouts/Components/styles'
5
+ import { PermissionsStore } from '../../shared-state'
5
6
  import ErrorBoundary from '../ErrorBoundary'
6
7
  import SideNav from './SideNav'
7
8
  interface Props {
@@ -15,12 +16,29 @@ export default function LayoutWrapper({
15
16
  menu,
16
17
  sideMenuHeader,
17
18
  }: Props) {
19
+ const permissions = PermissionsStore.useState()
20
+
18
21
  return (
19
22
  <ErrorBoundary>
20
- <StyledLeftNavContainer>
21
- <SideNav menuItems={menu as any[]} header={sideMenuHeader} />
22
- </StyledLeftNavContainer>
23
- <StyledMainContentContainer>
23
+ {!permissions.isHomePageEnabled && (
24
+ <StyledLeftNavContainer>
25
+ <SideNav menuItems={menu as any[]} header={sideMenuHeader} />
26
+ </StyledLeftNavContainer>
27
+ )}
28
+ <StyledMainContentContainer
29
+ style={{
30
+ width: permissions.isHomePageEnabled
31
+ ? 'inherit'
32
+ : 'calc(100% - 220px)',
33
+ position: permissions.isHomePageEnabled ? 'unset' : 'fixed',
34
+ marginTop: permissions.isHomePageEnabled ? '10px' : '0px',
35
+ borderRadius: permissions.isHomePageEnabled ? '10px' : '0px',
36
+ border: permissions.isHomePageEnabled ? '1px solid #1212' : 'none',
37
+ height: permissions.isHomePageEnabled
38
+ ? 'calc(100vh - 74px)'
39
+ : 'calc(100vh - 64px)',
40
+ }}
41
+ >
24
42
  <ErrorBoundary>{children}</ErrorBoundary>
25
43
  </StyledMainContentContainer>
26
44
  </ErrorBoundary>
@@ -26,13 +26,13 @@ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
26
26
  const [prevExamType, setPrevExamType] = useState(null)
27
27
  const [prevCourseId, setPrevCourseId] = useState(null)
28
28
  let api =
29
- filters.examType !== 'internal'
29
+ filters?.examType !== 'internal'
30
30
  ? '/exams/exams/exam-groups'
31
31
  : '/exams/internal-exams'
32
32
  const handleOpen = () => {
33
33
  if (filters) {
34
34
  if (
35
- (filters.examType && filters.examType !== prevExamType) ||
35
+ (filters?.examType && filters?.examType !== prevExamType) ||
36
36
  (filters?.courseId && filters?.courseId !== prevCourseId)
37
37
  ) {
38
38
  setOptions([])
@@ -46,12 +46,12 @@ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
46
46
  })
47
47
  .then((response) => {
48
48
  setOptions(
49
- filters.examType !== 'internal'
49
+ filters?.examType !== 'internal'
50
50
  ? response.data?.examGroups
51
51
  : response.data?.exams,
52
52
  )
53
- setPrevExamType(filters.examType)
54
- setPrevCourseId(filters.courseId)
53
+ setPrevExamType(filters?.examType)
54
+ setPrevCourseId(filters?.courseId)
55
55
  })
56
56
  .catch((error) => {
57
57
  console.error('Error fetching data from the API:', error)
@@ -59,9 +59,18 @@ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
59
59
  }
60
60
  } else if (options.length === 0) {
61
61
  axios
62
- .get(api)
62
+ .get(api, {
63
+ params: {
64
+ isArchived: 'false',
65
+ isExamPublished: 'true',
66
+ },
67
+ })
63
68
  .then((response) => {
64
- setOptions(response.data)
69
+ setOptions(
70
+ filters?.examType !== 'internal'
71
+ ? response.data?.examGroups
72
+ : response.data?.exams,
73
+ )
65
74
  })
66
75
  .catch((error) => {
67
76
  console.error('Error fetching data from the API:', error)
@@ -80,7 +89,7 @@ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
80
89
  ...(allowAll ? [{ value: 'all', label: 'All' }] : []),
81
90
  ...options.map((item) => ({
82
91
  label:
83
- filters.examType != 'internal'
92
+ filters?.examType != 'internal'
84
93
  ? item?.groupName
85
94
  : item?.displayName,
86
95
  value: item?.id,
@@ -14,10 +14,10 @@ import {
14
14
  } from '@mui/material'
15
15
  import { ReactNode, useEffect, useRef, useState } from 'react'
16
16
  import { toast } from 'react-toastify'
17
- import axios, { axiosErrorToast } from '../../config/axios'
17
+ import axios from '../../config/axios'
18
18
  import { buffertoCSV } from '../../utils'
19
- import { DeleteButton, EditButton } from '../IconButtons'
20
19
  import { useErrorModal } from '../ErrorModalWrapper/ErrorModalWrapper'
20
+ import { DeleteButton, EditButton } from '../IconButtons'
21
21
  const animatedImage = require('./AnimatedUploadFile.gif')
22
22
 
23
23
  const StyledDialogHeader = styled(Box)(({ theme }) => ({
@@ -80,7 +80,8 @@ interface UploadFileDialogProps {
80
80
  sampleFileDownloadUrl?: string
81
81
  uploadUrl: string
82
82
  successMessage?: string
83
- refetchFn: (res: any) => void
83
+ refetchFn?: (res: any) => void
84
+ onUpload?: () => void
84
85
  postBody?: { [key: string]: string }
85
86
  }
86
87
 
@@ -95,6 +96,7 @@ export default function UploadFileDialog({
95
96
  refetchFn,
96
97
  sampleFileDownloadUrl,
97
98
  postBody = {},
99
+ onUpload,
98
100
  }: UploadFileDialogProps) {
99
101
  const inputRef: any = useRef(null)
100
102
  const [loading, setLoading] = useState(false)
@@ -115,6 +117,7 @@ export default function UploadFileDialog({
115
117
  }
116
118
 
117
119
  const handleOnUpload = () => {
120
+ onUpload && onUpload()
118
121
  if (!file) return ``
119
122
  const formData = new FormData()
120
123
  formData.append('file', file)
@@ -129,7 +132,7 @@ export default function UploadFileDialog({
129
132
  .post(uploadUrl, formData)
130
133
  .then((res) => {
131
134
  setLoading(false)
132
- refetchFn(res)
135
+ refetchFn && refetchFn(res)
133
136
  setOpen(false)
134
137
  toast.success(successMessage ?? 'Successful')
135
138
  setFile(null)
@@ -6,7 +6,7 @@ import { isDevelopment, isSetup } from '../constants'
6
6
  import { InstitutionsStore } from '../shared-state/InstitutionsStore'
7
7
 
8
8
  const sessionKey = Cookies.get('campx_session_key')
9
- const clientId = window.location.pathname.split('/')[1] ?? 'campx_dev'
9
+ const clientId = window.location.origin.split('.')[0] ?? 'campx_dev'
10
10
  const institutionId = window.location.pathname.split('/')[2] ?? 'campx_dev'
11
11
  const openPaymentsKey = Cookies.get('campx_open_payments_key')
12
12
 
@@ -26,6 +26,7 @@ type AuthResponse = {
26
26
  logo: string
27
27
  logo_square: string
28
28
  }
29
+ isHomePageEnabled?: boolean
29
30
  }
30
31
  }
31
32
 
@@ -235,6 +236,7 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
235
236
  s.isMasterInstitutionUser = res.data?.institutions
236
237
  ?.map((institution) => institution?.id)
237
238
  ?.includes(res?.data?.masterInstitutionUniqueId)
239
+ s.isHomePageEnabled = res.data?.isHomePageEnabled
238
240
  })
239
241
  AssetsStore.update((s) => {
240
242
  s.logo = res.data?.assets.logo
@@ -1,5 +1,5 @@
1
- import styled from 'styled-components'
2
1
  import { styled as muiStyled } from '@mui/material'
2
+ import styled from 'styled-components'
3
3
 
4
4
  export const headerHeight = '64px'
5
5
  export const sideNavWidth = '220px'
@@ -59,16 +59,29 @@ export const StyledMainContentContainer = muiStyled('main')(() => ({
59
59
  overflowY: 'auto',
60
60
 
61
61
  '&::-webkit-scrollbar': {
62
- width: '0.6em',
63
- height: '0.6em',
62
+ width: '0.4em',
63
+ height: '0.4em',
64
64
  },
65
65
 
66
66
  '&::-webkit-scrollbar-thumb': {
67
- backgroundColor: 'rgba(0,0,0, 0.3)',
67
+ backgroundColor: 'rgba(0, 0, 0, 0.2)',
68
68
  borderRadius: '3px',
69
-
70
69
  '&:hover': {
71
70
  background: 'rgba(0,0,0, 0.4)',
72
71
  },
73
72
  },
73
+
74
+ // '&::-webkit-scrollbar': {
75
+ // width: '0.6em',
76
+ // height: '0.6em',
77
+ // },
78
+
79
+ // '&::-webkit-scrollbar-thumb': {
80
+ // backgroundColor: 'rgba(0,0,0, 0.3)',
81
+ // borderRadius: '3px',
82
+
83
+ // '&:hover': {
84
+ // background: 'rgba(0,0,0, 0.4)',
85
+ // },
86
+ // },
74
87
  }))
@@ -2047,6 +2047,7 @@ interface IPermissionsStore {
2047
2047
  masterInstitutionId?: string
2048
2048
  isMasterInstitution: boolean
2049
2049
  isMasterInstitutionUser?: boolean
2050
+ isHomePageEnabled?: boolean
2050
2051
  }
2051
2052
 
2052
2053
  export const PermissionsStore = new Store<IPermissionsStore>({
@@ -2057,4 +2058,5 @@ export const PermissionsStore = new Store<IPermissionsStore>({
2057
2058
  masterInstitutionId: null,
2058
2059
  isMasterInstitution: false,
2059
2060
  isMasterInstitutionUser: false,
2061
+ isHomePageEnabled: false,
2060
2062
  })
@@ -6,3 +6,14 @@ export default function getUrlParams() {
6
6
  }
7
7
  return params
8
8
  }
9
+
10
+ export const createSearchParams = (query: { [key: string]: string }) => {
11
+ const searchParams = new URLSearchParams()
12
+
13
+ for (const key in query) {
14
+ if (query[key] !== null && query[key] !== 'all') {
15
+ searchParams.append(key, encodeURIComponent(query[key]))
16
+ }
17
+ }
18
+ return query
19
+ }
@@ -1,8 +1,11 @@
1
- export { default as getUrlParams } from './getUrlParams'
1
+ import { createSearchParams } from './getUrlParams'
2
2
  export { default as arrayPadEnd } from './arrayPadEnd'
3
- export { default as romanize } from './romanize'
4
3
  export { default as buffertoCSV } from './buffertoCSV'
4
+ export { default as getUrlParams } from './getUrlParams'
5
+ export { default as romanize } from './romanize'
5
6
 
7
+ export { default as onLogout } from './logout'
6
8
  export { default as withRouteWrapper } from './withRouteWrapper'
7
9
  export { default as withSuspense } from './withSuspense'
8
- export { default as onLogout } from './logout'
10
+
11
+ export { createSearchParams }