You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

228 regels
7.7 KiB

  1. // material-ui
  2. import * as React from 'react';
  3. import {
  4. DataGrid,
  5. GridActionsCellItem,
  6. } from "@mui/x-data-grid";
  7. import EditIcon from '@mui/icons-material/Edit';
  8. import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
  9. import {useContext, useEffect} from "react";
  10. import {useNavigate} from "react-router-dom";
  11. import {CustomNoRowsOverlay, dateComparator, getDateString} from "../../../utils/CommonFunction";
  12. import AbilityContext from "../../../components/AbilityProvider";
  13. import {LIONER_BUTTON_THEME} from "../../../themes/colorConst";
  14. import {ThemeProvider} from "@emotion/react";
  15. // ==============================|| CLIENT TABLE ||============================== //
  16. export default function ClientTable({recordList}) {
  17. const [rows, setRows] = React.useState(recordList);
  18. const [rowModesModel] = React.useState({});
  19. const navigate = useNavigate()
  20. const ability = useContext(AbilityContext);
  21. const [paginationModel, setPaginationModel] = React.useState({
  22. page: 0,
  23. pageSize:10
  24. });
  25. useEffect(() => {
  26. setPaginationModel({page:0,pageSize:10});
  27. setRows(recordList);
  28. }, [recordList]);
  29. const handleEditClick = (id) => () => {
  30. navigate('/client/maintain/'+ id);
  31. };
  32. const handlePdfClick = (id) => () => {
  33. navigate(`/pdf/${id}`);
  34. };
  35. const columns = [
  36. {
  37. field: 'actions',
  38. type: 'actions',
  39. headerName: 'Actions',
  40. // flex: 0.5,
  41. width: 100,
  42. cellClassName: 'actions',
  43. getActions: ({id}) => {
  44. return [
  45. <ThemeProvider key="OutSave" theme={LIONER_BUTTON_THEME}>
  46. <GridActionsCellItem
  47. icon={<EditIcon sx={{fontSize: 25}}/>}
  48. label="Edit"
  49. className="textPrimary"
  50. onClick={handleEditClick(id)}
  51. color="edit"
  52. // disabled={'true'}
  53. // disabled={!ability.can('VIEW','DASHBOARD')}
  54. />
  55. <GridActionsCellItem
  56. icon={<PictureAsPdfIcon sx={{fontSize: 25}}/>}
  57. label="Edit PDF"
  58. className="textPrimary"
  59. onClick={handlePdfClick(id)}
  60. color="edit"
  61. // disabled={'true'}
  62. // disabled={!ability.can('VIEW','DASHBOARD')}
  63. />
  64. </ThemeProvider>
  65. ]
  66. },
  67. },
  68. // {
  69. // id: 'title',
  70. // field: 'title',
  71. // headerName: 'Title',
  72. // // sortComparator: dateComparator,
  73. // flex: 0.75,
  74. // renderCell: (params) => (
  75. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  76. // {params.value}
  77. // </div>
  78. // // <div>
  79. // // {getDateString(params.row.clientFrom,false)}
  80. // // </div>
  81. // ),
  82. // },
  83. {
  84. id: 'fullname',
  85. field: 'fullname',
  86. headerName: 'Client Name',
  87. flex: 1.5,
  88. renderCell: (params) => {
  89. return (
  90. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  91. {params.value}
  92. {/* {params.row.title ? `(${params.row.title})` : ''} {params.value} */}
  93. </div>
  94. );
  95. }
  96. },
  97. {
  98. id: 'title',
  99. field: 'title',
  100. headerName: 'Title',
  101. flex: 1.5,
  102. },
  103. {
  104. id: 'joinDate',
  105. field: 'joinDate',
  106. headerName: 'Join Date',
  107. flex: 1,
  108. sortComparator: dateComparator,
  109. renderCell: (params) => (
  110. <div>
  111. {getDateString(params.row.joinDate, 'dd/MM/yyyy')}
  112. </div>
  113. ),
  114. },
  115. // {
  116. // id: 'lastname',
  117. // field: 'lastname',
  118. // headerName: 'Last Name',
  119. // flex: 1.5,
  120. // sortComparator: dateComparator,
  121. // renderCell: (params) => (
  122. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  123. // {params.value}
  124. // </div>
  125. // // <div>
  126. // // {getDateString(params.row.startDate,false)}
  127. // // </div>
  128. // ),
  129. // },
  130. // {
  131. // id: 'firstname',
  132. // field: 'firstname',
  133. // headerName: 'First Name',
  134. // // sortComparator: dateComparator,
  135. // flex: 2,
  136. // renderCell: (params) => (
  137. // <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  138. // {params.value}
  139. // </div>
  140. // // <div>
  141. // // {getDateString(params.row.applicationDeadline,false)}
  142. // // </div>
  143. // ),
  144. // },
  145. {
  146. id: 'email',
  147. field: 'email',
  148. headerName: 'Email',
  149. flex: 1.5,
  150. renderCell: (params) => {
  151. return (
  152. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  153. {params.value}
  154. </div>
  155. );
  156. }
  157. },
  158. {
  159. id: 'phone1',
  160. field: 'phone1',
  161. headerName: 'Phone No.',
  162. flex: 1,
  163. renderCell: (params) => {
  164. return (
  165. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  166. {params.value}
  167. </div>
  168. );
  169. }
  170. },
  171. {
  172. id: 'phone2',
  173. field: 'phone2',
  174. headerName: '2nd Phone No.',
  175. flex: 1,
  176. renderCell: (params) => {
  177. return (
  178. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  179. {params.value}
  180. </div>
  181. );
  182. }
  183. },
  184. {
  185. id: 'remarks',
  186. field: 'remarks',
  187. headerName: 'Remarks',
  188. flex: 3,
  189. renderCell: (params) => {
  190. return (
  191. <div style={{display: 'flex', alignItems: 'center', justifyContent: 'center', whiteSpace: 'normal', wordBreak: 'break-word'}}>
  192. {params.value}
  193. </div>
  194. );
  195. }
  196. },
  197. ];
  198. return (
  199. <DataGrid
  200. rows={rows}
  201. columns={columns}
  202. columnHeaderHeight={45}
  203. editMode="row"
  204. //autoPageSize
  205. rowModesModel={rowModesModel}
  206. getRowHeight={() => 'auto'}
  207. paginationModel={paginationModel}
  208. onPaginationModelChange={setPaginationModel}
  209. slots={{
  210. noRowsOverlay: () => (
  211. CustomNoRowsOverlay()
  212. )
  213. }}
  214. pageSizeOptions={[10]}
  215. autoHeight
  216. />
  217. );
  218. }