@campxdev/shared 1.10.65 → 1.10.67
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 +1 -1
- package/src/components/Input/MultiSelect.tsx +2 -0
- package/src/components/Layout/SideMenuHeader.tsx +2 -0
- package/src/components/Layout/SideNav.tsx +1 -1
- package/src/components/ListItemButton.tsx +2 -7
- package/src/components/Selectors/CourseSelector.tsx +59 -0
- package/src/components/Selectors/FeeTypeSelector.tsx +60 -0
- package/src/components/Selectors/FormSelectors/FormCourseSelector.tsx +45 -0
- package/src/components/Selectors/FormSelectors/FormFeeTypeSelector.tsx +44 -0
- package/src/components/Selectors/FormSelectors/FormProgramSelector.tsx +48 -0
- package/src/components/Selectors/FormSelectors/FormQuotaSelector.tsx +48 -0
- package/src/components/Selectors/FormSelectors/FormSemesterSelector.tsx +48 -0
- package/src/components/Selectors/FormSelectors/MultiSelect/MultiProgramSelector.tsx +98 -0
- package/src/components/Selectors/FormSelectors/MultiSelect/MultiQuotaSelector.tsx +96 -0
- package/src/components/Selectors/ProgramSelector.tsx +52 -16
- package/src/components/Selectors/QuotaSelector.tsx +83 -0
- package/src/components/Selectors/SemesterSelector.tsx +85 -0
- package/src/components/Selectors/index.tsx +26 -1
- package/src/components/Tables/BasicTable/Table.tsx +124 -31
- package/src/components/index.ts +0 -1
- package/src/components/Tables/MobileTable/MobileTable.tsx +0 -218
- package/src/components/Tables/MobileTable/index.tsx +0 -1
package/package.json
CHANGED
|
@@ -87,6 +87,7 @@ interface MultiSelectProps {
|
|
|
87
87
|
helperText?: string
|
|
88
88
|
multiple?: boolean
|
|
89
89
|
limitTags?: number
|
|
90
|
+
onOpen?: (e: any) => void
|
|
90
91
|
noOptionsText?: string
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -119,6 +120,7 @@ export default function MultiSelect({
|
|
|
119
120
|
if (!onChange) return
|
|
120
121
|
onChange(value)
|
|
121
122
|
}}
|
|
123
|
+
onOpen={props.onOpen}
|
|
122
124
|
onInputChange={onInputChange}
|
|
123
125
|
limitTags={limitTags}
|
|
124
126
|
isOptionEqualToValue={(option: any, value: any) =>
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
styled,
|
|
8
8
|
} from '@mui/material'
|
|
9
9
|
import { Store } from 'pullstate'
|
|
10
|
-
import {
|
|
10
|
+
import { ReactNode, memo } from 'react'
|
|
11
11
|
import { Link, useMatch, useResolvedPath } from 'react-router-dom'
|
|
12
12
|
import { PermissionsStore } from '../../shared-state'
|
|
13
13
|
import {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ChevronRight } from '@mui/icons-material'
|
|
2
2
|
import {
|
|
3
|
-
Box,
|
|
4
|
-
ListItemButton as MuiListItemButton,
|
|
5
3
|
ListItemButtonProps,
|
|
6
4
|
ListItemIcon,
|
|
7
5
|
ListItemText,
|
|
6
|
+
ListItemButton as MuiListItemButton,
|
|
8
7
|
styled,
|
|
9
8
|
} from '@mui/material'
|
|
10
9
|
import { ReactNode } from 'react'
|
|
@@ -25,11 +24,7 @@ export const ListItemButton = ({
|
|
|
25
24
|
}: Props) => {
|
|
26
25
|
return (
|
|
27
26
|
<StyledListItemButton isActive={isActive} onClick={onClick}>
|
|
28
|
-
{Icon ?
|
|
29
|
-
<ListItemIcon>{<Icon />}</ListItemIcon>
|
|
30
|
-
) : (
|
|
31
|
-
<Box minWidth={16}></Box>
|
|
32
|
-
)}
|
|
27
|
+
{Icon ? <ListItemIcon>{<Icon />}</ListItemIcon> : null}
|
|
33
28
|
<ListItemText primary={label} />
|
|
34
29
|
</StyledListItemButton>
|
|
35
30
|
)
|
|
@@ -0,0 +1,59 @@
|
|
|
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 CourseSelectorProps = {
|
|
7
|
+
name?: string
|
|
8
|
+
label: string
|
|
9
|
+
required?: boolean
|
|
10
|
+
onChange?: (value: any) => void
|
|
11
|
+
allowAll?: boolean
|
|
12
|
+
error?: boolean
|
|
13
|
+
helperText?: string
|
|
14
|
+
} & SelectProps
|
|
15
|
+
export default function CourseSelector(props: CourseSelectorProps) {
|
|
16
|
+
const { name, required = false, label, onChange, allowAll = true } = props
|
|
17
|
+
const [options, setOptions] = useState([])
|
|
18
|
+
|
|
19
|
+
const handleOpen = () => {
|
|
20
|
+
if (options.length === 0) {
|
|
21
|
+
axios
|
|
22
|
+
.get('/square/courses')
|
|
23
|
+
.then((response) => {
|
|
24
|
+
setOptions(response.data.courses)
|
|
25
|
+
})
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
console.error('Error fetching data from the API:', error)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (props?.value && props.value != 'all') {
|
|
33
|
+
handleOpen()
|
|
34
|
+
}
|
|
35
|
+
}, [props.value])
|
|
36
|
+
const handleOptions =
|
|
37
|
+
options.length > 0
|
|
38
|
+
? [
|
|
39
|
+
...(allowAll ? [{ value: 'all', label: 'All' }] : []),
|
|
40
|
+
...options.map((item) => ({
|
|
41
|
+
label: `${item.courseName} `,
|
|
42
|
+
value: `${item.id}`,
|
|
43
|
+
})),
|
|
44
|
+
]
|
|
45
|
+
: allowAll
|
|
46
|
+
? [{ value: 'all', label: 'All' }]
|
|
47
|
+
: []
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<SingleSelect
|
|
51
|
+
name={name}
|
|
52
|
+
label={label}
|
|
53
|
+
required={required}
|
|
54
|
+
options={handleOptions}
|
|
55
|
+
onOpen={handleOpen}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 FeeTypeSelectorProps = {
|
|
7
|
+
name?: string
|
|
8
|
+
label: string
|
|
9
|
+
required?: boolean
|
|
10
|
+
allowAll?: boolean
|
|
11
|
+
onChange?: (value: any) => void
|
|
12
|
+
error?: boolean
|
|
13
|
+
helperText?: string
|
|
14
|
+
} & SelectProps
|
|
15
|
+
export default function FeeTypeSelector(props: FeeTypeSelectorProps) {
|
|
16
|
+
const { name, required = false, label, onChange, allowAll = true } = props
|
|
17
|
+
const [options, setOptions] = useState([])
|
|
18
|
+
|
|
19
|
+
const handleOpen = () => {
|
|
20
|
+
if (options.length === 0) {
|
|
21
|
+
axios
|
|
22
|
+
.get('/payments/fee-types')
|
|
23
|
+
.then((response) => {
|
|
24
|
+
setOptions(response.data)
|
|
25
|
+
})
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
console.error('Error fetching data from the API:', error)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (props?.value && props.value != 'all') {
|
|
33
|
+
handleOpen()
|
|
34
|
+
}
|
|
35
|
+
}, [props.value])
|
|
36
|
+
|
|
37
|
+
const handleOptions =
|
|
38
|
+
options.length > 0
|
|
39
|
+
? [
|
|
40
|
+
...(allowAll ? [{ value: 'all', label: 'All' }] : []),
|
|
41
|
+
...options.map((item) => ({
|
|
42
|
+
label: `${item.name} `,
|
|
43
|
+
value: `${item.slug}`,
|
|
44
|
+
})),
|
|
45
|
+
]
|
|
46
|
+
: allowAll
|
|
47
|
+
? [{ value: 'all', label: 'All' }]
|
|
48
|
+
: []
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<SingleSelect
|
|
52
|
+
name={name}
|
|
53
|
+
label={label}
|
|
54
|
+
required={required}
|
|
55
|
+
options={handleOptions}
|
|
56
|
+
onOpen={handleOpen}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SelectProps } from '@mui/material'
|
|
2
|
+
import { Controller } from 'react-hook-form'
|
|
3
|
+
import CourseSelector from '../CourseSelector'
|
|
4
|
+
|
|
5
|
+
type FormCourseSelectorProps = {
|
|
6
|
+
control: any
|
|
7
|
+
name: string
|
|
8
|
+
label: string
|
|
9
|
+
required?: boolean
|
|
10
|
+
multiple?: boolean
|
|
11
|
+
allowAll?: boolean
|
|
12
|
+
onChange?: (value: any) => void
|
|
13
|
+
} & SelectProps
|
|
14
|
+
export default function FormCourseSelector(props: FormCourseSelectorProps) {
|
|
15
|
+
const {
|
|
16
|
+
name,
|
|
17
|
+
required = false,
|
|
18
|
+
control,
|
|
19
|
+
label,
|
|
20
|
+
allowAll = true,
|
|
21
|
+
multiple = false,
|
|
22
|
+
onChange,
|
|
23
|
+
value,
|
|
24
|
+
} = props
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Controller
|
|
28
|
+
name={name}
|
|
29
|
+
control={control}
|
|
30
|
+
render={({ field, fieldState: { error } }) => (
|
|
31
|
+
<CourseSelector
|
|
32
|
+
label={label}
|
|
33
|
+
name={name}
|
|
34
|
+
onChange={onChange ?? field.onChange}
|
|
35
|
+
value={value ?? field?.value}
|
|
36
|
+
allowAll={allowAll}
|
|
37
|
+
required={required}
|
|
38
|
+
error={!!error}
|
|
39
|
+
helperText={error?.message}
|
|
40
|
+
{...props}
|
|
41
|
+
/>
|
|
42
|
+
)}
|
|
43
|
+
/>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SelectProps } from '@mui/material'
|
|
2
|
+
import { Controller } from 'react-hook-form'
|
|
3
|
+
import FeeTypeSelector from '../FeeTypeSelector'
|
|
4
|
+
|
|
5
|
+
type FormFeeTypeSelectorProps = {
|
|
6
|
+
control: any
|
|
7
|
+
name: string
|
|
8
|
+
label: string
|
|
9
|
+
required?: boolean
|
|
10
|
+
multiple?: boolean
|
|
11
|
+
allowAll?: boolean
|
|
12
|
+
onChange?: (value: any) => void
|
|
13
|
+
} & SelectProps
|
|
14
|
+
export default function FormFeeTypeSelector(props: FormFeeTypeSelectorProps) {
|
|
15
|
+
const {
|
|
16
|
+
name,
|
|
17
|
+
required = false,
|
|
18
|
+
control,
|
|
19
|
+
label,
|
|
20
|
+
allowAll = true,
|
|
21
|
+
multiple = false,
|
|
22
|
+
onChange,
|
|
23
|
+
value,
|
|
24
|
+
} = props
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Controller
|
|
28
|
+
name={name}
|
|
29
|
+
control={control}
|
|
30
|
+
render={({ field, fieldState: { error } }) => (
|
|
31
|
+
<FeeTypeSelector
|
|
32
|
+
label={label}
|
|
33
|
+
name={name}
|
|
34
|
+
onChange={onChange ?? field.onChange}
|
|
35
|
+
value={value ?? field?.value}
|
|
36
|
+
allowAll={allowAll}
|
|
37
|
+
error={!!error}
|
|
38
|
+
helperText={error?.message}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
)}
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SelectProps } from '@mui/material'
|
|
2
|
+
import { Controller } from 'react-hook-form'
|
|
3
|
+
import ProgramSelector from '../ProgramSelector'
|
|
4
|
+
|
|
5
|
+
type ProgramSelectorProps = {
|
|
6
|
+
control: any
|
|
7
|
+
name: string
|
|
8
|
+
label: string
|
|
9
|
+
required?: boolean
|
|
10
|
+
multiple?: boolean
|
|
11
|
+
allowAll?: boolean
|
|
12
|
+
filters?: { courseId: number }
|
|
13
|
+
onChange?: (value: any) => void
|
|
14
|
+
} & SelectProps
|
|
15
|
+
export default function FormProgramSelector(props: ProgramSelectorProps) {
|
|
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
|
+
<ProgramSelector
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SelectProps } from '@mui/material'
|
|
2
|
+
import { Controller } from 'react-hook-form'
|
|
3
|
+
import QuotaSelector from '../QuotaSelector'
|
|
4
|
+
|
|
5
|
+
type FormQuotaSelectorProps = {
|
|
6
|
+
control: any
|
|
7
|
+
name: string
|
|
8
|
+
label: string
|
|
9
|
+
required?: boolean
|
|
10
|
+
multiple?: boolean
|
|
11
|
+
allowAll?: boolean
|
|
12
|
+
onChange?: (value: any) => void
|
|
13
|
+
filters?: { courseId: number }
|
|
14
|
+
} & SelectProps
|
|
15
|
+
export default function FormQuotaSelector(props: FormQuotaSelectorProps) {
|
|
16
|
+
const {
|
|
17
|
+
name,
|
|
18
|
+
required = false,
|
|
19
|
+
control,
|
|
20
|
+
label,
|
|
21
|
+
allowAll = true,
|
|
22
|
+
multiple = false,
|
|
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
|
+
<QuotaSelector
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SelectProps } from '@mui/material'
|
|
2
|
+
import { Controller } from 'react-hook-form'
|
|
3
|
+
import SemesterSelector from '../SemesterSelector'
|
|
4
|
+
|
|
5
|
+
type SemesterSelectorProps = {
|
|
6
|
+
control: any
|
|
7
|
+
name: string
|
|
8
|
+
label: string
|
|
9
|
+
required?: boolean
|
|
10
|
+
multiple?: boolean
|
|
11
|
+
allowAll?: boolean
|
|
12
|
+
filters?: { courseId: number }
|
|
13
|
+
onChange?: (value: any) => void
|
|
14
|
+
} & SelectProps
|
|
15
|
+
export default function FormSemseterSelector(props: SemesterSelectorProps) {
|
|
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
|
+
<SemesterSelector
|
|
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
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { SelectProps } from '@mui/material'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
import { Controller } from 'react-hook-form'
|
|
4
|
+
import axios from '../../../../config/axios'
|
|
5
|
+
import { MultiSelect } from '../../../Input'
|
|
6
|
+
|
|
7
|
+
type MultiProgramSelectorProps = {
|
|
8
|
+
control: any
|
|
9
|
+
name?: string
|
|
10
|
+
label: string
|
|
11
|
+
filters?: { courseId: number }
|
|
12
|
+
required?: boolean
|
|
13
|
+
onChange?: (value: any) => void
|
|
14
|
+
allowAll?: boolean
|
|
15
|
+
error?: boolean
|
|
16
|
+
helperText?: string
|
|
17
|
+
} & SelectProps
|
|
18
|
+
const MultiProgramSelector = (props: MultiProgramSelectorProps) => {
|
|
19
|
+
const {
|
|
20
|
+
control,
|
|
21
|
+
onChange,
|
|
22
|
+
name,
|
|
23
|
+
required = false,
|
|
24
|
+
label,
|
|
25
|
+
multiple = false,
|
|
26
|
+
filters,
|
|
27
|
+
value,
|
|
28
|
+
allowAll = true,
|
|
29
|
+
} = props
|
|
30
|
+
const [options, setOptions] = useState([])
|
|
31
|
+
const [prevCourseId, setPrevCourseId] = useState(null)
|
|
32
|
+
const handleOpen = () => {
|
|
33
|
+
if (filters) {
|
|
34
|
+
if (filters.courseId && filters.courseId !== prevCourseId) {
|
|
35
|
+
setOptions([])
|
|
36
|
+
axios
|
|
37
|
+
.get('/square/branches', {
|
|
38
|
+
params: filters,
|
|
39
|
+
})
|
|
40
|
+
.then((response) => {
|
|
41
|
+
setOptions(response.data)
|
|
42
|
+
setPrevCourseId(filters.courseId)
|
|
43
|
+
})
|
|
44
|
+
.catch((error) => {
|
|
45
|
+
console.error('Error fetching data from the API:', error)
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
} else if (options.length === 0) {
|
|
49
|
+
axios
|
|
50
|
+
.get('/square/branches')
|
|
51
|
+
.then((response) => {
|
|
52
|
+
setOptions(response.data)
|
|
53
|
+
})
|
|
54
|
+
.catch((error) => {
|
|
55
|
+
console.error('Error fetching data from the API:', error)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (props?.value && props.value != 'all') {
|
|
61
|
+
handleOpen()
|
|
62
|
+
}
|
|
63
|
+
}, [props.value])
|
|
64
|
+
|
|
65
|
+
const handleOptions =
|
|
66
|
+
options.length > 0
|
|
67
|
+
? [
|
|
68
|
+
...(allowAll ? [{ value: 'all', label: 'All' }] : []),
|
|
69
|
+
...options.map((item) => ({
|
|
70
|
+
label: `${item.branchName}`,
|
|
71
|
+
value: `${item.branchCode}`,
|
|
72
|
+
})),
|
|
73
|
+
]
|
|
74
|
+
: allowAll
|
|
75
|
+
? [{ value: 'all', label: 'All' }]
|
|
76
|
+
: []
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<Controller
|
|
80
|
+
name={name}
|
|
81
|
+
control={control}
|
|
82
|
+
render={({ field, fieldState: { error } }) => (
|
|
83
|
+
<MultiSelect
|
|
84
|
+
name={name}
|
|
85
|
+
label={label}
|
|
86
|
+
required={required}
|
|
87
|
+
options={handleOptions}
|
|
88
|
+
onOpen={handleOpen}
|
|
89
|
+
onChange={onChange ?? field.onChange}
|
|
90
|
+
value={value ?? field?.value}
|
|
91
|
+
error={!!error}
|
|
92
|
+
helperText={error?.message}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
/>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
export default MultiProgramSelector
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SelectProps } from '@mui/material'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
import { Controller } from 'react-hook-form'
|
|
4
|
+
import axios from '../../../../config/axios'
|
|
5
|
+
import { MultiSelect } from '../../../Input'
|
|
6
|
+
|
|
7
|
+
type MultiQuotaSelectorProps = {
|
|
8
|
+
control: any
|
|
9
|
+
name?: string
|
|
10
|
+
label: string
|
|
11
|
+
filters?: { courseId: number }
|
|
12
|
+
required?: boolean
|
|
13
|
+
onChange?: (value: any) => void
|
|
14
|
+
allowAll?: boolean
|
|
15
|
+
error?: boolean
|
|
16
|
+
helperText?: string
|
|
17
|
+
} & SelectProps
|
|
18
|
+
export default function MultiQuotaSelector(props: MultiQuotaSelectorProps) {
|
|
19
|
+
const {
|
|
20
|
+
control,
|
|
21
|
+
onChange,
|
|
22
|
+
name,
|
|
23
|
+
required = false,
|
|
24
|
+
label,
|
|
25
|
+
multiple = false,
|
|
26
|
+
filters,
|
|
27
|
+
value,
|
|
28
|
+
allowAll = true,
|
|
29
|
+
} = props
|
|
30
|
+
const [options, setOptions] = useState([])
|
|
31
|
+
const [prevCourseId, setPrevCourseId] = useState(null)
|
|
32
|
+
const handleOpen = () => {
|
|
33
|
+
if (filters) {
|
|
34
|
+
if (filters.courseId && filters.courseId !== prevCourseId) {
|
|
35
|
+
setOptions([])
|
|
36
|
+
axios
|
|
37
|
+
.get('/square/quotas', {
|
|
38
|
+
params: filters,
|
|
39
|
+
})
|
|
40
|
+
.then((response) => {
|
|
41
|
+
setOptions(response.data)
|
|
42
|
+
setPrevCourseId(filters.courseId)
|
|
43
|
+
})
|
|
44
|
+
.catch((error) => {
|
|
45
|
+
console.error('Error fetching data from the API:', error)
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
} else if (options.length === 0) {
|
|
49
|
+
axios
|
|
50
|
+
.get('/square/quotas')
|
|
51
|
+
.then((response) => {
|
|
52
|
+
setOptions(response.data)
|
|
53
|
+
})
|
|
54
|
+
.catch((error) => {
|
|
55
|
+
console.error('Error fetching data from the API:', error)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (props?.value && props.value != 'all') {
|
|
61
|
+
handleOpen()
|
|
62
|
+
}
|
|
63
|
+
}, [props.value])
|
|
64
|
+
const handleOptions =
|
|
65
|
+
options.length > 0
|
|
66
|
+
? [
|
|
67
|
+
...(allowAll ? [{ value: 'all', label: 'All' }] : []),
|
|
68
|
+
...options.map((item) => ({
|
|
69
|
+
label: `${item.name}`,
|
|
70
|
+
value: `${item.id}`,
|
|
71
|
+
})),
|
|
72
|
+
]
|
|
73
|
+
: allowAll
|
|
74
|
+
? [{ value: 'all', label: 'All' }]
|
|
75
|
+
: []
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Controller
|
|
79
|
+
name={name}
|
|
80
|
+
control={control}
|
|
81
|
+
render={({ field, fieldState: { error } }) => (
|
|
82
|
+
<MultiSelect
|
|
83
|
+
name={name}
|
|
84
|
+
label={label}
|
|
85
|
+
required={required}
|
|
86
|
+
options={handleOptions}
|
|
87
|
+
onOpen={handleOpen}
|
|
88
|
+
onChange={onChange ?? field.onChange}
|
|
89
|
+
value={value ?? field?.value}
|
|
90
|
+
error={!!error}
|
|
91
|
+
helperText={error?.message}
|
|
92
|
+
/>
|
|
93
|
+
)}
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
}
|