@campxdev/shared 1.10.66 → 1.10.68

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.66",
3
+ "version": "1.10.68",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -1,23 +1,26 @@
1
1
  import {
2
- alpha,
3
2
  Box,
4
3
  IconButton,
5
4
  ListItemIcon,
6
- styled,
7
5
  Table as MuiTable,
8
6
  TableBody,
9
7
  TableCell,
10
8
  TableContainer,
11
9
  TableHead,
12
10
  TableRow,
11
+ alpha,
12
+ styled,
13
13
  } from '@mui/material'
14
14
  import _ from 'lodash'
15
15
  import { useEffect, useState } from 'react'
16
16
  import Spinner from '../../Spinner'
17
- import { SortAscIcon, SortDescIcon, SortIcon } from '../common/icons'
18
17
  import NoRecordsFound from '../common/NoRecordsFound'
18
+ import { SortAscIcon, SortDescIcon, SortIcon } from '../common/icons'
19
19
  import TableFooter from './TableFooter'
20
20
 
21
+ type Order = 'asc' | 'desc' | ''
22
+ type Sort = {}
23
+ type DataType = 'currency' | 'string' | 'number'
21
24
  export interface ColumnProps {
22
25
  dataIndex: string
23
26
  key: string
@@ -26,8 +29,8 @@ export interface ColumnProps {
26
29
  textColor?: string
27
30
  sort?: boolean
28
31
  width?: string //pixels
32
+ dataType?: DataType
29
33
  }
30
-
31
34
  interface TableProps {
32
35
  columns: Array<ColumnProps>
33
36
  rowKey?: string
@@ -43,11 +46,9 @@ interface TableProps {
43
46
  }
44
47
  onSort?: (sort: any) => void
45
48
  dense?: boolean
49
+ showTotal?: boolean
50
+ isMobile?: boolean
46
51
  }
47
-
48
- type Order = 'asc' | 'desc' | ''
49
- type Sort = {}
50
-
51
52
  export default function Table({
52
53
  columns,
53
54
  dataSource,
@@ -56,8 +57,11 @@ export default function Table({
56
57
  loading,
57
58
  onSort,
58
59
  dense = false,
60
+ showTotal = false,
61
+ isMobile = false,
59
62
  }: TableProps) {
60
63
  const [sort, setSort] = useState<Sort>({})
64
+ let totalCount = []
61
65
 
62
66
  const handleSortClick = (sortBykey) => {
63
67
  setSort((prev) => {
@@ -87,20 +91,45 @@ export default function Table({
87
91
  })
88
92
  }, [sort])
89
93
 
94
+ const calculateTotal = (row) => {
95
+ columns.forEach((col, colIndex) => {
96
+ const colValue = col?.render
97
+ ? col.render(row[col.dataIndex], row, colIndex)
98
+ : _.get(row, col.dataIndex)
99
+
100
+ if (!totalCount[colIndex]) {
101
+ totalCount[colIndex] = 0
102
+ }
103
+
104
+ if (colIndex === 0) {
105
+ totalCount[colIndex] = 'Total'
106
+ return
107
+ }
108
+
109
+ totalCount[colIndex] += colValue
110
+ })
111
+ }
112
+
113
+ const convertToAmount = (data) => {
114
+ return data.toLocaleString('en-IN', {
115
+ style: 'currency',
116
+ currency: 'INR',
117
+ })
118
+ }
119
+
90
120
  return (
91
- <StyledTableContainer>
121
+ <StyledTableContainer isMobile={isMobile}>
92
122
  <>
93
- <MuiTable>
123
+ <StyledMuiTable isMobile={isMobile}>
94
124
  <TableHead>
95
125
  <TableRow>
96
126
  {columns.map((col, index) => (
97
- <TableCell
127
+ <StyledTableCell
98
128
  key={index}
99
- sx={{
100
- ...(col?.width && {
101
- width: col?.width,
102
- }),
103
- }}
129
+ isMobile={isMobile}
130
+ columnsLength={columns.length}
131
+ index={index}
132
+ col={col}
104
133
  >
105
134
  <Box sx={{ fontWeight: 600, fontSize: '14px' }}>
106
135
  {col.title}
@@ -118,7 +147,7 @@ export default function Table({
118
147
  </ListItemIcon>
119
148
  </IconButton>
120
149
  )}
121
- </TableCell>
150
+ </StyledTableCell>
122
151
  ))}
123
152
  </TableRow>
124
153
  </TableHead>
@@ -126,34 +155,72 @@ export default function Table({
126
155
  <>
127
156
  {dataSource?.length ? (
128
157
  <TableBody>
129
- {dataSource?.map((row, index) => (
158
+ {dataSource?.map((row, rowIndex) => (
130
159
  <StyledTableRow
131
160
  canRowClick={!!onRowClick}
132
161
  hover={!!onRowClick}
133
- key={index}
162
+ key={rowIndex}
134
163
  onClick={() => {
135
164
  return onRowClick && onRowClick(row)
136
165
  }}
137
166
  >
167
+ <> {showTotal && calculateTotal(row)}</>
138
168
  {columns.map((col, colIndex) => (
139
- <TableCell
169
+ <StyledTableCell
170
+ key={colIndex}
171
+ isMobile={isMobile}
172
+ columnsLength={columns.length}
173
+ index={colIndex}
174
+ col={col}
140
175
  sx={{
141
176
  color: col.textColor,
142
177
  padding: dense ? '10px' : '15px',
143
178
  font: 'avenir',
144
179
  fontSize: '14px',
145
180
  }}
146
- key={colIndex}
147
181
  >
148
- <>
149
- {col?.render
150
- ? col.render(row[col.dataIndex], row, index)
151
- : _.get(row, col.dataIndex)}
152
- </>
153
- </TableCell>
182
+ {col?.dataType && col?.dataType == 'currency' ? (
183
+ <>{convertToAmount(row[col.dataIndex])}</>
184
+ ) : (
185
+ <>
186
+ {col?.render
187
+ ? col.render(row[col.dataIndex], row, rowIndex)
188
+ : _.get(row, col.dataIndex)}
189
+ </>
190
+ )}
191
+ </StyledTableCell>
154
192
  ))}
155
193
  </StyledTableRow>
156
194
  ))}
195
+
196
+ {showTotal && (
197
+ <StyledTableRow canRowClick={false}>
198
+ {columns.map((col, colIndex) => (
199
+ <>
200
+ <StyledTableCell
201
+ key={colIndex}
202
+ isMobile={isMobile}
203
+ columnsLength={columns.length}
204
+ index={colIndex}
205
+ col={col}
206
+ sx={{
207
+ color: col.textColor,
208
+ padding: dense ? '10px' : '15px',
209
+ font: 'avenir',
210
+ fontSize: '14px',
211
+ fontWeight: '600',
212
+ }}
213
+ >
214
+ {col?.dataType && col?.dataType == 'currency' ? (
215
+ <>{convertToAmount(totalCount[colIndex])}</>
216
+ ) : (
217
+ <>{totalCount[colIndex]}</>
218
+ )}
219
+ </StyledTableCell>
220
+ </>
221
+ ))}
222
+ </StyledTableRow>
223
+ )}
157
224
  </TableBody>
158
225
  ) : (
159
226
  <>
@@ -164,7 +231,7 @@ export default function Table({
164
231
  ) : (
165
232
  <Spinner />
166
233
  )}
167
- </MuiTable>
234
+ </StyledMuiTable>
168
235
  </>
169
236
  <>
170
237
  {pagination && (
@@ -181,11 +248,37 @@ export default function Table({
181
248
  )
182
249
  }
183
250
 
184
- const StyledTableContainer = styled(TableContainer)(({ theme }) => ({
185
- width: '100%',
186
- overflowX: 'auto',
251
+ const StyledTableContainer = styled(TableContainer)<{ isMobile: boolean }>(
252
+ ({ theme, isMobile }) => ({
253
+ width: '100%',
254
+ overflowX: 'auto',
255
+ borderRadius: isMobile ? '10px 10px 10px 10px' : 'none',
256
+ border: isMobile ? '1px solid #1212121A' : 'none',
257
+ }),
258
+ )
259
+
260
+ const StyledTableCell = styled(TableCell)<{
261
+ isMobile: boolean
262
+ columnsLength: number
263
+ index: number
264
+ col: any
265
+ sx?: any
266
+ }>(({ theme, isMobile, columnsLength, index, col, sx }) => ({
267
+ ...(col?.width && {
268
+ width: col?.width,
269
+ }),
270
+ borderRightColor:
271
+ isMobile && columnsLength - 1 !== index ? '#1212121A' : 'none',
272
+ borderRightStyle: isMobile && columnsLength - 1 !== index ? 'solid' : 'none',
273
+ ...sx,
187
274
  }))
188
275
 
276
+ const StyledMuiTable = styled(MuiTable)<{ isMobile: boolean }>(
277
+ ({ theme, isMobile }) => ({
278
+ border: isMobile ? 'none' : '1px solid #1212121A',
279
+ }),
280
+ )
281
+
189
282
  const StyledTableRow = styled(TableRow, {
190
283
  shouldForwardProp: (prop) => prop !== 'canRowClick',
191
284
  })<{ canRowClick: boolean }>(({ canRowClick }) => ({
@@ -60,7 +60,6 @@ export { default as Spinner } from './Spinner'
60
60
  export { default as SwitchButton } from './SwitchButton'
61
61
  export { default as Table } from './Tables/BasicTable'
62
62
  export { default as TableFooter } from './Tables/BasicTable/TableFooter'
63
- export { default as MobileTable } from './Tables/MobileTable'
64
63
  export { default as ReactTable } from './Tables/ReactTable'
65
64
  export { default as Tabs } from './Tabs/Tabs'
66
65
  export { default as ToastContainer } from './ToastContainer'
@@ -749,13 +749,17 @@ export enum Permission {
749
749
  STUDENTS_ALLOTMENT = 'can_students_allotment',
750
750
  STUDENT_INFO_VIEW = 'can_student_info_view',
751
751
 
752
- //EmailReportCronJobs
753
- EMAIL_REPORT_CRON_JOBS_VIEW='can_email_report_cron_jobs_view',
754
- EMAIL_REPORT_CRON_JOBS_ADD='can_email_report_cron_jobs_add',
755
- EMAIL_REPORT_CRON_JOBS_EDIT='can_email_report_cron_jobs_edit',
756
- EMAIL_REPORT_CRON_JOBS_DELETE='can_email_report_cron_jobs_delete',
757
-
752
+ // Student Certificate
753
+ CAN_STUDENT_CERTIFICATES_VIEW = 'can_student_certificates_view',
754
+ CAN_STUDENT_CERTIFICATES_EDIT = 'can_student_certificates_edit',
755
+ CAN_STUDENT_CERTIFICATES_DELETE = 'can_student_certificates_delete',
756
+ CAN_STUDENT_CERTIFICATES_ADD = 'can_student_certificates_add',
758
757
 
758
+ //EmailReportCronJobs
759
+ EMAIL_REPORT_CRON_JOBS_VIEW = 'can_email_report_cron_jobs_view',
760
+ EMAIL_REPORT_CRON_JOBS_ADD = 'can_email_report_cron_jobs_add',
761
+ EMAIL_REPORT_CRON_JOBS_EDIT = 'can_email_report_cron_jobs_edit',
762
+ EMAIL_REPORT_CRON_JOBS_DELETE = 'can_email_report_cron_jobs_delete',
759
763
 
760
764
  // Subjects
761
765
  SUBJECTS_VIEW = 'can_subjects_view',
@@ -793,6 +797,10 @@ export enum Permission {
793
797
  CAN_CLASSROOM_SESSION_EDIT = 'can_classroom_session_edit',
794
798
  CAN_CLASSROOM_SESSION_DELETE = 'can_classroom_session_delete',
795
799
 
800
+ CAN_CLASSROOM_SUBJECT_ASSESSMENT_CREATE = 'can_classroom_subject_assessment_create',
801
+ CAN_CLASSROOM_SUBJECT_ASSESSMENT_DELETE = 'can_classroom_subject_assessment_delete',
802
+ CAN_CLASSROOM_SUBJECT_ASSESSMENT_LINK_EXAM = 'can_classroom_subject_assessment_link_exam',
803
+
796
804
  // Institution
797
805
  CAN_INSTITUTION_VIEW = 'can_institutions_view',
798
806
  CAN_INSTITUTION_EDIT = 'can_institutions_edit',
@@ -1,218 +0,0 @@
1
- import {
2
- Box,
3
- IconButton,
4
- ListItemIcon,
5
- Table as MuiTable,
6
- TableBody,
7
- TableCell,
8
- TableContainer,
9
- TableHead,
10
- TableRow,
11
- alpha,
12
- styled,
13
- } from '@mui/material'
14
- import _ from 'lodash'
15
- import { useEffect, useState } from 'react'
16
- import Spinner from '../../Spinner'
17
- import TableFooter from '../BasicTable/TableFooter'
18
- import NoRecordsFound from '../common/NoRecordsFound'
19
- import { SortAscIcon, SortDescIcon, SortIcon } from '../common/icons'
20
-
21
- export interface ColumnProps {
22
- dataIndex: string
23
- key: string
24
- title: any
25
- render?: (cellData: any, row: any, index: number) => any
26
- textColor?: string
27
- sort?: boolean
28
- width?: string //pixels
29
- }
30
-
31
- interface TableProps {
32
- columns: Array<ColumnProps>
33
- rowKey?: string
34
- dataSource?: any[]
35
- loading?: boolean
36
- onRowClick?: (row: any) => void
37
- pagination?: {
38
- page: number
39
- limit: number
40
- totalCount: number
41
- onChange: (v: number) => void
42
- onChangeLimit?: (v: number) => void
43
- }
44
- onSort?: (sort: any) => void
45
- dense?: boolean
46
- isLastRowColorChange?: boolean
47
- }
48
-
49
- type Order = 'asc' | 'desc' | ''
50
- type Sort = {}
51
-
52
- export default function MobileTable({
53
- columns,
54
- dataSource,
55
- onRowClick,
56
- pagination,
57
- loading,
58
- onSort,
59
- dense = false,
60
- isLastRowColorChange = false,
61
- }: TableProps) {
62
- const [sort, setSort] = useState<Sort>({})
63
-
64
- const handleSortClick = (sortBykey) => {
65
- setSort((prev) => {
66
- if (prev[sortBykey]) {
67
- if (prev[sortBykey] === 'desc') return { ...prev, [sortBykey]: 'asc' }
68
- if (prev[sortBykey] === 'asc') {
69
- delete prev[sortBykey]
70
- return { ...prev }
71
- }
72
- } else {
73
- return {
74
- ...prev,
75
- [sortBykey]: 'desc',
76
- }
77
- }
78
- })
79
- }
80
-
81
- useEffect(() => {
82
- if (!onSort) return
83
-
84
- onSort({
85
- sortBy: Object.keys(sort).join(','),
86
- sortOrder: Object.keys(sort)
87
- .map((item) => sort[item])
88
- .join(','),
89
- })
90
- }, [sort])
91
-
92
- return (
93
- <StyledTableContainer>
94
- <>
95
- <StyledMuiTable>
96
- <TableHead>
97
- <TableRow>
98
- {columns.map((col, index) => (
99
- <TableCell
100
- key={index}
101
- sx={{
102
- ...(col?.width && {
103
- width: col?.width,
104
- }),
105
- borderRightColor: '#1212121A',
106
- borderRightStyle: 'solid',
107
- }}
108
- >
109
- <Box sx={{ fontWeight: 500, fontSize: '14px' }}>
110
- {col.title}
111
- </Box>
112
- {col.sort && (
113
- <IconButton onClick={() => handleSortClick(col.dataIndex)}>
114
- <ListItemIcon>
115
- {sort[col.dataIndex] === 'asc' ? (
116
- <SortAscIcon />
117
- ) : sort[col.dataIndex] === 'desc' ? (
118
- <SortDescIcon />
119
- ) : (
120
- <SortIcon />
121
- )}
122
- </ListItemIcon>
123
- </IconButton>
124
- )}
125
- </TableCell>
126
- ))}
127
- </TableRow>
128
- </TableHead>
129
- {!loading ? (
130
- <>
131
- {dataSource?.length ? (
132
- <TableBody>
133
- {dataSource?.map((row, index) => (
134
- <StyledTableRow
135
- canRowClick={!!onRowClick}
136
- hover={!!onRowClick}
137
- key={index}
138
- onClick={() => {
139
- return onRowClick && onRowClick(row)
140
- }}
141
- isLastRowColorChange={isLastRowColorChange}
142
- >
143
- {columns.map((col, colIndex) => (
144
- <TableCell
145
- sx={{
146
- color: col.textColor,
147
- padding: dense ? '10px' : '15px',
148
- font: 'avenir',
149
- fontSize: '14px',
150
- borderRightColor: '#1212121A',
151
- borderRightStyle: 'solid',
152
- }}
153
- key={colIndex}
154
- >
155
- <>
156
- {col?.render
157
- ? col.render(row[col.dataIndex], row, index)
158
- : _.get(row, col.dataIndex)}
159
- </>
160
- </TableCell>
161
- ))}
162
- </StyledTableRow>
163
- ))}
164
- </TableBody>
165
- ) : (
166
- <>
167
- <NoRecordsFound colLength={columns?.length} />
168
- </>
169
- )}
170
- </>
171
- ) : (
172
- <Spinner />
173
- )}
174
- </StyledMuiTable>
175
- </>
176
- <>
177
- {pagination && (
178
- <TableFooter
179
- page={pagination.page + 1}
180
- limit={pagination.limit}
181
- totalCount={pagination.totalCount ?? 0}
182
- handlePagination={pagination.onChange}
183
- handlePageLimit={pagination.onChangeLimit}
184
- />
185
- )}
186
- </>
187
- </StyledTableContainer>
188
- )
189
- }
190
-
191
- const StyledTableContainer = styled(TableContainer)<{}>(({ theme }) => ({
192
- width: '100%',
193
- overflowX: 'auto',
194
- borderRadius: '10px 10px 10px 10px',
195
- border: '1px solid #1212121A',
196
- }))
197
-
198
- const StyledMuiTable = styled(MuiTable)<{}>(({ theme }) => ({
199
- border: 'none',
200
- }))
201
-
202
- const StyledTableRow = styled(TableRow, {
203
- shouldForwardProp: (prop) => prop !== 'canRowClick',
204
- })<{ canRowClick: boolean; isLastRowColorChange?: boolean }>(
205
- ({ canRowClick, isLastRowColorChange }) => ({
206
- ...(canRowClick && {
207
- cursor: 'pointer',
208
- '&.MuiTableRow-hover:hover': {
209
- backgroundColor: alpha('#f2f2f2', 0.4),
210
- },
211
- }),
212
- ...(isLastRowColorChange && {
213
- '&:last-child': {
214
- backgroundColor: '#F2F2F2',
215
- },
216
- }),
217
- }),
218
- )
@@ -1 +0,0 @@
1
- export { default } from './MobileTable'