You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

176 lines
7.5 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 proofPaymentDeadline = DateUtils.convertToDate(responseData.data.proofPaymentDeadline);
  66. let current = new Date();
  67. setIsOverTime(current.getTime() > proofPaymentDeadline.getTime());
  68. setShowCancelBtn(responseData.data.cancelled || responseData.data.replyDate || current.getTime() > proofPaymentDeadline.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. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  94. <Grid item>
  95. <LoadingComponent />
  96. </Grid>
  97. </Grid>
  98. :
  99. (
  100. <Grid container sx={{ minHeight: '110vh', backgroundColor: 'backgroundColor.default' }} direction="column" justifyContent="flex-start" alignItems="center" >
  101. <Grid item xs={12} width="100%">
  102. <div style={BackgroundHead} width="100%">
  103. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  104. <Typography ml={15} color='#FFF' variant="h4">Proof Record</Typography>
  105. </Stack>
  106. </div>
  107. </Grid>
  108. <Grid item xs={12} width="100%">
  109. <Button title="Back" sx={{ ml: 6, mt: 2.5 }} style={{ border: '2px solid' }} variant="outlined" onClick={() => { navigate("/proof/search") }}>
  110. <ForwardIcon style={{ height: 30, width: 50, transform: "rotate(180deg)" }} />
  111. </Button>
  112. </Grid>
  113. {/*row 1*/}
  114. <Grid item xs={12} md={12} >
  115. <Grid container justifyContent="flex-start" alignItems="center" direction="column">
  116. <center>
  117. <Grid item xs={12} md={12} sx={{ pt: 2, ml: 6, mr: 6, }}>
  118. <Box xs={12} md={12} sx={{ p: 4, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  119. <ApplicationDetails
  120. // setBackButtonPos={setBackButtonPos}
  121. formData={record}
  122. showCancelBtn={showCancelBtn}
  123. showProofBtn={showProofBtn}
  124. style={{
  125. display: "flex",
  126. height: "100%",
  127. flex: 1
  128. }}
  129. />
  130. </Box>
  131. </Grid>
  132. <Grid item xs={12} md={12} sx={{ pt: 3, pb: 2, ml: 6, mr: 6, }}>
  133. <Box xs={12} md={12} sx={{ p: 4, borderRadius: '10px', backgroundColor: '#ffffff' }}>
  134. <ProofForm
  135. formData={record}
  136. isOverTime={isOverTime}
  137. />
  138. </Box>
  139. </Grid>
  140. </center>
  141. </Grid>
  142. </Grid>
  143. {/*row 2*/}
  144. </Grid >
  145. )
  146. );
  147. };
  148. export default Index;