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.
 
 

203 wiersze
9.2 KiB

  1. // material-ui
  2. import { Grid, Typography, Stack, Box, Button } from '@mui/material';
  3. import * as React from "react";
  4. import * as HttpUtils from "utils/HttpUtils";
  5. import * as UrlUtils from "utils/ApiPathConst";
  6. import * as DateUtils from "utils/DateUtils";
  7. import Loadable from 'components/Loadable';
  8. const InfoCard = Loadable(React.lazy(() => import('./OrganizationCard')));
  9. const InfoPubCard = Loadable(React.lazy(() => import('./OrganizationPubCard')));
  10. const Table = Loadable(React.lazy(() => import('./CreditorHistoryTable')));
  11. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  12. import ForwardIcon from '@mui/icons-material/Forward';
  13. import { useNavigate, useParams } from 'react-router-dom';
  14. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  15. import {getObjectByType} from "utils/CommonFunction";
  16. import * as ComboData from "utils/ComboData";
  17. import {
  18. isGLDLoggedIn,
  19. isINDLoggedIn,
  20. isORGLoggedIn,
  21. isPrimaryLoggedIn
  22. } from "utils/Utils";
  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. import {
  33. FormattedMessage,
  34. // FormattedMessage,
  35. useIntl
  36. } from "react-intl";
  37. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  38. const OrganizationDetailPage = () => {
  39. const params = useParams();
  40. const [formData, setFormData] = React.useState({})
  41. const [list, setList] = React.useState([])
  42. const [isLoading, setLoding] = React.useState(true);
  43. const [isEditMode, setEditMode] = React.useState(false);
  44. const navigate = useNavigate();
  45. const intl = useIntl();
  46. const { locale } = intl;
  47. const isCreditor = locale === 'en' ?"Yes":locale === 'zh-HK' ?"是":"是";
  48. const notCreditor = locale === 'en' ?"No":locale === 'zh-HK' ?"否":"否";
  49. React.useEffect(() => {
  50. // console.log(formData);
  51. if (isINDLoggedIn()||isORGLoggedIn()&&!isPrimaryLoggedIn()){
  52. navigate('/dashboard');
  53. }else{
  54. loadData();
  55. }
  56. loadData();
  57. }, []);
  58. const loadData = () => {
  59. setLoding(true);
  60. if(isGLDLoggedIn()){
  61. if (params.id > 0) {
  62. HttpUtils.get({
  63. url: UrlUtils.GET_ORG_PATH + "/" + params.id,
  64. onSuccess: function (response) {
  65. // console.log(response)
  66. response.data["country"] = getObjectByType(ComboData.country, "type", response.data.addressTemp?.country);
  67. response.data["district"] = getObjectByType(ComboData.district, "type", response.data.addressTemp?.district);
  68. response.data["addressLine1"] = response.data.addressTemp?.addressLine1;
  69. response.data["addressLine2"] = response.data.addressTemp?.addressLine2;
  70. response.data["addressLine3"] = response.data.addressTemp?.addressLine3;
  71. response.data["phoneNumber"] = response.data.contactTel?.phoneNumber;
  72. response.data["tel_countryCode"] = response.data.contactTel?.countryCode;
  73. response.data["faxNumber"] = response.data.faxNo?.faxNumber;
  74. response.data["fax_countryCode"] = response.data.faxNo?.countryCode;
  75. response.data["brExpiryDate"] = response.data.brExpiryDate ? DateUtils.dateValue(response.data.brExpiryDate) : "";
  76. response.data["orgShortName"] = response.data.orgShortName ? response.data.orgShortName : "N/A" ;
  77. setFormData(response.data)
  78. setList(response.historyList)
  79. }
  80. });
  81. }
  82. }
  83. if(isPrimaryLoggedIn()){
  84. HttpUtils.get({
  85. url: UrlUtils.GET_PUB_ORG_PATH,
  86. onSuccess: function (response) {
  87. // console.log(response)
  88. response.data["creditor"] = response.data.creditor!=null?response.data.creditor?isCreditor:notCreditor:notCreditor;
  89. response.data["country"] = getObjectByType(ComboData.country, "type", response.data.addressTemp?.country);
  90. response.data["district"] = getObjectByType(ComboData.district, "type", response.data.addressTemp?.district);
  91. response.data["addressLine1"] = response.data.addressTemp?.addressLine1;
  92. response.data["addressLine2"] = response.data.addressTemp?.addressLine2;
  93. response.data["addressLine3"] = response.data.addressTemp?.addressLine3;
  94. response.data["phoneNumber"] = response.data.contactTel?.phoneNumber;
  95. response.data["tel_countryCode"] = response.data.contactTel?.countryCode;
  96. response.data["faxNumber"] = response.data.faxNo?.faxNumber;
  97. response.data["fax_countryCode"] = response.data.faxNo?.countryCode;
  98. response.data["brExpiryDate"] = response.data.brExpiryDate ? DateUtils.dateStr(response.data.brExpiryDate) : "" ;
  99. setFormData(response.data)
  100. setList(response.historyList)
  101. }
  102. });
  103. }
  104. };
  105. React.useEffect(() => {
  106. setLoding(false);
  107. }, [formData]);
  108. return (
  109. isLoading ?
  110. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  111. <Grid item>
  112. <LoadingComponent />
  113. </Grid>
  114. </Grid>
  115. :
  116. <Grid container direction="column" sx={{minHeight: '87vh',backgroundColor:isGLDLoggedIn()?'backgroundColor.default':'#ffffff' }}>
  117. <Grid item xs={12}>
  118. <div style={BackgroundHead}>
  119. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  120. {isGLDLoggedIn()?
  121. <Typography ml={15} color='#FFF' variant="h4" sx={{display: { xs: 'none', sm: 'none', md: 'block' }}}>
  122. Maintain Organisation
  123. </Typography>
  124. :
  125. <Typography ml={15} color='#FFF' variant="h4" sx={{display: { xs: 'none', sm: 'none', md: 'block' }}}>
  126. <FormattedMessage id="organizationProfile" />
  127. </Typography>
  128. }
  129. </Stack>
  130. </div>
  131. </Grid>
  132. <Grid item xs={12}>
  133. <Button aria-label={intl.formatMessage({id: 'back'})} title="Back" sx={{ ml: 3.5, mt: 2 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate(-1)}}>
  134. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  135. </Button>
  136. </Grid>
  137. {/*col 1*/}
  138. <Grid item xs={12} >
  139. <Grid container>
  140. <Grid item xs={12} md={12} lg={12}>
  141. <Box xs={12} ml={0} mt={-1} mr={0} sx={{ p: 1, borderRadius: '10px' }}>
  142. {isGLDLoggedIn()?
  143. <InfoCard
  144. userData={formData}
  145. loadDataFun={loadData}
  146. id={params.id}
  147. setEditModeFun={setEditMode}
  148. />
  149. :
  150. <InfoPubCard
  151. userData={formData}
  152. loadDataFun={loadData}
  153. id={params.id}
  154. setEditModeFun={setEditMode}
  155. />
  156. }
  157. </Box>
  158. <br />
  159. </Grid>
  160. {isGLDLoggedIn()?
  161. <Grid item xs={12} md={12} lg={12} display={isEditMode?"none":""}>
  162. <Box xs={12} ml={0} mt={-1} mr={0} sx={{ pl:4, pr:4, pb:2 }}>
  163. <Grid container sx={{ p: 3, backgroundColor: "#FFF", borderRadius: '10px' }}>
  164. <Grid item xs={12} sx={{ p:1 }}>
  165. <Table
  166. sx={{ p: 1 }}
  167. recordList={list}
  168. >
  169. </Table>
  170. </Grid>
  171. </Grid>
  172. </Box>
  173. </Grid>
  174. : null
  175. }
  176. </Grid>
  177. </Grid>
  178. {/*col 2*/}
  179. </Grid>
  180. );
  181. };
  182. export default OrganizationDetailPage;