@campxdev/shared 1.10.83 → 1.10.84

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.10.83",
3
+ "version": "1.10.84",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -1,18 +1,17 @@
1
- import { Alert, Box, Button, Divider, styled, Typography } from '@mui/material'
1
+ import { Alert, Box, Button, styled, Typography } from '@mui/material'
2
+ import Cookies from 'js-cookie'
2
3
  import { useEffect, useState } from 'react'
3
4
  import {
5
+ internalserver,
4
6
  nointernet,
5
7
  pagenotfound,
6
8
  permissiondenied,
7
9
  unauth,
8
- internalserver,
9
10
  } from '../../assets/images'
10
- import Cookies from 'js-cookie'
11
- import LoginForm from '../LoginForm'
12
- import { useModal } from '../DrawerWrapper/DrawerWrapper'
13
- import { PermissionsStore } from '../../shared-state'
14
11
  import axios from '../../config/axios'
15
12
  import { openRootModal } from '../../contexts/RootModal'
13
+ import { PermissionsStore } from '../../shared-state'
14
+ import { useModal } from '../DrawerWrapper/DrawerWrapper'
16
15
 
17
16
  const StyledAlert = styled(Alert)(({ theme }) => ({
18
17
  height: '60px',
@@ -171,6 +170,7 @@ export function UnAuth({ resetBoundary }) {
171
170
  process.env.NODE_ENV === 'development' ||
172
171
  origin?.slice(-2).join('.') === 'campx.dev'
173
172
  const sessionCookie = Cookies.get('campx_session_key')
173
+
174
174
  const appinit = async () => {
175
175
  setLoading(true)
176
176
  await axios
@@ -211,6 +211,12 @@ export function UnAuth({ resetBoundary }) {
211
211
  }
212
212
  }
213
213
 
214
+ useEffect(() => {
215
+ if (!isLocalHost) {
216
+ window.location.replace(`https://www.id.campx.in/?redirect_to=${url}`)
217
+ }
218
+ }, [isLocalHost])
219
+
214
220
  return (
215
221
  <>
216
222
  <StyledBox>
@@ -0,0 +1,105 @@
1
+ import { KeyboardArrowDown } from '@mui/icons-material'
2
+ import {
3
+ Autocomplete,
4
+ BoxProps,
5
+ Popper,
6
+ TextField,
7
+ alpha,
8
+ styled,
9
+ } from '@mui/material'
10
+
11
+ export const StyledAutocomplete = styled(Autocomplete)(({ theme }) => ({
12
+ '& .MuiAutocomplete-tag': {
13
+ border: '1px solid #D1D1D1',
14
+ background: '#F8F8F8',
15
+ borderRadius: '5px',
16
+ height: '38px',
17
+ '& .MuiSvgIcon-root': {
18
+ fontSize: '15px',
19
+ marginLeft: '5px',
20
+ fontWeight: 700,
21
+ color: theme.palette.secondary.main,
22
+ '&:hover': {
23
+ color: alpha(theme.palette.secondary.main, 0.8),
24
+ },
25
+ },
26
+ },
27
+ }))
28
+
29
+ export const StyledPopper = styled(Popper)(({ theme }) => ({
30
+ minWidth: 'fit-content',
31
+ '& .MuiPaper-root': {
32
+ borderRadius: '10px',
33
+ borderTopRightRadius: 0,
34
+ borderTopLeftRadius: 0,
35
+ boxShadow: '0px 4px 16px #0000000F',
36
+ marginTop: '1px',
37
+ '& .MuiAutocomplete-listbox': {
38
+ minWidth: '240px',
39
+ padding: '0px',
40
+ '& .MuiAutocomplete-option': {
41
+ padding: '15px',
42
+ borderBottom: '1px solid rgba(18, 18, 18, 0.1)',
43
+ },
44
+ },
45
+ '&::-webkit-scrollbar': {
46
+ width: '0.5em',
47
+ height: '0.5em',
48
+ },
49
+
50
+ '&::-webkit-scrollbar-thumb': {
51
+ backgroundColor: 'rgba(0, 0, 0, 0.15)',
52
+ borderRadius: '3px',
53
+
54
+ '&:hover': {
55
+ background: 'rgba(0, 0, 0, 0.2)',
56
+ },
57
+ },
58
+ },
59
+ }))
60
+
61
+ type Props = {
62
+ options: Array<{ label: string; value: any }>
63
+ value: { label: string; value: any }
64
+ onChange?: (value: any) => void
65
+ containerProps?: BoxProps
66
+ }
67
+ export const SearchSingleSelect = ({ options, value, onChange }: Props) => {
68
+ return (
69
+ <StyledAutocomplete
70
+ sx={{ legend: { display: 'none' } }}
71
+ fullWidth
72
+ multiple={false}
73
+ getOptionLabel={(option: any) => option?.label || ''}
74
+ options={options || []}
75
+ value={value}
76
+ onChange={(e, value) => {
77
+ onChange(value)
78
+ }}
79
+ isOptionEqualToValue={(option: any, value: any) =>
80
+ option?.value === value?.value
81
+ }
82
+ disableCloseOnSelect
83
+ PopperComponent={StyledPopper}
84
+ popupIcon={<KeyboardArrowDown />}
85
+ renderInput={(params) => {
86
+ console.log(params)
87
+ return (
88
+ <TextField
89
+ inputRef={(input) => {
90
+ if (input && value) {
91
+ input.style.width = `${value.label.length * 9}px`
92
+ }
93
+ }}
94
+ InputProps={{
95
+ ...params.InputProps,
96
+ endAdornment: <>{params.InputProps.endAdornment}</>,
97
+ }}
98
+ sx={{ minWidth: '220px' }}
99
+ {...params}
100
+ />
101
+ )
102
+ }}
103
+ />
104
+ )
105
+ }
@@ -1,9 +1,6 @@
1
- import { KeyboardArrowDown } from '@mui/icons-material'
2
- import { Box } from '@mui/material'
3
1
  import { urlTenantKey } from '../../contexts/Providers'
4
2
  import { InsititutionsStore } from '../../shared-state/InstitutionsStore'
5
- import { TextField } from '../Input'
6
- import { StyledAutocomplete, StyledPopper } from '../Input/MultiSelect'
3
+ import { SearchSingleSelect } from '../Input/SearchSingleSelect'
7
4
 
8
5
  export default function SchoolSwitch() {
9
6
  const { current, institutions } = InsititutionsStore.useState((s) => s)
@@ -18,40 +15,16 @@ export default function SchoolSwitch() {
18
15
  }
19
16
  const options =
20
17
  institutions?.map((item) => ({
21
- label: item.name,
22
- value: item.code,
18
+ label: item?.name,
19
+ value: item?.code,
23
20
  })) || []
21
+ const selectedOption = { label: current?.name, value: current?.code }
24
22
 
25
23
  return (
26
- <Box sx={{ legend: { display: 'none' } }}>
27
- <StyledAutocomplete
28
- multiple={false}
29
- sx={{
30
- minWidth: '220px',
31
- }}
32
- getOptionLabel={(option: any) => option?.label || ''}
33
- options={options || []}
34
- value={{ label: current.name, value: current.code }}
35
- onChange={(e, value) => {
36
- handleChange(value)
37
- }}
38
- isOptionEqualToValue={(option: any, value: any) =>
39
- option?.value === value?.value
40
- }
41
- disableCloseOnSelect
42
- PopperComponent={StyledPopper}
43
- popupIcon={<KeyboardArrowDown />}
44
- renderInput={(params) => (
45
- <TextField
46
- label={null}
47
- InputProps={{
48
- ...params.InputProps,
49
- endAdornment: <>{params.InputProps.endAdornment}</>,
50
- }}
51
- {...params}
52
- />
53
- )}
54
- />
55
- </Box>
24
+ <SearchSingleSelect
25
+ options={options}
26
+ value={selectedOption}
27
+ onChange={handleChange}
28
+ />
56
29
  )
57
30
  }
@@ -0,0 +1,105 @@
1
+ import { SelectProps } from '@mui/material'
2
+ import { useEffect, useState } from 'react'
3
+ import axios from '../../config/axios'
4
+ import { SingleSelect } from '../Input'
5
+
6
+ type ExamGroupSelectorProps = {
7
+ name?: string
8
+ label: string
9
+ filters?: { courseId: number; examType: string }
10
+ required?: boolean
11
+ onChange?: (value: any) => void
12
+ allowAll?: boolean
13
+ error?: boolean
14
+ helperText?: string
15
+ } & SelectProps
16
+ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
17
+ const {
18
+ name,
19
+ required = false,
20
+ label,
21
+ multiple = false,
22
+ filters,
23
+ allowAll = true,
24
+ } = props
25
+ const [options, setOptions] = useState([])
26
+ const [prevExamType, setPrevExamType] = useState(null)
27
+ const [prevCourseId, setPrevCourseId] = useState(null)
28
+ let api =
29
+ filters.examType !== 'internal'
30
+ ? '/exams/exams/exam-groups'
31
+ : '/exams/internal-exams'
32
+ const handleOpen = () => {
33
+ if (filters) {
34
+ if (
35
+ (filters.examType && filters.examType !== prevExamType) ||
36
+ (filters?.courseId && filters?.courseId !== prevCourseId)
37
+ ) {
38
+ setOptions([])
39
+ axios
40
+ .get(api, {
41
+ params: {
42
+ ...filters,
43
+ isArchived: 'false',
44
+ isExamPublished: 'true',
45
+ },
46
+ })
47
+ .then((response) => {
48
+ setOptions(
49
+ filters.examType !== 'internal'
50
+ ? response.data?.examGroups
51
+ : response.data?.exams,
52
+ )
53
+ setPrevExamType(filters.examType)
54
+ setPrevCourseId(filters.courseId)
55
+ })
56
+ .catch((error) => {
57
+ console.error('Error fetching data from the API:', error)
58
+ })
59
+ }
60
+ } else if (options.length === 0) {
61
+ axios
62
+ .get(api)
63
+ .then((response) => {
64
+ setOptions(response.data)
65
+ })
66
+ .catch((error) => {
67
+ console.error('Error fetching data from the API:', error)
68
+ })
69
+ }
70
+ }
71
+ useEffect(() => {
72
+ if (props?.value && props.value != 'all') {
73
+ handleOpen()
74
+ }
75
+ }, [props.value])
76
+
77
+ const handleOptions =
78
+ options.length > 0
79
+ ? [
80
+ ...(allowAll ? [{ value: 'all', label: 'All' }] : []),
81
+ ...options.map((item) => ({
82
+ label:
83
+ filters.examType != 'internal'
84
+ ? item?.groupName
85
+ : item?.displayName,
86
+ value: item?.id,
87
+ })),
88
+ ]
89
+ : allowAll
90
+ ? [{ value: 'all', label: 'All' }]
91
+ : []
92
+
93
+ return (
94
+ <SingleSelect
95
+ name={name}
96
+ label={label}
97
+ required={required}
98
+ options={handleOptions}
99
+ onOpen={handleOpen}
100
+ defaultValue="all"
101
+ {...props}
102
+ />
103
+ )
104
+ }
105
+ export default ExamGroupSelector
@@ -0,0 +1,48 @@
1
+ import { SelectProps } from '@mui/material'
2
+ import { Controller } from 'react-hook-form'
3
+ import ExamGroupSelector from '../ExamGroupSelector'
4
+
5
+ type ExamGroupSelectorProps = {
6
+ control: any
7
+ name: string
8
+ label: string
9
+ required?: boolean
10
+ multiple?: boolean
11
+ allowAll?: boolean
12
+ filters?: { courseId: number; examType: string }
13
+ onChange?: (value: any) => void
14
+ } & SelectProps
15
+ export default function FormExamGroupSelector(props: ExamGroupSelectorProps) {
16
+ const {
17
+ name,
18
+ required = false,
19
+ control,
20
+ label,
21
+ multiple = false,
22
+ allowAll = true,
23
+ onChange,
24
+ value,
25
+ filters,
26
+ } = props
27
+
28
+ return (
29
+ <Controller
30
+ name={name}
31
+ control={control}
32
+ render={({ field, fieldState: { error } }) => (
33
+ <ExamGroupSelector
34
+ label={label}
35
+ name={name}
36
+ onChange={onChange ?? field.onChange}
37
+ value={value ?? field?.value}
38
+ allowAll={allowAll}
39
+ filters={filters}
40
+ required={required}
41
+ error={!!error}
42
+ helperText={error?.message}
43
+ {...props}
44
+ />
45
+ )}
46
+ />
47
+ )
48
+ }
@@ -1,11 +1,13 @@
1
1
  import ClassRoomSelector from './ClassRoomSelector'
2
2
  import CourseSelector from './CourseSelector'
3
3
  import DepartmentSelector from './DepartmentSelector'
4
+ import ExamGroupSelector from './ExamGroupSelector'
4
5
  import FacultySelector from './FacultySelector'
5
6
  import FeeTypeSelector from './FeeTypeSelector'
6
7
  import FormClassRoomSelector from './FormSelectors/FormClassRoomSelector'
7
8
  import FormCourseSelector from './FormSelectors/FormCourseSelector'
8
9
  import FormDepartmentSelector from './FormSelectors/FormDepartmentSelector'
10
+ import FormExamGroupSelector from './FormSelectors/FormExamGroupSelector'
9
11
  import FormFacultySelector from './FormSelectors/FormFacultySelector'
10
12
  import FormFeeTypeSelector from './FormSelectors/FormFeeTypeSelector'
11
13
  import FormProgramSelector from './FormSelectors/FormProgramSelector'
@@ -23,11 +25,13 @@ export {
23
25
  ClassRoomSelector,
24
26
  CourseSelector,
25
27
  DepartmentSelector,
28
+ ExamGroupSelector,
26
29
  FacultySelector,
27
30
  FeeTypeSelector,
28
31
  FormClassRoomSelector,
29
32
  FormCourseSelector,
30
33
  FormDepartmentSelector,
34
+ FormExamGroupSelector,
31
35
  FormFacultySelector,
32
36
  FormFeeTypeSelector,
33
37
  FormProgramSelector,
@@ -13,9 +13,8 @@ import {
13
13
  } from '@mui/material'
14
14
  import { useEffect, useMemo, useState } from 'react'
15
15
  import { usePagination, useRowSelect, useTable } from 'react-table'
16
- import BatchActionsHeader from './BatchActionsHeader'
16
+ import TableStats from '../common/TableStats'
17
17
  import { SortAscIcon, SortDescIcon, SortIcon } from '../common/icons'
18
- import { RenderTableBody } from './RenderTableBody'
19
18
  import {
20
19
  StyledLimitBox,
21
20
  StyledLimitMenu,
@@ -23,7 +22,8 @@ import {
23
22
  StyledTableFooter,
24
23
  } from '../common/styles'
25
24
  import { ColumnProps, Sort, TableProps } from '../common/types'
26
- import TableStats from '../common/TableStats'
25
+ import BatchActionsHeader from './BatchActionsHeader'
26
+ import { RenderTableBody } from './RenderTableBody'
27
27
 
28
28
  type ReactTableCell = {
29
29
  Header: any
@@ -75,6 +75,7 @@ const getTableCol = (headerItem: ColumnProps) => {
75
75
 
76
76
  export default function ReactTable({
77
77
  columns,
78
+ rowKey = 'id',
78
79
  dataSource,
79
80
  loading,
80
81
  pagination,
@@ -128,7 +129,7 @@ export default function ReactTable({
128
129
  manualPagination: true,
129
130
  autoResetSelectedRows: false,
130
131
  pageCount: pagination?.totalCount ?? dataSource?.length,
131
- getRowId: select?.enable ? (row) => row?.id : undefined,
132
+ getRowId: select?.enable ? (row) => row[rowKey] : undefined,
132
133
  },
133
134
  // useSortBy,
134
135
  usePagination,
@@ -1,14 +1,13 @@
1
1
  import Axios, { AxiosRequestConfig } from 'axios'
2
- import _ from 'lodash'
3
- import { toast } from 'react-toastify'
4
2
  import Cookies from 'js-cookie'
3
+ import { toast } from 'react-toastify'
5
4
  import { NetworkStore } from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
6
5
  import { isDevelopment } from '../constants'
7
- import { UserStore } from '../shared-state'
8
6
  import { InsititutionsStore } from '../shared-state/InstitutionsStore'
9
7
 
10
8
  const sessionKey = Cookies.get('campx_session_key')
11
9
  const clientId = window.location.pathname.split('/')[1] ?? 'campx_dev'
10
+ const institutionId = window.location.pathname.split('/')[2] ?? 'campx_dev'
12
11
 
13
12
  export const formatParams = (params) => {
14
13
  return Object.fromEntries(
@@ -36,6 +35,8 @@ axios.interceptors.request.use(
36
35
  const { current } = InsititutionsStore.getRawState()
37
36
  if (current) {
38
37
  config.headers['x-institution-code'] = current.code
38
+ } else {
39
+ config.headers['x-institution-code'] = institutionId
39
40
  }
40
41
 
41
42
  const params = formatParams(config?.params)