Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

295 wiersze
13 KiB

  1. // material-ui
  2. import { Grid, Typography, Stack, Box, Button, Tab } from '@mui/material';
  3. import { TabPanel, TabContext, TabList } from '@mui/lab';
  4. import { useEffect, useState } from "react";
  5. import * as React from "react";
  6. //import axios from "axios";
  7. import * as HttpUtils from "utils/HttpUtils";
  8. import { useParams } from "react-router-dom";
  9. import FileList from "components/FileList"
  10. import MainCard from "components/MainCard";
  11. import * as UrlUtils from "utils/ApiPathConst";
  12. import * as DateUtils from 'utils/DateUtils';
  13. import Loadable from 'components/Loadable';
  14. import { lazy } from 'react';
  15. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  16. const UserInformationCard = Loadable(lazy(() => import('./UserInformationCard_Organization')));
  17. const UserInformationPubCard = Loadable(lazy(() => import('./UserInformationCard_Organization_Pub')));
  18. import ForwardIcon from '@mui/icons-material/Forward';
  19. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  20. import { useNavigate } from 'react-router-dom';
  21. import * as ComboData from "utils/ComboData";
  22. import {getObjectByType} from "utils/CommonFunction";
  23. const LoginGrid = Loadable(React.lazy(() => import('./LoginGrid')));
  24. const BackgroundHead = {
  25. backgroundImage: `url(${titleBackgroundImg})`,
  26. width: '100%',
  27. height: '100%',
  28. backgroundSize: 'contain',
  29. backgroundRepeat: 'no-repeat',
  30. backgroundColor: '#0C489E',
  31. backgroundPosition: 'right'
  32. }
  33. import {
  34. isGLDLoggedIn,
  35. isORGLoggedIn,
  36. isINDLoggedIn
  37. } from "utils/Utils";
  38. import {FormattedMessage, useIntl} from "react-intl";
  39. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  40. const UserMaintainPage_Organization = () => {
  41. const params = useParams();
  42. const navigate = useNavigate();
  43. const [userData, setUserData] = useState({})
  44. const [loginLogData, setLoginLogData] = React.useState([])
  45. const [orgData, setOrgData] = useState({})
  46. const [isLoading, setLoding] = useState(true);
  47. const intl = useIntl();
  48. const { locale } = intl;
  49. const [selectedTab, setSelectedTab] = React.useState("1");
  50. const isPrimaryLocale = locale === 'en' ?"Yes":locale === 'zh-HK' ?"是":"是";
  51. const notPrimaryLocale = locale === 'en' ?"No":locale === 'zh-HK' ?"否":"否";
  52. // const _sx = {
  53. // ml: 3,
  54. // mb: 3,
  55. // mt: 3,
  56. // mr: 6,
  57. // padding: "4 2 4 2",
  58. // boxShadow: 1,
  59. // border: 1,
  60. // borderColor: '#DDD',
  61. // '& .MuiDataGrid-cell': {
  62. // borderTop: 1,
  63. // borderBottom: 1,
  64. // borderColor: "#EEE"
  65. // },
  66. // '& .MuiDataGrid-footerContainer': {
  67. // border: 1,
  68. // borderColor: "#EEE"
  69. // }
  70. // }
  71. const handleChange = (event, newValue) => {
  72. setSelectedTab(newValue);
  73. }
  74. useEffect(() => {
  75. // console.log(userData);
  76. if (isINDLoggedIn()){
  77. navigate('/dashboard');
  78. }else{
  79. loadData();
  80. }
  81. }, []);
  82. useEffect(() => {
  83. // console.log(userData);
  84. loadData();
  85. }, [locale]);
  86. // const reloadPage=()=>{
  87. // window.location.reload(false);
  88. // }
  89. const loadData = () => {
  90. setLoding(true);
  91. if (isGLDLoggedIn()){
  92. HttpUtils.get({
  93. url: `${UrlUtils.GET_ORG_USER_PATH}/${params.id}`,
  94. onSuccess: function (response) {
  95. // console.log(response)
  96. if (response.data.orgId != null) {
  97. // console.log("1a")
  98. response.data["addressBus"] = response.orgDetail.data["addressTemp"];
  99. response.data["contactTel"] = response.orgDetail.data["contactTel"];
  100. response.data["faxNo"] = response.orgDetail.data["faxNo"];
  101. response.data["brExpiryDate"] = response.orgDetail.data.brExpiryDate ? DateUtils.dateStr(response.orgDetail.data.brExpiryDate) : "";
  102. response.data["brNo"] = response.orgDetail.data.brNo;
  103. response.data["enCompanyName"] = response.orgDetail.data.enCompanyName;
  104. response.data["chCompanyName"] = response.orgDetail.data.chCompanyName;
  105. response.data["chCompanyName"] = response.orgDetail.data.chCompanyName;
  106. } else {
  107. // console.log("1b")
  108. response.data["addressBus"] = JSON.parse(response.data["addressBus"]);
  109. response.data["contactTel"] = JSON.parse(response.data["contactTel"]);
  110. response.data["faxNo"] = JSON.parse(response.data["faxNo"]);
  111. response.data["brExpiryDate"] = response.data.brExpiryDate ? DateUtils.dateStr(response.data.brExpiryDate) : "";
  112. }
  113. // console.log("2")
  114. // console.log(response.data)
  115. let createDate = DateUtils.datetimeStr(response.data.created);
  116. let modifiedBy = DateUtils.datetimeStr(response.data.modified) + ", " + response.data.modifiedBy;
  117. response.data["createDate"] = createDate;
  118. response.data["modifieDate"] = modifiedBy;
  119. response.data["verifiedStatus"] = response.data.verifiedBy ? DateUtils.datetimeStr(response.data.verifiedDate) + ", " + response.data.verifiedByName : "Not Verified";
  120. response.data["lastLoginDate"] = response.data.lastLogin ? DateUtils.datetimeStr(response.data.lastLoginDate) : "";
  121. response.data["country"] = getObjectByType(ComboData.country, "type", response.data.addressBus?.country);
  122. response.data["district"] = getObjectByType(ComboData.district, "type", response.data.addressBus?.district);
  123. response.data["addressLine1"] = response.data.addressBus?.addressLine1;
  124. response.data["addressLine2"] = response.data.addressBus?.addressLine2;
  125. response.data["addressLine3"] = response.data.addressBus?.addressLine3;
  126. response.data["phoneNumber"] = response.data.contactTel?.phoneNumber;
  127. response.data["tel_countryCode"] = response.data.contactTel?.countryCode;
  128. response.data["faxNumber"] = response.data.faxNo?.faxNumber;
  129. response.data["fax_countryCode"] = response.data.faxNo?.countryCode;
  130. // response.data["status"] = response.data?.locked?"locked":response.data?.status;
  131. response.data["preferLocale"] = getObjectByType(ComboData.Locale, "type", response.data?.preferLocale);
  132. //response.data["orgId"] = response.data.brExpiryDate?DateUtils.dateStr(response.data.brExpiryDate):"";
  133. // console.log("3")
  134. // console.log(response.data)
  135. setUserData(response.data);
  136. setOrgData(response.orgList);
  137. getLoginLogList()
  138. }
  139. });
  140. }
  141. if (isORGLoggedIn()){
  142. HttpUtils.get({
  143. url: `${UrlUtils.GET_PUB_ORG_USER_PATH}`,
  144. onSuccess: function (response) {
  145. // console.log(response)
  146. response.data["contactTel"] = JSON.parse(response.data["contactTel"]);
  147. response.data["primaryUser"] = response.data.primaryUser?isPrimaryLocale:notPrimaryLocale;
  148. response.data["phoneNumber"] = response.data.contactTel?.phoneNumber;
  149. response.data["tel_countryCode"] = response.data.contactTel?.countryCode;
  150. response.data["faxNumber"] = response.data.faxNo?.faxNumber;
  151. response.data["fax_countryCode"] = response.data.faxNo?.countryCode;
  152. response.data["preferLocale"] = getObjectByType(ComboData.Locale, "type", response.data?.preferLocale);
  153. //response.data["orgId"] = response.data.brExpiryDate?DateUtils.dateStr(response.data.brExpiryDate):"";
  154. setUserData(response.data);
  155. setOrgData(response.orgList);
  156. // console.log(response.data)
  157. }
  158. });
  159. }
  160. };
  161. const getLoginLogList = () => {
  162. HttpUtils.get({
  163. url: `${UrlUtils.GET_LOGIN_LOG_LIST}`,
  164. params:{
  165. userId:params.id
  166. },
  167. onSuccess: function (response) {
  168. // console.log(response)
  169. setLoginLogData(response);
  170. }
  171. });
  172. }
  173. useEffect(() => {
  174. setLoding(false);
  175. }, [loginLogData]);
  176. return (
  177. isLoading ?
  178. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  179. <Grid item>
  180. <LoadingComponent />
  181. </Grid>
  182. </Grid>
  183. :
  184. <Grid container sx={{ minHeight: '87vh', backgroundColor: isGLDLoggedIn()?'backgroundColor.default':'#ffffff' }} direction="column">
  185. <Grid item xs={12}>
  186. <div style={BackgroundHead}>
  187. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  188. {isGLDLoggedIn()?
  189. <Typography ml={15} color='#FFF' variant="h4" sx={{display: { xs: 'none', sm: 'none', md: 'block', pt:2 }}}>
  190. Maintain Organisation User
  191. </Typography>
  192. :
  193. <Typography ml={15} color='#FFF' variant="h4" sx={{display: { xs: 'none', sm: 'none', md: 'block', pt:2 }}}>
  194. <FormattedMessage id="userProfile" />
  195. </Typography>
  196. }
  197. </Stack>
  198. </div>
  199. </Grid>
  200. <Grid item xs={12}>
  201. <Button title="Back" sx={{ ml: 3.5, mt: 2 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1) }}>
  202. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  203. </Button>
  204. </Grid>
  205. {/*col 1*/}
  206. <Grid item xs={12} >
  207. <Grid container>
  208. {isGLDLoggedIn()?
  209. <Grid item xs={12} md={12} lg={12}>
  210. <Box xs={12} ml={0} mt={-1} mr={0} sx={{ p: 1, borderRadius: '10px' }}>
  211. <UserInformationCard
  212. userData={userData}
  213. loadDataFun={loadData}
  214. orgData={orgData}
  215. />
  216. </Box>
  217. </Grid>
  218. : isORGLoggedIn()?
  219. <Grid item xs={12} md={12} lg={12}>
  220. <Box xs={12} ml={0} mt={-1} mr={0} sx={{ p: 1, borderRadius: '10px' }}>
  221. <UserInformationPubCard
  222. userData={userData}
  223. loadDataFun={loadData}
  224. orgData={orgData}
  225. />
  226. </Box>
  227. </Grid>
  228. :null
  229. }
  230. {isGLDLoggedIn()?
  231. <Grid item xs={12} md={12} lg={12}>
  232. <MainCard elevation={0} border={false} content={false} sx={{maxWidth: '100%', mr:2, width: "-webkit-fill-available"}}>
  233. <TabContext value={selectedTab}>
  234. <Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
  235. <TabList variant="scrollable" onChange={handleChange} aria-label="lab API tabs example">
  236. <Tab label="Files" value="1" />
  237. <Tab label="Login" value="2" />
  238. </TabList>
  239. </Box>
  240. <TabPanel value="1">
  241. <FileList
  242. refId={params.id}
  243. refType={"identification"}
  244. />
  245. </TabPanel>
  246. <TabPanel value="2">
  247. <LoginGrid
  248. rows = {loginLogData}
  249. />
  250. </TabPanel>
  251. </TabContext>
  252. </MainCard>
  253. <br />
  254. </Grid>
  255. :null
  256. }
  257. </Grid>
  258. </Grid>
  259. {/*col 2*/}
  260. </Grid>
  261. );
  262. };
  263. export default UserMaintainPage_Organization;