@campxdev/shared 1.10.76 → 1.10.78

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 (25) hide show
  1. package/package.json +1 -1
  2. package/src/components/Input/MultiSelect.tsx +0 -1
  3. package/src/components/MyProfile/Education/EducationForm.tsx +14 -12
  4. package/src/components/MyProfile/Experience/ExperienceForm.tsx +21 -14
  5. package/src/components/MyProfile/MyProfile.tsx +2 -3
  6. package/src/components/MyProfile/PaperPublication/Authors.tsx +47 -51
  7. package/src/components/MyProfile/PaperPublication/PublicationsForm.tsx +8 -5
  8. package/src/components/MyProfile/PaperPublication/Styles.tsx +8 -1
  9. package/src/components/MyProfile/ResearchProjects/ResearchProjects.tsx +25 -38
  10. package/src/components/MyProfile/Workshop/WorkshopForm.tsx +14 -12
  11. package/src/components/Selectors/ClassRoomSelector.tsx +97 -0
  12. package/src/components/Selectors/CourseSelector.tsx +4 -2
  13. package/src/components/Selectors/DepartmentSelector.tsx +67 -0
  14. package/src/components/Selectors/FacultySelector.tsx +92 -0
  15. package/src/components/Selectors/FormSelectors/FormClassRoomSelector.tsx +50 -0
  16. package/src/components/Selectors/FormSelectors/FormCourseSelector.tsx +3 -0
  17. package/src/components/Selectors/FormSelectors/FormDepartmentSelector.tsx +49 -0
  18. package/src/components/Selectors/FormSelectors/FormFacultySelector.tsx +55 -0
  19. package/src/components/Selectors/FormSelectors/FormProgramSelector.tsx +4 -1
  20. package/src/components/Selectors/FormSelectors/MultiSelect/MultiFacultySelector.tsx +106 -0
  21. package/src/components/Selectors/ProgramSelector.tsx +4 -2
  22. package/src/components/Selectors/index.tsx +14 -0
  23. package/src/components/Tables/2DTable/Table.tsx +42 -34
  24. package/src/permissions/PermissionsStore.ts +356 -0
  25. package/src/shared-state/PermissionsStore.ts +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.10.76",
3
+ "version": "1.10.78",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -90,7 +90,6 @@ interface MultiSelectProps {
90
90
  onOpen?: (e: any) => void
91
91
  noOptionsText?: string
92
92
  }
93
-
94
93
  export default function MultiSelect({
95
94
  name,
96
95
  options,
@@ -82,18 +82,20 @@ export const EducationForm = ({ data, hideDialog }) => {
82
82
  label="Institution"
83
83
  required
84
84
  />
85
- <FormDatePicker
86
- control={control}
87
- name="startDate"
88
- label="From Date"
89
- required
90
- />
91
- <FormDatePicker
92
- control={control}
93
- name="endDate"
94
- label="To Date"
95
- required
96
- />
85
+ <Stack direction="row" gap={2}>
86
+ <FormDatePicker
87
+ control={control}
88
+ name="startDate"
89
+ label="From Date"
90
+ required
91
+ />
92
+ <FormDatePicker
93
+ control={control}
94
+ name="endDate"
95
+ label="To Date"
96
+ required
97
+ />
98
+ </Stack>
97
99
  <FormTextField
98
100
  control={control}
99
101
  multiline
@@ -17,10 +17,14 @@ import {
17
17
  import { createUpdateExperience } from '../service'
18
18
 
19
19
  const schema = yup.object().shape({
20
- experienceType: yup.string().required('Experience Type is required'),
20
+ experienceType: yup.string().required('Experience type is required'),
21
21
  title: yup.string().required('Title is required'),
22
- organizationName: yup.string().required('Organization Name is required'),
23
- fromDate: yup.string().required('FromDate is Required'),
22
+ organizationName: yup.string().required('Organization name is required'),
23
+ fromDate: yup.string().required('From date is Required'),
24
+ toDate: yup.string().when('currentlyWorking', {
25
+ is: (val) => !val,
26
+ then: yup.string().required('To date is Required'),
27
+ }),
24
28
  })
25
29
 
26
30
  export const ExperienceForm = ({ data, hideDialog }) => {
@@ -63,6 +67,7 @@ export const ExperienceForm = ({ data, hideDialog }) => {
63
67
  }
64
68
  const selectedType = watch('experienceType')
65
69
  const currentlyWorking = watch('currentlyWorking')
70
+ const isEmploymentType = selectedType === 'Employment'
66
71
 
67
72
  return (
68
73
  <form onSubmit={handleSubmit(onSubmit, onError)}>
@@ -82,7 +87,7 @@ export const ExperienceForm = ({ data, hideDialog }) => {
82
87
  <FormTextField
83
88
  control={control}
84
89
  name="title"
85
- label="Title"
90
+ label={isEmploymentType ? 'Job Title' : `${selectedType} Title`}
86
91
  required
87
92
  />
88
93
  <FormTextField
@@ -96,20 +101,22 @@ export const ExperienceForm = ({ data, hideDialog }) => {
96
101
  name="currentlyWorking"
97
102
  label="Currently Working"
98
103
  />
99
- <FormDatePicker
100
- control={control}
101
- name="fromDate"
102
- label="From"
103
- required
104
- />
105
- {!currentlyWorking && (
104
+ <Stack direction="row" gap={2}>
106
105
  <FormDatePicker
107
106
  control={control}
108
- name="toDate"
109
- label="To"
107
+ name="fromDate"
108
+ label="From"
110
109
  required
111
110
  />
112
- )}
111
+ {!currentlyWorking && (
112
+ <FormDatePicker
113
+ control={control}
114
+ name="toDate"
115
+ label="To"
116
+ required
117
+ />
118
+ )}
119
+ </Stack>
113
120
 
114
121
  <FormTextField
115
122
  control={control}
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-console */
2
1
  import { Box, Chip, Container, Typography } from '@mui/material'
3
2
  import { useQuery } from 'react-query'
4
3
  import axios from '../../config/axios'
@@ -31,7 +30,7 @@ const MyProfile = ({ close }) => {
31
30
  const { data: classroomSubjects } = useQuery('classroom-subjects', () =>
32
31
  axios.get('/square/subjects/faculty').then((res) => res?.data),
33
32
  )
34
- const { data: ResearchProject } = useQuery('research-projects', () =>
33
+ const { data: researchProject } = useQuery('research-projects', () =>
35
34
  axios.get('/square/research-projects').then((res) => res?.data),
36
35
  )
37
36
 
@@ -71,7 +70,7 @@ const MyProfile = ({ close }) => {
71
70
  {
72
71
  key: 'research projects',
73
72
  label: 'Research Projects',
74
- component: <ResearchProjects ResearchProject={ResearchProject} />,
73
+ component: <ResearchProjects researchProject={researchProject} />,
75
74
  },
76
75
  ]
77
76
  function Years(num) {
@@ -1,11 +1,18 @@
1
- /* eslint-disable react/jsx-key */
2
- import { Box, Button } from '@mui/material'
1
+ import { Box, Button, Chip } from '@mui/material'
3
2
  import { useFieldArray } from 'react-hook-form'
4
3
  import { FormTextField } from '../../HookForm'
5
4
  import { RadioGroup } from '../../Input'
6
- import { StyledBox, StyledDeleteButton, StyledStack } from './Styles'
5
+ import { StyledGrid, StyledStack } from './Styles'
7
6
 
8
- const Authors = ({ control, selectedAuthor, setState, authorsSelect }) => {
7
+ const Authors = ({
8
+ control,
9
+ selectedAuthor,
10
+ setState,
11
+ authorsSelect,
12
+ userName,
13
+ watch,
14
+ setValue,
15
+ }) => {
9
16
  const { fields, append, remove } = useFieldArray({
10
17
  control,
11
18
  name: 'authors',
@@ -29,56 +36,45 @@ const Authors = ({ control, selectedAuthor, setState, authorsSelect }) => {
29
36
  })
30
37
  }}
31
38
  />
39
+ {selectedAuthor === 'singleAuthor' && (
40
+ <Box sx={{ marginTop: 1 }}>
41
+ <Chip variant="outlined" color="primary" label={userName} disabled />
42
+ </Box>
43
+ )}
32
44
  {selectedAuthor === 'multipleAuthors' && (
33
45
  <Box>
34
- {!fields.length && (
35
- <StyledBox>
36
- <Button
37
- variant="text"
38
- color="primary"
39
- size="small"
40
- onClick={() => {
41
- append({ name: '' })
42
- }}
43
- >
44
- Add Author
45
- </Button>
46
- </StyledBox>
47
- )}
46
+ <StyledStack direction={'row'} gap={1}>
47
+ <FormTextField
48
+ control={control}
49
+ name="newAuthor"
50
+ label="Author Name"
51
+ required
52
+ />
53
+ <Button
54
+ variant="text"
55
+ color="primary"
56
+ size="small"
57
+ onClick={() => {
58
+ append({ name: watch('newAuthor') })
59
+ setValue('newAuthor', '')
60
+ }}
61
+ >
62
+ + Add
63
+ </Button>
64
+ </StyledStack>
48
65
 
49
- {fields && (
50
- <>
51
- <StyledBox>
52
- <Button
53
- variant="text"
54
- color="primary"
55
- size="small"
56
- onClick={() => {
57
- append({ name: '' })
58
- }}
59
- >
60
- Add Author
61
- </Button>
62
- </StyledBox>
63
- {fields.map((author, index) => (
64
- <StyledStack
65
- direction={'row'}
66
- gap={2}
67
- sx={{ alignItems: 'flex-end' }}
68
- >
69
- <FormTextField
70
- control={control}
71
- name={`authors[${index}].name`}
72
- label="Details about Authors"
73
- required
74
- />
75
- {index > 0 && (
76
- <StyledDeleteButton onClick={() => remove(index)} />
77
- )}
78
- </StyledStack>
79
- ))}
80
- </>
81
- )}
66
+ <StyledGrid>
67
+ {fields.map((author: any, index) => (
68
+ <Chip
69
+ key={author.id}
70
+ variant="outlined"
71
+ color="primary"
72
+ label={author.name}
73
+ onDelete={index === 0 ? null : () => remove(index)}
74
+ disabled={index === 0}
75
+ />
76
+ ))}
77
+ </StyledGrid>
82
78
  </Box>
83
79
  )}
84
80
  </Box>
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-console */
2
2
  import { yupResolver } from '@hookform/resolvers/yup'
3
- import { Stack, Typography } from '@mui/material'
3
+ import { Stack } from '@mui/material'
4
4
  import { useEffect, useState } from 'react'
5
5
  import { useForm } from 'react-hook-form'
6
6
  import { useMutation, useQuery } from 'react-query'
@@ -34,7 +34,10 @@ const authorsSelect = [
34
34
  const schema = yup.object().shape({
35
35
  title: yup.string().required('Title is required'),
36
36
  publicationType: yup.string().required('Publication Type is required'),
37
- publicationYear: yup.number().required('Year of Publication is required'),
37
+ publicationYear: yup
38
+ .number()
39
+ .typeError('Year of Publication must be a number')
40
+ .required('Year of Publication is required'),
38
41
  stream: yup.string().required('Stream is required'),
39
42
  program: yup.string().required('Program is required'),
40
43
  })
@@ -123,7 +126,6 @@ export const PublicationsForm = ({ data, hideDialog, userProfile = null }) => {
123
126
  }, [data, setValue])
124
127
 
125
128
  const onSubmit = (formData) => {
126
- console.log(formData, 'formDaa')
127
129
  const isOthers = formData.publicationType === 'Other'
128
130
  const postBody = {
129
131
  ...formData,
@@ -138,7 +140,6 @@ export const PublicationsForm = ({ data, hideDialog, userProfile = null }) => {
138
140
  image: media[0]?.key || null,
139
141
  attachments: state.resource.map((file) => file.key),
140
142
  }
141
- console.log(postBody, 'postBody')
142
143
  mutate(postBody)
143
144
  }
144
145
 
@@ -210,9 +211,11 @@ export const PublicationsForm = ({ data, hideDialog, userProfile = null }) => {
210
211
  selectedAuthor={selectedAuthor}
211
212
  setState={setState}
212
213
  authorsSelect={authorsSelect}
214
+ userName={userProfile?.fullName}
215
+ watch={watch}
216
+ setValue={setValue}
213
217
  />
214
218
 
215
- <Typography variant="h5">{userProfile?.fullName}</Typography>
216
219
  <FormSingleSelect
217
220
  name="publicationType"
218
221
  label="Publication Type"
@@ -46,6 +46,13 @@ export const StyledDeleteButton = styled(DeleteButton)({
46
46
  })
47
47
 
48
48
  export const StyledStack = styled(Stack)({
49
- alignItems: 'center',
49
+ alignItems: 'flex-end',
50
50
  justifyContent: 'space-between',
51
51
  })
52
+
53
+ export const StyledGrid = styled(Stack)({
54
+ display: 'grid',
55
+ gridTemplateColumns: 'repeat(auto-fill, minmax(120px, max-content))',
56
+ gap: '10px',
57
+ marginTop: '10px',
58
+ })
@@ -3,52 +3,39 @@ import StyledTabsContainer from '../StyledTabsContainer'
3
3
  import ResearchProjectData from './ResearchProjectData'
4
4
  import ResearchProjectForm from './ResearchProjectForm'
5
5
 
6
- function ResearchProjects({ ResearchProject }) {
7
- const test = []
8
- const Research = true
9
- const Ongoing = ResearchProject?.filter(
10
- (project) => project?.projectStatus == 'ongoing',
11
- )
12
- const Completed = test?.filter(
13
- (project) => project?.projectStatus == 'completed',
14
- )
15
-
6
+ function ResearchProjects({ researchProject }) {
16
7
  const tabs = [
17
8
  {
18
- key: 'Ongoing',
19
- label: 'Ongoing',
20
- component: (
21
- <ResearchProjectData title={'Ongoing'} ResearchProject={Ongoing} />
22
- ),
23
- },
24
- {
25
- key: 'Completed',
26
- label: 'Completed',
9
+ key: 'ResearchProject',
10
+ label: 'Research Project',
27
11
  component: (
28
- <ResearchProjectData title={'Completed'} ResearchProject={Completed} />
12
+ <ResearchProjectData
13
+ title={'Research Project'}
14
+ ResearchProject={researchProject}
15
+ />
29
16
  ),
30
17
  },
31
18
  ]
32
- return (
19
+ const isResearchProject = researchProject && researchProject?.length > 0
20
+
21
+ return isResearchProject ? (
33
22
  <>
34
- {Research ? (
35
- <StyledTabsContainer
36
- tabs={tabs}
37
- centered
38
- textColor="primary"
39
- indicatorBackgroundColor="primary"
40
- />
41
- ) : (
42
- <NoDataSection
43
- title="ResearchProjects"
44
- subtitle="Add ResearchProjects"
45
- addButtonTitle="Add Your ResearchProjects"
46
- addButtonContent={({ close }) => (
47
- <ResearchProjectForm close={close} data={[]} />
48
- )}
49
- />
50
- )}
23
+ <StyledTabsContainer
24
+ tabs={tabs}
25
+ centered
26
+ textColor="primary"
27
+ indicatorBackgroundColor="primary"
28
+ />
51
29
  </>
30
+ ) : (
31
+ <NoDataSection
32
+ title="Research Project"
33
+ subtitle="Add Research Project"
34
+ addButtonTitle="Add Your Research Project"
35
+ addButtonContent={({ close }) => (
36
+ <ResearchProjectForm data={null} close={close} />
37
+ )}
38
+ />
52
39
  )
53
40
  }
54
41
 
@@ -171,18 +171,20 @@ export const WorkshopForm = ({ data, hideDialog }) => {
171
171
  label="Organization"
172
172
  required
173
173
  />
174
- <FormDatePicker
175
- control={control}
176
- name="fromDate"
177
- label="From Date"
178
- required
179
- />
180
- <FormDatePicker
181
- control={control}
182
- name="toDate"
183
- label="To Date"
184
- required
185
- />
174
+ <Stack direction="row" gap={2}>
175
+ <FormDatePicker
176
+ control={control}
177
+ name="fromDate"
178
+ label="From Date"
179
+ required
180
+ />
181
+ <FormDatePicker
182
+ control={control}
183
+ name="toDate"
184
+ label="To Date"
185
+ required
186
+ />
187
+ </Stack>
186
188
  <FormTextField
187
189
  control={control}
188
190
  name="stream"
@@ -0,0 +1,97 @@
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 ClassRoomSelectorProps = {
7
+ name?: string
8
+ label: string
9
+ filters?: { programId: number; courseId: number; batch: string }
10
+ required?: boolean
11
+ onChange?: (value: any) => void
12
+ allowAll?: boolean
13
+ error?: boolean
14
+ helperText?: string
15
+ api?: string
16
+ } & SelectProps
17
+ const ClassRoomSelector = (props: ClassRoomSelectorProps) => {
18
+ const {
19
+ name,
20
+ required = false,
21
+ label,
22
+ multiple = false,
23
+ filters,
24
+ allowAll = true,
25
+ api = '/square/classrooms/filters',
26
+ } = props
27
+ const [options, setOptions] = useState([])
28
+ const [prevProgramId, setPrevProgramId] = useState(null)
29
+ const [prevBatch, setPrevBatch] = useState(null)
30
+ const [prevCourseId, setPrevCourseId] = useState(null)
31
+ const handleOpen = () => {
32
+ if (filters) {
33
+ if (
34
+ (filters?.programId && filters?.programId !== prevProgramId) ||
35
+ (filters?.batch &&
36
+ filters?.batch !== prevBatch &&
37
+ filters?.programId) ||
38
+ (filters?.courseId && filters?.courseId !== prevCourseId)
39
+ ) {
40
+ setOptions([])
41
+ axios
42
+ .get(api, {
43
+ params: filters,
44
+ })
45
+ .then((response) => {
46
+ setOptions(response.data)
47
+ setPrevProgramId(filters.programId)
48
+ setPrevBatch(filters.batch)
49
+ setPrevCourseId(filters.courseId)
50
+ })
51
+ .catch((error) => {
52
+ console.error('Error fetching data from the API:', error)
53
+ })
54
+ }
55
+ } else if (options.length === 0) {
56
+ axios
57
+ .get(api)
58
+ .then((response) => {
59
+ setOptions(response.data)
60
+ })
61
+ .catch((error) => {
62
+ console.error('Error fetching data from the API:', error)
63
+ })
64
+ }
65
+ }
66
+ useEffect(() => {
67
+ if (props?.value && props.value != 'all') {
68
+ handleOpen()
69
+ }
70
+ }, [props.value])
71
+
72
+ const handleOptions =
73
+ options.length > 0
74
+ ? [
75
+ ...(allowAll ? [{ value: 'all', label: 'All' }] : []),
76
+ ...options.map((item) => ({
77
+ label: `${item.name}`,
78
+ value: `${item.id}`,
79
+ })),
80
+ ]
81
+ : allowAll
82
+ ? [{ value: 'all', label: 'All' }]
83
+ : []
84
+
85
+ return (
86
+ <SingleSelect
87
+ name={name}
88
+ label={label}
89
+ required={required}
90
+ options={handleOptions}
91
+ onOpen={handleOpen}
92
+ defaultValue="all"
93
+ {...props}
94
+ />
95
+ )
96
+ }
97
+ export default ClassRoomSelector
@@ -12,6 +12,7 @@ type CourseSelectorProps = {
12
12
  error?: boolean
13
13
  helperText?: string
14
14
  api?: string
15
+ valueByUniqueId?: boolean
15
16
  } & SelectProps
16
17
  export default function CourseSelector(props: CourseSelectorProps) {
17
18
  const {
@@ -20,7 +21,8 @@ export default function CourseSelector(props: CourseSelectorProps) {
20
21
  label,
21
22
  onChange,
22
23
  allowAll = true,
23
- api = '/square/courses',
24
+ valueByUniqueId = false,
25
+ api = '/paymentx/domain/courses',
24
26
  } = props
25
27
  const [options, setOptions] = useState([])
26
28
 
@@ -47,7 +49,7 @@ export default function CourseSelector(props: CourseSelectorProps) {
47
49
  ...(allowAll ? [{ value: 'all', label: 'All' }] : []),
48
50
  ...options.map((item) => ({
49
51
  label: `${item.courseName} `,
50
- value: `${item.id}`,
52
+ value: !valueByUniqueId ? `${item.id}` : `${item.uniqueId}`,
51
53
  })),
52
54
  ]
53
55
  : allowAll
@@ -0,0 +1,67 @@
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 DepartmentSelectorProps = {
7
+ name?: string
8
+ label: string
9
+ required?: boolean
10
+ onChange?: (value: any) => void
11
+ allowAll?: boolean
12
+ error?: boolean
13
+ helperText?: string
14
+ api?: string
15
+ } & SelectProps
16
+ export default function DepartmentSelector(props: DepartmentSelectorProps) {
17
+ const {
18
+ name,
19
+ required = false,
20
+ label,
21
+ onChange,
22
+ allowAll = true,
23
+ api = '/hrms/departments',
24
+ } = props
25
+ const [options, setOptions] = useState([])
26
+
27
+ const handleOpen = () => {
28
+ if (options.length === 0) {
29
+ axios
30
+ .get(api)
31
+ .then((response) => {
32
+ setOptions(response.data.data)
33
+ })
34
+ .catch((error) => {
35
+ console.error('Error fetching data from the API:', error)
36
+ })
37
+ }
38
+ }
39
+ useEffect(() => {
40
+ if (props?.value && props.value != 'all') {
41
+ handleOpen()
42
+ }
43
+ }, [props.value])
44
+ const handleOptions =
45
+ options.length > 0
46
+ ? [
47
+ ...(allowAll ? [{ value: 'all', label: 'All' }] : []),
48
+ ...options.map((item) => ({
49
+ label: `${item.name} `,
50
+ value: `${item._id}`,
51
+ })),
52
+ ]
53
+ : allowAll
54
+ ? [{ value: 'all', label: 'All' }]
55
+ : []
56
+
57
+ return (
58
+ <SingleSelect
59
+ name={name}
60
+ label={label}
61
+ required={required}
62
+ options={handleOptions}
63
+ onOpen={handleOpen}
64
+ {...props}
65
+ />
66
+ )
67
+ }