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

index.js 9.4 KiB

2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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;