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.
 
 

83 line
2.8 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 DateUtils from "utils/DateUtils";
  6. import * as FormatUtils from "utils/FormatUtils";
  7. import {
  8. Grid,
  9. Radio,
  10. FormControlLabel
  11. } from '@mui/material';
  12. import Loadable from 'components/Loadable';
  13. import { lazy } from 'react';
  14. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  15. const PublicNoticeApplyForm = Loadable(lazy(() => import('./PublicNoticeApplyForm')));
  16. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  17. const ApplyForm = () => {
  18. const [userData, setUserData] = React.useState(null);
  19. const [selections, setSelection] = React.useState([]);
  20. const [isLoading, setLoding] = React.useState(true);
  21. React.useEffect(() => {
  22. loadUserData();
  23. }, []);
  24. const loadUserData = () => {
  25. setLoding(true);
  26. HttpUtils.get({
  27. url: `${UrlUtils.GET_PUBLIC_NOTICE_getApplyUser}`,
  28. onSuccess: function (response) {
  29. response["tel_countryCode"] = response?.contactTelNo?.countryCode;
  30. response["phoneNumber"] = response?.contactTelNo?.phoneNumber;
  31. response["fax_countryCode"] = response?.contactFaxNo?.countryCode;
  32. response["faxNumber"] = response?.contactFaxNo?.faxNumber;
  33. response["issueId"] = response?.gazetteIssueList[0].id;
  34. response["remarks"] = "";
  35. var selection = [];
  36. for (var i = 0; i < response?.gazetteIssueList?.length; i++) {
  37. let data = response.gazetteIssueList[i];
  38. let label = getIssueLabel(data);
  39. selection.push(<FormControlLabel value={data.id} control={<Radio />} label={label} />);
  40. }
  41. setSelection(selection);
  42. setUserData(response);
  43. }
  44. });
  45. };
  46. function getIssueLabel(data) {
  47. return data.issueYear
  48. + " Vol. " + FormatUtils.zeroPad(data.volume, 3)
  49. + ", No. " + FormatUtils.zeroPad(data.issueNo, 2)
  50. + ", " + DateUtils.dateFormat(data.issueDate, "D MMM YYYY (ddd)");
  51. }
  52. React.useEffect(() => {
  53. if (userData !== null) setLoding(false);
  54. }, [userData]);
  55. return (
  56. isLoading ?
  57. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  58. <Grid item>
  59. <LoadingComponent />
  60. </Grid>
  61. </Grid>
  62. :
  63. <PublicNoticeApplyForm
  64. loadedData={userData}
  65. selections={selections}
  66. />
  67. );
  68. };
  69. export default ApplyForm;