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

index.js 18 KiB

2年前
2年前
1年前
1年前
2年前
2年前
2年前
2年前
2年前
1年前
2年前
2年前
1年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
1年前
2年前
2年前
2年前
2年前
2年前
2年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. // material-ui
  2. import {
  3. Button,
  4. Grid,
  5. Typography,
  6. Stack,
  7. Box,
  8. Tab
  9. } from '@mui/material';
  10. import { TabPanel, TabContext, TabList } from '@mui/lab';
  11. import MainCard from "components/MainCard";
  12. import { useEffect, useState, lazy } from "react";
  13. import axios from "axios";
  14. import { useNavigate, useParams } from "react-router-dom";
  15. import { GLD_USER_PATH, DELETE_USER, POST_ADMIN_USER_REGISTER } from "utils/ApiPathConst";
  16. import {isGrantedAny} from "auth/utils";
  17. import Loadable from 'components/Loadable';
  18. const UserInformationCard = Loadable(lazy(() => import('./UserInformationCard')));
  19. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  20. const UserGroupCard = Loadable(lazy(() => import('./UserGroupCard')));
  21. const UserAuthorityCard = Loadable(lazy(() => import('./UserAuthorityCard')));
  22. const LoginGrid = Loadable(lazy(() => import('./LoginGrid')));
  23. import { ThemeProvider } from "@emotion/react";
  24. import { PNSPS_BUTTON_THEME } from "themes/buttonConst";
  25. import {
  26. GeneralConfirmWindow,
  27. getDeletedRecordWithRefList,
  28. notifyDeleteSuccess,
  29. notifySaveSuccess,
  30. } from "utils/CommonFunction";
  31. import ForwardIcon from '@mui/icons-material/Forward';
  32. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  33. import { useIntl } from 'react-intl';
  34. const BackgroundHead = {
  35. backgroundImage: `url(${titleBackgroundImg})`,
  36. width: '100%',
  37. height: '100%',
  38. backgroundSize: 'contain',
  39. backgroundRepeat: 'no-repeat',
  40. backgroundColor: '#0C489E',
  41. backgroundPosition: 'right'
  42. }
  43. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  44. const UserMaintainPage = () => {
  45. const intl = useIntl();
  46. const params = useParams();
  47. const navigate = useNavigate();
  48. const [userData, setUserData] = useState({});
  49. const [onReady, setOnReady] = useState(false);
  50. const [isCollectData, setIsCollectData] = useState(false);
  51. const [editedCustomerData, setEditedCustomerData] = useState({});
  52. const [userGroupData, setUserGroupData] = useState([]);
  53. const [userAuthData, setUserAuthData] = useState([]);
  54. const [userConfirm, setUserConfirm] = useState(false);
  55. const [isNewRecord, setIsNewRecord] = useState(false);
  56. const [refUserData, setRefUserData] = useState({});
  57. const [editMode, setEditMode] = useState(false);
  58. const [createMode, setCreateMode] = useState(false);
  59. const [selectedTab, setSelectedTab] = useState("1");
  60. function updateUserObject(userData) {
  61. setEditedCustomerData(userData);
  62. }
  63. function updateUserGroupList(userGroupData) {
  64. setUserGroupData(userGroupData);
  65. }
  66. function updateUserAuthList(userAuthData) {
  67. setUserAuthData(userAuthData);
  68. }
  69. const submitData = () => {
  70. setUserConfirm(true);
  71. setIsCollectData(!isCollectData);
  72. }
  73. const handleChange = (event, newValue) => {
  74. setSelectedTab(newValue);
  75. }
  76. // ==============================|| DELETE WINDOW RELATED ||============================== //
  77. const [isWindowOpen, setIsWindowOpen] = useState(false);
  78. const handleClose = () => {
  79. setIsWindowOpen(false);
  80. };
  81. const handleDeleteClick = () => {
  82. setIsWindowOpen(true);
  83. };
  84. function deleteData() {
  85. axios.delete(`${DELETE_USER}/${params.id}`,
  86. )
  87. .then((response) => {
  88. if (response.status === 204) {
  89. notifyDeleteSuccess();
  90. setIsWindowOpen(false);
  91. navigate('/userSearchview');
  92. }
  93. })
  94. .catch(error => {
  95. console.log(error);
  96. return false;
  97. });
  98. }
  99. // ==============================|| DELETE WINDOW RELATED ||============================== //
  100. useEffect(() => {
  101. if (params.id > 0) {
  102. loadData()
  103. }
  104. else {
  105. setUserData(
  106. {
  107. "authIds": [],
  108. "data": {},
  109. "groupIds": []
  110. }
  111. );
  112. setRefUserData(
  113. {
  114. "authIds": [],
  115. "data": {},
  116. "groupIds": []
  117. }
  118. );
  119. setIsNewRecord(true);
  120. setCreateMode(true)
  121. }
  122. }, []);
  123. const loadData = () => {
  124. setOnReady(false);
  125. setEditMode(false);
  126. axios.get(`${GLD_USER_PATH}/${params.id}`)
  127. .then((response) => {
  128. if (response.status === 200) {
  129. setRefUserData(response.data);
  130. setUserData(response.data);
  131. }
  132. })
  133. .catch(error => {
  134. console.log(error);
  135. return false;
  136. });
  137. }
  138. useEffect(() => {
  139. // if (Object.keys(userData).length > 0 && userData !== undefined) {
  140. if (Object.keys(userData).length > 0 && userData !== undefined) {
  141. setOnReady(true);
  142. }
  143. else if (isNewRecord) {
  144. setOnReady(true);
  145. }
  146. }, [userData]);
  147. useEffect(() => {
  148. if (userConfirm && onReady) {
  149. const deletedUserAuth = getDeletedRecordWithRefList(refUserData.authIds, userAuthData);
  150. const deletedUserGroup = getDeletedRecordWithRefList(refUserData.groupIds, userGroupData);
  151. // console.log(userGroupData)
  152. // console.log(userAuthData)
  153. if (parseInt(params.id) > -1) {
  154. axios.post(`${GLD_USER_PATH}/${params.id}`,
  155. {
  156. "enName": editedCustomerData.enName,
  157. "locked": editedCustomerData.locked,
  158. // "password": editedCustomerData.password,
  159. // "phone": editedCustomerData.phone,
  160. "post": editedCustomerData.post,
  161. "emailAddress": editedCustomerData.emailAddress,
  162. "addGroupIds": userGroupData,
  163. "removeGroupIds": deletedUserGroup,
  164. "addAuthIds": userAuthData,
  165. "removeAuthIds": deletedUserAuth,
  166. },
  167. ).then((response) => {
  168. if (response.status === 204) {
  169. notifySaveSuccess();
  170. location.reload();
  171. }
  172. })
  173. .catch(error => {
  174. console.log(error);
  175. return false;
  176. });
  177. } else {
  178. if (editedCustomerData.pwErr) return;
  179. axios.post(POST_ADMIN_USER_REGISTER,
  180. {
  181. "username": editedCustomerData.username,
  182. "name": editedCustomerData.username,
  183. "password": editedCustomerData.password,
  184. "enName": editedCustomerData.enName,
  185. "locked": editedCustomerData.locked,
  186. "emailAddress": editedCustomerData.emailAddress,
  187. "post": editedCustomerData.post,
  188. "addGroupIds": userGroupData,
  189. "removeGroupIds": [],
  190. "addAuthIds": userAuthData,
  191. "removeAuthIds": [],
  192. },
  193. ).then((response) => {
  194. if (response.status === 200) {
  195. notifySaveSuccess();
  196. navigate('/userSearchview');
  197. }
  198. })
  199. .catch(function (error){
  200. // console.log(error.response.data)
  201. if(error.response.data.error == "USERNAME_NOT_AVAILABLE"){
  202. alert("Username is already used.")
  203. }
  204. return false;
  205. });
  206. }
  207. }
  208. setUserConfirm(false);
  209. }, [editedCustomerData, userGroupData, userAuthData]);
  210. const onEditClick = () => {
  211. setEditMode(true);
  212. };
  213. return (
  214. !onReady ?
  215. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  216. <Grid item>
  217. <LoadingComponent />
  218. </Grid>
  219. </Grid>
  220. :
  221. <Grid container sx={{ minHeight: '87vh', backgroundColor: 'backgroundColor.default' }}>
  222. <Grid item xs={12}>
  223. <div style={BackgroundHead}>
  224. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  225. <Typography ml={15} color='#FFF' variant="h4" sx={{ "textShadow": "0px 0px 25px #0C489E" }}>{isNewRecord ? "Create GLD User" : "Maintain GLD User"}</Typography>
  226. </Stack>
  227. </div>
  228. </Grid>
  229. <Grid item xs={12}>
  230. <Button title="Back" sx={{ ml: 3.5, mt: 2 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate("/userSearchview") }}>
  231. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  232. </Button>
  233. </Grid>
  234. {/*col 1*/}
  235. {/*bottom button*/}
  236. {
  237. isGrantedAny(["MAINTAIN_USER", "MAINTAIN_GLD_USER"]) ?
  238. <Grid item s={12} md={12} lg={12} sx={{ mt: 2, mb: 2 }} alignItems={"start"} justifyContent="center">
  239. <Grid container maxWidth justifyContent="flex-start">
  240. {
  241. createMode?
  242. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  243. <Grid item sx={{ ml: 3, mr: 3 }}>
  244. <Button
  245. size="large"
  246. variant="contained"
  247. type="submit"
  248. sx={{
  249. textTransform: 'capitalize',
  250. alignItems: 'end'
  251. }}
  252. onClick={submitData}
  253. >
  254. Create User
  255. </Button>
  256. </Grid>
  257. </ThemeProvider>
  258. :
  259. editMode ?
  260. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  261. <Grid item sx={{ ml: 3, mr: 3 }}>
  262. <Button
  263. variant="contained"
  264. onClick={loadData}
  265. color="cancel"
  266. >
  267. Reset & Back
  268. </Button>
  269. </Grid>
  270. <Grid item sx={{ ml: 3, mr: 3 }}>
  271. <Button
  272. size="large"
  273. variant="contained"
  274. type="submit"
  275. sx={{
  276. textTransform: 'capitalize',
  277. alignItems: 'end'
  278. }}
  279. onClick={submitData}
  280. >
  281. Save
  282. </Button>
  283. </Grid>
  284. </ThemeProvider>
  285. :
  286. <ThemeProvider theme={PNSPS_BUTTON_THEME}>
  287. <Grid item sx={{ ml: 3, mr: 3 }}>
  288. <Button
  289. variant="contained"
  290. onClick={onEditClick}
  291. >
  292. Edit
  293. </Button>
  294. </Grid>
  295. <Grid item sx={{ ml: 3, mr: 3 }}>
  296. <Button
  297. size="large"
  298. variant="contained"
  299. sx={{
  300. textTransform: 'capitalize',
  301. alignItems: 'end'
  302. }}
  303. disabled={isNewRecord}
  304. onClick={handleDeleteClick}
  305. color='error'
  306. >
  307. Delete User
  308. </Button>
  309. <GeneralConfirmWindow
  310. isWindowOpen={isWindowOpen}
  311. title={"Attention"}
  312. content={`Confirm to delete User "${userData.data.username}" ?`}
  313. onNormalClose={handleClose}
  314. onConfirmClose={deleteData}
  315. />
  316. </Grid>
  317. </ThemeProvider>
  318. }
  319. </Grid>
  320. </Grid>
  321. : <></>
  322. }
  323. <Grid item xs={12} md={5} lg={5}>
  324. <Grid container>
  325. <Grid item xs={12} md={12} lg={12}>
  326. <Box xs={12} ml={4} mt={2} sx={{ borderRadius: '10px', backgroundColor: '#fff' }}>
  327. <UserInformationCard
  328. updateUserObject={updateUserObject}
  329. userData={userData}
  330. isCollectData={isCollectData}
  331. isNewRecord={isNewRecord}
  332. editMode={editMode}
  333. createMode={createMode}
  334. />
  335. </Box>
  336. </Grid>
  337. <Grid item xs={12} md={12} lg={12} sx={{ mt: 0.5 }}>
  338. <Box xs={12} ml={4} mt={2} sx={{ borderRadius: '10px', backgroundColor: '#fff' }}>
  339. <UserGroupCard
  340. updateUserGroupList={updateUserGroupList}
  341. userData={userData}
  342. isCollectData={isCollectData}
  343. isNewRecord={isNewRecord}
  344. editMode={editMode}
  345. createMode={createMode}
  346. />
  347. </Box>
  348. </Grid>
  349. </Grid>
  350. </Grid>
  351. {/*col 2*/}
  352. <Grid item xs={12} md={7} lg={7}>
  353. <Box xs={12} ml={2} mt={2} mr={3} sx={{ borderRadius: '10px', backgroundColor: '#fff' }}>
  354. <UserAuthorityCard
  355. updateUserAuthList={updateUserAuthList}
  356. userData={userData}
  357. isCollectData={isCollectData}
  358. isNewRecord={isNewRecord}
  359. editMode={editMode}
  360. createMode={createMode}
  361. />
  362. </Box>
  363. </Grid>
  364. <Grid item xs={12} md={12} lg={12}>
  365. <Box xs={12} ml={2} mt={2} mr={3} sx={{ borderRadius: '10px', backgroundColor: '#fff' }}>
  366. <MainCard elevation={0} border={false} content={false} sx={{maxWidth: '100%', mr:2, width: "-webkit-fill-available"}}>
  367. <TabContext value={selectedTab}>
  368. <Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
  369. <TabList variant="scrollable" onChange={handleChange} aria-label={intl.formatMessage({ id: 'ariaRelatedRecords' })}>
  370. <Tab label="Login Log" value="1" />
  371. </TabList>
  372. </Box>
  373. <TabPanel value="1">
  374. <LoginGrid
  375. u1 = {params.id}
  376. />
  377. </TabPanel>
  378. </TabContext>
  379. </MainCard>
  380. </Box>
  381. </Grid>
  382. </Grid>
  383. );
  384. };
  385. export default UserMaintainPage;