您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

119 行
4.4 KiB

  1. // material-ui
  2. import {
  3. Box,
  4. Grid, Typography
  5. } from '@mui/material';
  6. import ConsultantForm from "./ConsultantForm";
  7. import {useContext, useEffect, useState} from "react";
  8. import * as React from "react";
  9. import axios from "axios";
  10. import {apiPath} from "../../../auth/utils";
  11. import {
  12. GET_CONSULTANT_PATH,
  13. } from "../../../utils/ApiPathConst";
  14. import LoadingComponent from "../../extra-pages/LoadingComponent";
  15. import {useLocation, useParams} from "react-router-dom";
  16. import ApplicationTable from "./ApplicationTable";
  17. import MainCard from "../../../components/MainCard";
  18. import AbilityContext from "../../../components/AbilityProvider";
  19. import {LIONER_FORM_THEME, CARD_MAX_WIDTH} from "../../../themes/themeConst";
  20. import {ThemeProvider} from "@emotion/react";
  21. import {isObjEmpty} from "../../../utils/Utils";
  22. import { el } from 'date-fns/locale';
  23. const ConsultantPanel = () => {
  24. const { id } = useParams();
  25. const location = useLocation();
  26. const queryParams = new URLSearchParams(location.search);
  27. const [onReady, setOnReady] = useState(false);
  28. const [isNewRecord, setIsNewRecord] = useState(false);
  29. const [consultantDetail, setConsultantDetail] = useState({});
  30. function getConsultantDetail(consultantId) {
  31. axios.get(`${apiPath}${GET_CONSULTANT_PATH}/${consultantId}`,
  32. )
  33. .then((response) => {
  34. if (response.status === 200) {
  35. setConsultantDetail(response.data.data);
  36. console.log("response.data:" + response.data.name);
  37. // This is the correct place to set the ready state
  38. setOnReady(true);
  39. }
  40. })
  41. .catch(error => {
  42. console.log(error);
  43. // Handle the error by still setting onReady to true, but maybe with a message
  44. setOnReady(true);
  45. return false;
  46. });
  47. }
  48. useEffect(() => {
  49. // Check if id is defined and not null
  50. if(id){
  51. // Check if it's a new record based on a negative ID
  52. if (Number(id) < 0) {
  53. setIsNewRecord(true);
  54. // Set ready state for new records immediately
  55. setOnReady(true);
  56. } else {
  57. setIsNewRecord(false);
  58. getConsultantDetail(id);
  59. }
  60. } else {
  61. // This block will handle cases where 'id' is undefined or null
  62. // If the route is /consultant without an ID, treat it as a new record.
  63. setIsNewRecord(true);
  64. setOnReady(true);
  65. }
  66. }, [id]);
  67. useEffect(() => {
  68. // This code will only run AFTER the 'onReady' state has been updated.
  69. if(consultantDetail)
  70. console.log("consultantDetail:" + consultantDetail.name);
  71. else
  72. console.log("consultantDetail null");
  73. }, [onReady]); // The dependency array ensures this runs when onReady changes.
  74. useEffect(() => {
  75. // This code will only run AFTER the 'onReady' state has been updated.
  76. if (onReady === true) {
  77. console.log("The component is now ready!");
  78. }
  79. }, [setConsultantDetail]); // The dependency array ensures this runs when onReady changes.
  80. return (
  81. !onReady ?
  82. <LoadingComponent/>
  83. :
  84. <Grid container rowSpacing={3} columnSpacing={2.75} >
  85. <ThemeProvider theme={LIONER_FORM_THEME}>
  86. <Grid item xs={12} s={12} md={12} lg={12}>
  87. <Grid container justifyContent="flex-start" alignItems="center">
  88. <Grid item xs={3} sx={{mt:-1, mb: -2.25}} >
  89. <Box sx={{ display: 'flex', alignItems: 'center'}}>
  90. <Typography align="center" variant="h4" >{isNewRecord? "New Consultant" : "Maintain Consultant"}</Typography>
  91. </Box>
  92. </Grid>
  93. </Grid>
  94. </Grid>
  95. {/*row 1*/}
  96. <Grid item xs={12} md={12} lg={12} >
  97. <ConsultantForm
  98. getConsultantDetail={getConsultantDetail}
  99. refConsultantDetail={consultantDetail}
  100. isNewRecord={isNewRecord}
  101. />
  102. </Grid>
  103. </ThemeProvider>
  104. </Grid>
  105. );
  106. };
  107. export default ConsultantPanel;