Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

282 righe
9.7 KiB

  1. // material-ui
  2. import { FiDataGrid } from "components/FiDataGrid";
  3. import {
  4. Typography, Button, Grid, Stack, useMediaQuery,
  5. Dialog, DialogTitle, DialogContent, DialogActions,
  6. } from '@mui/material';
  7. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  8. import Checkbox from '@mui/material/Checkbox';
  9. import * as React from "react";
  10. import * as HttpUtils from "utils/HttpUtils";
  11. import * as UrlUtils from "utils/ApiPathConst";
  12. import * as DateUtils from "utils/DateUtils";
  13. import { FormattedMessage, useIntl } from "react-intl";
  14. import { useTheme } from "@emotion/react";
  15. const BackgroundHead = {
  16. backgroundImage: `url(${titleBackgroundImg})`,
  17. width: '100%',
  18. height: '100%',
  19. backgroundSize: 'contain',
  20. backgroundRepeat: 'no-repeat',
  21. backgroundColor: '#0C489E',
  22. backgroundPosition: 'right'
  23. }
  24. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  25. const ManageOrgUserPage = () => {
  26. const [rows, setRows] = React.useState([]);
  27. const intl = useIntl();
  28. const theme = useTheme();
  29. const isMdOrLg = useMediaQuery(theme.breakpoints.up('md'));
  30. const [userId, setUserId] = React.useState("");
  31. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  32. const [warningText, setWarningText] = React.useState("");
  33. const [selectUser, setSelectUser] = React.useState({});
  34. const _sx = {
  35. padding: "4 2 4 2",
  36. boxShadow: 1,
  37. border: 1,
  38. borderColor: '#DDD',
  39. '& .MuiDataGrid-cell': {
  40. borderTop: 1,
  41. borderBottom: 1,
  42. borderColor: "#EEE"
  43. },
  44. '& .MuiDataGrid-footerContainer': {
  45. border: 1,
  46. borderColor: "#EEE"
  47. }
  48. }
  49. React.useEffect(() => {
  50. setUserId(JSON.parse(localStorage.getItem("userData")).id);
  51. loadData();
  52. }, []);
  53. function loadData() {
  54. HttpUtils.get(
  55. {
  56. url: UrlUtils.GET_PUBLIC_ORG_USER_LIST,
  57. onSuccess: function (responseData) {
  58. setRows(responseData);
  59. }
  60. }
  61. );
  62. }
  63. function onActiveClick(params) {
  64. HttpUtils.get({
  65. url: UrlUtils.GET_USER_UNLOCK + "/" + params.row.id,
  66. onSuccess: () => {
  67. loadData();
  68. }
  69. });
  70. }
  71. function getHeader(headerStr) {
  72. return <Typography variant="h5" >{headerStr}</Typography>;
  73. }
  74. function getStatus(params) {
  75. if (params.row.locked) {
  76. return (
  77. <>
  78. {getStatusTag({ color: "#525150", text: intl.formatMessage({ id: 'locked' }) })}
  79. <Button variant="outlined" onClick={() => onActiveClick(params)}>
  80. <FormattedMessage id="unlock" />
  81. </Button>
  82. </>
  83. )
  84. } else if (!params.row.verifiedBy) {
  85. return getStatusTag({ color: "#fca503", text: intl.formatMessage({ id: 'pendingFor' }) })
  86. } else if (params.row.status === "active") {
  87. return getStatusTag({ color: "#73AD21", text: intl.formatMessage({ id: 'active' }) })
  88. }
  89. return getStatusTag({ text: params.row.status })
  90. }
  91. function getStatusTag({ color = "#000", textColor = "#FFF", text = "" }) {
  92. return (
  93. <div style={{ borderRadius: "25px", "background": color, "color": textColor, "padding": "5px 10px 5px 10px" }}><b>{text}</b></div>
  94. )
  95. }
  96. const setPrimaryUser = () => {
  97. setIsWarningPopUp(false)
  98. HttpUtils.get(
  99. {
  100. url: (!selectUser.row.primaryUser ? UrlUtils.GET_SET_PRIMARY_USER : UrlUtils.GET_SET_UN_PRIMARY_USER) + "/" + selectUser.row.id,
  101. onSuccess: function () {
  102. loadData();
  103. }
  104. }
  105. );
  106. }
  107. const columns = [
  108. {
  109. id: 'username',
  110. field: 'username',
  111. headerName: getHeader(intl.formatMessage({ id: 'loginName' })),
  112. width: isMdOrLg ? 'auto' : 160,
  113. flex: isMdOrLg ? 1 : undefined,
  114. },
  115. {
  116. id: 'contactPerson',
  117. field: 'contactPerson',
  118. headerName: getHeader(intl.formatMessage({ id: 'userName' })),
  119. width: isMdOrLg ? 'auto' : 160,
  120. flex: isMdOrLg ? 1 : undefined,
  121. },
  122. {
  123. id: 'contactTel',
  124. field: 'contactTel',
  125. headerName: getHeader(intl.formatMessage({ id: 'userContactNumber' })),
  126. width: isMdOrLg ? 'auto' : 160,
  127. flex: isMdOrLg ? 1 : undefined,
  128. valueGetter: (params) => {
  129. let contactTel = JSON.parse(params.value)
  130. return contactTel?.countryCode + " " + contactTel?.phoneNumber;
  131. }
  132. },
  133. {
  134. id: 'emailBus',
  135. field: 'emailBus',
  136. headerName: getHeader(intl.formatMessage({ id: 'userContactEmail' })),
  137. width: isMdOrLg ? 'auto' : 160,
  138. flex: isMdOrLg ? 1 : undefined,
  139. },
  140. {
  141. id: 'lastLogin',
  142. field: 'lastLogin',
  143. headerName: getHeader(intl.formatMessage({ id: 'lastLoginDate' })),
  144. width: isMdOrLg ? 'auto' : 160,
  145. flex: isMdOrLg ? 1 : undefined,
  146. valueGetter: (params) => {
  147. return DateUtils.datetimeStr(params.value);
  148. }
  149. },
  150. {
  151. id: 'lastApply',
  152. field: 'lastApply',
  153. headerName: getHeader(intl.formatMessage({ id: 'lastSubmissionDate' })),
  154. width: isMdOrLg ? 'auto' : 160,
  155. flex: isMdOrLg ? 1 : undefined,
  156. valueGetter: () => {
  157. return "--";
  158. }
  159. },
  160. {
  161. field: 'actions',
  162. type: 'actions',
  163. headerName: getHeader(intl.formatMessage({ id: 'status' })),
  164. width: isMdOrLg ? 'auto' : 160,
  165. flex: isMdOrLg ? 1 : undefined,
  166. cellClassName: 'actions',
  167. getActions: (params) => {
  168. return [getStatus(params)]
  169. },
  170. },
  171. {
  172. id: 'primaryUser',
  173. field: 'primaryUser',
  174. type: 'bool',
  175. headerName: getHeader(intl.formatMessage({ id: 'primary' })),
  176. width: isMdOrLg ? 'auto' : 160,
  177. flex: isMdOrLg ? 1 : undefined,
  178. renderCell: (params) => {
  179. console.log(params);
  180. return (
  181. <>
  182. {params.row.id == userId ?
  183. <></> :
  184. <Checkbox
  185. onClick={() => {
  186. setSelectUser(params);
  187. let str = params.row.primaryUser ?
  188. intl.formatMessage({ id: 'MSG.revokePrimay' },
  189. {
  190. username: params.row.username
  191. })
  192. :
  193. intl.formatMessage({ id: 'MSG.setPrimay' },
  194. {
  195. username: params.row.username
  196. });
  197. setWarningText(str);
  198. setIsWarningPopUp(true);
  199. }}
  200. checked={params.row.primaryUser}
  201. />
  202. }
  203. </>
  204. );
  205. },
  206. }
  207. ];
  208. return (
  209. <Grid container>
  210. <Grid item xs={12}>
  211. <div style={BackgroundHead}>
  212. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  213. <Typography ml={15} color='#FFF' variant="h4" sx={{ display: { xs: 'none', sm: 'none', md: 'block' } }}>
  214. <FormattedMessage id="companyOrUserRecord" />
  215. </Typography>
  216. </Stack>
  217. </div>
  218. </Grid>
  219. <Grid item lg={12} sx={{ padding: 2 }}>
  220. <FiDataGrid
  221. sx={_sx}
  222. rows={rows}
  223. columns={columns}
  224. customPageSize={10}
  225. />
  226. </Grid>
  227. <div>
  228. <Dialog
  229. open={isWarningPopUp}
  230. onClose={() => setIsWarningPopUp(false)}
  231. PaperProps={{
  232. sx: {
  233. minWidth: '40vw',
  234. maxWidth: { xs: '90vw', s: '90vw', m: '70vw', lg: '70vw' },
  235. maxHeight: { xs: '90vh', s: '70vh', m: '70vh', lg: '60vh' }
  236. }
  237. }}
  238. >
  239. <DialogTitle>
  240. <FormattedMessage id="confirm" />
  241. </DialogTitle>
  242. <DialogContent style={{ display: 'flex', }}>
  243. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  244. </DialogContent>
  245. <DialogActions>
  246. <Button onClick={() => {
  247. setSelectUser({})
  248. setIsWarningPopUp(false)
  249. }}><FormattedMessage id="cancel" /></Button>
  250. <Button onClick={() => setPrimaryUser()}><FormattedMessage id="confirm" /></Button>
  251. </DialogActions>
  252. </Dialog>
  253. </div>
  254. </Grid>
  255. );
  256. };
  257. export default ManageOrgUserPage;