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.
 
 

152 regels
5.4 KiB

  1. // material-ui
  2. import * as React from "react";
  3. import * as HttpUtils from "utils/HttpUtils";
  4. import * as UrlUtils from "utils/ApiPathConst";
  5. import * as FormatUtils from "utils/FormatUtils";
  6. import * as DateUtils from "utils/DateUtils";
  7. import { useIntl } from "react-intl";
  8. import { useNavigate } from "react-router-dom";
  9. import {
  10. Grid,
  11. Radio,
  12. FormControlLabel
  13. } from '@mui/material';
  14. import Loadable from 'components/Loadable';
  15. import { lazy } from 'react';
  16. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  17. const PublicNoticeApplyForm = Loadable(lazy(() => import('./PublicNoticeApplyForm')));
  18. import usePageTitle from "components/usePageTitle";
  19. import {
  20. // isORGLoggedIn,
  21. isDummyLoggedIn,
  22. // checkIsOnlyOnlinePaymentByIssueDate,
  23. // checkIsOnlyOnlinePayment
  24. // isCreditorLoggedIn
  25. } from "utils/Utils";
  26. import { fetchOrgBrData, applyBlockVariant } from "utils/orgBrUtils";
  27. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  28. const ApplyForm = () => {
  29. usePageTitle("applyPublicNotice");
  30. const [userData, setUserData] = React.useState(null);
  31. const [gazetteIssueList, setGazetteIssueList] = React.useState([]);
  32. const [selections, setSelection] = React.useState([]);
  33. const [isLoading, setLoding] = React.useState(true);
  34. const [orgBrReady, setOrgBrReady] = React.useState(false);
  35. const intl = useIntl();
  36. const navigate = useNavigate();
  37. const { locale } = intl;
  38. React.useEffect(() => {
  39. loadUserData();
  40. fetchOrgBrData({
  41. onSuccess: (org) => {
  42. if (applyBlockVariant(org)) {
  43. navigate("/dashboard", { replace: true });
  44. return;
  45. }
  46. setOrgBrReady(true);
  47. }
  48. });
  49. }, []);
  50. const loadUserData = () => {
  51. setLoding(true);
  52. HttpUtils.get({
  53. url: `${UrlUtils.GET_PUBLIC_NOTICE_getApplyUser}`,
  54. onSuccess: function (response) {
  55. response["tel_countryCode"] = response?.contactTelNo?.countryCode;
  56. response["fax_countryCode"] = response?.contactFaxNo?.countryCode;
  57. response["phoneNumber"] = response?.contactTelNo?.phoneNumber;
  58. response["faxNumber"] = response?.contactFaxNo?.faxNumber;
  59. response["issueId"] = response?.gazetteIssueList[0].id;
  60. response["remarks"] = "";
  61. if (isDummyLoggedIn()){
  62. response["contactPerson"] = "";
  63. response["phoneNumber"] = "";
  64. response["faxNumber"] = "";
  65. }
  66. var selection = [];
  67. for (var i = 0; i < response?.gazetteIssueList?.length; i++) {
  68. let data = response.gazetteIssueList[i];
  69. //let label = getIssueLabel(data);
  70. selection.push(<FormControlLabel key={data.id} value={data.id} control={<Radio />} label={getIssueLabel(data)} />);
  71. }
  72. setGazetteIssueList(response?.gazetteIssueList);
  73. setSelection(selection);
  74. setUserData(response);
  75. // setOnlyOnlinePayment(checkIsOnlyOnlinePayment())
  76. }
  77. });
  78. };
  79. React.useEffect(() => {
  80. if(gazetteIssueList?.length>0){
  81. var selection = [];
  82. for (var i = 0; i < gazetteIssueList?.length; i++) {
  83. let data = gazetteIssueList[i];
  84. let label = getIssueLabel(data);
  85. selection.push(<FormControlLabel key={data.id} value={data.id} control={<Radio />} label={label} />);
  86. }
  87. setSelection(selection);
  88. }
  89. }, [locale]);
  90. const getIssueLabel=(data)=> {
  91. let issueYear = data.issueYear
  92. let volume = data.volume;
  93. let issueNo = data.issueNo;
  94. let issueDate = data.issueDate;
  95. if (locale === 'zh-HK') {
  96. return issueYear
  97. + " 第" + volume + "卷,"
  98. + " 第" + issueNo + "期,"
  99. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  100. + " (" + DateUtils.getWeekdayStr_ZH(issueDate) + ")";
  101. } else if (locale === 'zh-CN') {
  102. return issueYear
  103. + " 第" + volume + "卷,"
  104. + " 第" + issueNo + "期,"
  105. + " " + DateUtils.dateFormat(issueDate, "YYYY年MM月DD日")
  106. + " (" + DateUtils.getWeekdayStr_CN(issueDate) + ")";
  107. }
  108. return issueYear
  109. + " Vol. " + FormatUtils.zeroPad(volume, 3)
  110. + ", No. " + FormatUtils.zeroPad(issueNo, 2)
  111. + ", " + DateUtils.dateFormat(issueDate, "D MMM YYYY (ddd)");
  112. }
  113. React.useEffect(() => {
  114. if (userData !== null && orgBrReady){
  115. setLoding(false);
  116. }
  117. }, [userData, orgBrReady]);
  118. return (
  119. isLoading ?
  120. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  121. <Grid item>
  122. <LoadingComponent />
  123. </Grid>
  124. </Grid>
  125. :
  126. <PublicNoticeApplyForm
  127. loadedData={userData}
  128. _selections={selections}
  129. gazetteIssueList = {gazetteIssueList}
  130. // isOnlyOnlinePayment = {isOnlyOnlinePayment}
  131. />
  132. );
  133. };
  134. export default ApplyForm;