Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

172 righe
7.3 KiB

  1. // material-ui
  2. import {
  3. Grid,
  4. Typography,
  5. Stack,
  6. Box,
  7. Button
  8. } from '@mui/material';
  9. import * as UrlUtils from "utils/ApiPathConst";
  10. import * as React from "react";
  11. import * as HttpUtils from "utils/HttpUtils";
  12. import * as DateUtils from "utils/DateUtils";
  13. import * as FormatUtils from "utils/FormatUtils"
  14. import { useParams } from "react-router-dom";
  15. import { useNavigate } from "react-router-dom";
  16. import ForwardIcon from '@mui/icons-material/Forward';
  17. import Loadable from 'components/Loadable';
  18. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  19. const ApplicationDetails = Loadable(React.lazy(() => import('./ApplicationDetails')));
  20. const ProofForm = Loadable(React.lazy(() => import('./ProofForm')));
  21. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  22. const BackgroundHead = {
  23. backgroundImage: `url(${titleBackgroundImg})`,
  24. width: '100%',
  25. height: '100%',
  26. backgroundSize: 'contain',
  27. backgroundRepeat: 'no-repeat',
  28. backgroundColor: '#0C489E',
  29. backgroundPosition: 'right'
  30. }
  31. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  32. const Index = () => {
  33. const params = useParams();
  34. const navigate = useNavigate()
  35. const [record, setRecord] = React.useState({});
  36. const [onReady, setOnReady] = React.useState(false);
  37. const [isOverTime, setIsOverTime] = React.useState(false);
  38. const [showCancelBtn, setShowCancelBtn] = React.useState(false);
  39. const [showProofBtn, setShowProofBtn] = React.useState(false);
  40. React.useLayoutEffect(() => {
  41. loadForm();
  42. }, []);
  43. React.useLayoutEffect(() => {
  44. setOnReady(true);
  45. }, [record]);
  46. const loadForm = () => {
  47. if (params.id > 0) {
  48. HttpUtils.get({
  49. url: UrlUtils.GET_PROOF + "/" + params.id,
  50. onSuccess: (responseData) => {
  51. if (!responseData.data?.id) {
  52. navigate("/proof/search");
  53. }
  54. setShowProofBtn(responseData.data.action != null && responseData.data.action===true);
  55. responseData.data["phoneNumber"] = JSON.parse(responseData.data.contactTelNo).phoneNumber;
  56. responseData.data["tel_countryCode"] = JSON.parse(responseData.data.contactTelNo).countryCode;
  57. responseData.data["faxNumber"] = JSON.parse(responseData.data.contactFaxNo).faxNumber;
  58. responseData.data["fax_countryCode"] = JSON.parse(responseData.data.contactFaxNo).countryCode;
  59. responseData.data["issueNoStr"] = responseData.data.issueYear
  60. + " Vol. " + FormatUtils.zeroPad(responseData.data.issueVolume, 3)
  61. + ", No. " + FormatUtils.zeroPad(responseData.data.issueNo, 2);
  62. responseData.data["issueDateStr"] = DateUtils.dateFormat(responseData.data.issueDate, "D MMM YYYY (ddd)");
  63. responseData.data["groupType"] = responseData.data.groupTitle;
  64. responseData.data["action"] = responseData.data.replyDate ? responseData.data.action : true;
  65. let returnBeforeDate = DateUtils.convertToDate(responseData.data.returnBeforeDate);
  66. let current = new Date();
  67. setIsOverTime(current.getTime() > returnBeforeDate.getTime());
  68. setShowCancelBtn(responseData.data.cancelled || responseData.data.replyDate || current.getTime() > returnBeforeDate.getTime())
  69. setRecord(responseData.data);
  70. }
  71. });
  72. }
  73. }
  74. // calculate back button position
  75. // const applicationDetailsRef = React.useCallback(node => {
  76. // if (node === null) {
  77. // return
  78. // } else {
  79. // setBackButtonLeftPos(`${node.getBoundingClientRect()?.left}px`)
  80. // }
  81. // })
  82. // const [backButtonPos, setBackButtonPos] = React.useState()
  83. // const backButtonRef = React.useRef()
  84. // React.useLayoutEffect(()=>{
  85. // console.log(applicationDetailsRef.current?.getBoundingClientRect())
  86. // if (backButtonRef.current) backButtonRef.current.style.marginLeft = `${backButtonPos}`
  87. // },[backButtonPos])
  88. // React.useEffect(()=>{
  89. // if (backButtonRef.current) backButtonRef.current.style.marginLeft = `${backButtonLeftPos}`
  90. // }, [backButtonLeftPos])
  91. return (
  92. !onReady ?
  93. <LoadingComponent />
  94. :
  95. (
  96. <Grid container sx={{ minHeight: '110vh', backgroundColor: 'backgroundColor.default' }} direction="column" justifyContent="flex-start" alignItems="center" >
  97. <Grid item xs={12} width="100%">
  98. <div style={BackgroundHead} width="100%">
  99. <Stack direction="row" height='70px'>
  100. <Typography ml={15} color='#FFF' variant="h4" sx={{ pt: 2 }}>Proof Record</Typography>
  101. </Stack>
  102. </div>
  103. </Grid>
  104. <Grid item xs={12} width="100%">
  105. <Button title="Back" sx={{ ml: 6, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate("/proof/search") }}>
  106. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  107. </Button>
  108. </Grid>
  109. {/*row 1*/}
  110. <Grid item xs={12} md={12} >
  111. <Grid container justifyContent="flex-start" alignItems="center" direction="column">
  112. <center>
  113. <Grid item xs={12} md={12} sx={{ pt: 2, ml: 6, mr: 6, }}>
  114. <Box xs={12} md={12} sx={{ p: 4, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  115. <ApplicationDetails
  116. // setBackButtonPos={setBackButtonPos}
  117. formData={record}
  118. showCancelBtn={showCancelBtn}
  119. showProofBtn={showProofBtn}
  120. style={{
  121. display: "flex",
  122. height: "100%",
  123. flex: 1
  124. }}
  125. />
  126. </Box>
  127. </Grid>
  128. <Grid item xs={12} md={12} sx={{ pt: 3, pb: 2, ml: 6, mr: 6, }}>
  129. <Box xs={12} md={12} sx={{ p: 4, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  130. <ProofForm
  131. formData={record}
  132. isOverTime={isOverTime}
  133. />
  134. </Box>
  135. </Grid>
  136. </center>
  137. </Grid>
  138. </Grid>
  139. {/*row 2*/}
  140. </Grid >
  141. )
  142. );
  143. };
  144. export default Index;