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.
 
 

153 lines
4.2 KiB

  1. // material-ui
  2. import * as React from 'react';
  3. import {
  4. DataGrid,
  5. GridActionsCellItem
  6. } from "@mui/x-data-grid";
  7. import VisibilityIcon from '@mui/icons-material/Visibility';
  8. import HighlightOff from '@mui/icons-material/HighlightOff';
  9. import CheckCircleOutline from '@mui/icons-material/CheckCircleOutline';
  10. import {useEffect} from "react";
  11. import {useNavigate} from "react-router-dom";
  12. import * as DateUtils from "../../utils/DateUtils";
  13. // ==============================|| EVENT TABLE ||============================== //
  14. export default function UserTable_Individual({recordList}) {
  15. const [rows, setRows] = React.useState(recordList);
  16. const [rowModesModel] = React.useState({});
  17. const navigate = useNavigate()
  18. useEffect(() => {
  19. setRows(recordList);
  20. }, [recordList]);
  21. const handleActionClick = (id) => () => {
  22. navigate('/indUser/'+ id);
  23. };
  24. const columns = [
  25. {
  26. field: 'actions',
  27. type: 'actions',
  28. headerName: 'Actions',
  29. width: 100,
  30. cellClassName: 'actions',
  31. getActions: ({id}) => {
  32. return [
  33. <GridActionsCellItem
  34. key="OutSave"
  35. icon={<VisibilityIcon/>}
  36. label="View"
  37. className="textPrimary"
  38. onClick={handleActionClick(id)}
  39. color="primary"
  40. />]
  41. },
  42. },
  43. {
  44. id: 'username',
  45. field: 'username',
  46. headerName: 'User Name',
  47. flex: 1,
  48. },
  49. {
  50. id: 'enName',
  51. field: 'enName',
  52. headerName: 'Name (Eng)',
  53. flex: 1,
  54. },
  55. {
  56. id: 'chName',
  57. field: 'chName',
  58. headerName: 'Name (Ch)',
  59. flex: 1,
  60. },
  61. {
  62. id: 'mobileNumber',
  63. field: 'mobileNumber',
  64. headerName: 'Tel.',
  65. flex: 1,
  66. valueGetter:(params)=>{
  67. if(params.value){
  68. let tel = JSON.parse(params.value);
  69. return "+"+tel.countryCode+ " "+tel.phoneNumber;
  70. }
  71. }
  72. },
  73. {
  74. id: 'emailAddress',
  75. field: 'emailAddress',
  76. headerName: 'Email',
  77. flex: 1,
  78. },
  79. {
  80. id: 'lastLogin',
  81. field: 'lastLogin',
  82. headerName: 'Last Login',
  83. flex: 1,
  84. valueGetter:(params)=>{
  85. if(params.value){
  86. return DateUtils.datetimeStr(params.value);
  87. }
  88. }
  89. },
  90. {
  91. id: 'locked',
  92. field: 'locked',
  93. headerName: 'Status',
  94. flex: 1,
  95. valueGetter:(params)=>{
  96. if(params.value){
  97. return "Locked";
  98. }else{
  99. return "Active";
  100. }
  101. }
  102. },
  103. {
  104. field: 'verifiedDate',
  105. type: 'actions',
  106. headerName: 'Verified',
  107. width: 100,
  108. cellClassName: 'actions',
  109. getActions: (params) => {
  110. if(params.row.verifiedDate)
  111. return [
  112. <GridActionsCellItem
  113. key=""
  114. icon={<CheckCircleOutline/>}
  115. color="success"
  116. />];
  117. return [
  118. <GridActionsCellItem
  119. key=""
  120. icon={<HighlightOff/>}
  121. color="error"
  122. />];
  123. },
  124. },
  125. ];
  126. return (
  127. <div style={{height: 400, width: '100%'}}>
  128. <DataGrid
  129. rows={rows}
  130. columns={columns}
  131. editMode="row"
  132. rowModesModel={rowModesModel}
  133. initialState={{
  134. pagination: {
  135. paginationModel: {page: 0, pageSize: 5},
  136. },
  137. }}
  138. pageSizeOptions={[5, 10]}
  139. autoHeight = {true}
  140. />
  141. </div>
  142. );
  143. }