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.

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