Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

138 rindas
3.7 KiB

  1. // material-ui
  2. import * as React from 'react';
  3. import { GridActionsCellItem,} from "@mui/x-data-grid";
  4. import {FiDataGrid} from "components/FiDataGrid";
  5. import EditIcon from '@mui/icons-material/Edit';
  6. import {useEffect} from "react";
  7. import {useNavigate} from "react-router-dom";
  8. import { useTheme } from '@mui/material/styles';
  9. import Checkbox from '@mui/material/Checkbox';
  10. import * as UrlUtils from "../../../utils/ApiPathConst";
  11. import * as HttpUtils from '../../../utils/HttpUtils';
  12. // ==============================|| EVENT TABLE ||============================== //
  13. export default function UserTable({recordList,setChangeLocked}) {
  14. const [rows, setRows] = React.useState(recordList);
  15. const theme = useTheme();
  16. const navigate = useNavigate()
  17. useEffect(() => {
  18. setRows(recordList);
  19. }, [recordList]);
  20. const handleEditClick = (id) => () => {
  21. navigate('/user/'+ id);
  22. };
  23. const handleLock = (params) => () => {
  24. setChangeLocked(false)
  25. if (params.row.locked==true){
  26. doUnlock(params.id)
  27. }else{
  28. doLock(params.id)
  29. setRows(recordList);
  30. }
  31. }
  32. const doLock = (id) => {
  33. HttpUtils.get({
  34. url: UrlUtils.GET_USER_LOCK+"/"+id,
  35. onSuccess: function(){
  36. setRows(recordList);
  37. setChangeLocked(true)
  38. }
  39. });
  40. };
  41. const doUnlock = (id) => {
  42. HttpUtils.get({
  43. url: UrlUtils.GET_USER_UNLOCK+"/"+id,
  44. onSuccess: function(){
  45. setRows(recordList);
  46. setChangeLocked(true)
  47. }
  48. });
  49. };
  50. const columns = [
  51. {
  52. field: 'actions',
  53. type: 'actions',
  54. headerName: 'Actions',
  55. width: 100,
  56. cellClassName: 'actions',
  57. getActions: ({id}) => {
  58. return [
  59. <GridActionsCellItem
  60. key="OutSave"
  61. icon={<EditIcon/>}
  62. label="Edit"
  63. className="textPrimary"
  64. onClick={handleEditClick(id)}
  65. color="primary"
  66. />]
  67. },
  68. },
  69. {
  70. id: 'username',
  71. field: 'username',
  72. headerName: 'User Name',
  73. flex: 1,
  74. },
  75. {
  76. id: 'enName',
  77. field: 'enName',
  78. headerName: 'Full Name',
  79. flex: 1,
  80. },
  81. {
  82. id: 'post',
  83. field: 'post',
  84. headerName: 'Post',
  85. flex: 1,
  86. },
  87. {
  88. id: 'emailAddress',
  89. field: 'emailAddress',
  90. headerName: 'Email',
  91. flex: 1,
  92. },
  93. {
  94. id: 'locked',
  95. field: 'locked',
  96. type: 'bool',
  97. headerName: 'Locked',
  98. flex: 1,
  99. renderCell: (params) => {
  100. return (
  101. <Checkbox
  102. theme={theme}
  103. key="locked"
  104. checked={params.row.locked}
  105. color="primary"
  106. size="small"
  107. onClick={handleLock(params)}
  108. />
  109. );
  110. },
  111. },
  112. ];
  113. return (
  114. <div style={{height: "fit-content", width: '100%'}}>
  115. <FiDataGrid
  116. rows={rows}
  117. columns={columns}
  118. initialState={{
  119. pagination: {
  120. paginationModel: {page: 0, pageSize: 5},
  121. },
  122. }}
  123. />
  124. </div>
  125. );
  126. }