選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

286 行
9.4 KiB

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