Advertisement
shadiff

policy1.jsx

Sep 12th, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import './Layout.css';
  3. import './pages.css';
  4. import Tabs from './Tabs';
  5. import Sidebar from './Sidebar';
  6.  
  7. class Policy extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. selectedOption: '', // Initialize the selected option state
  12. policyData: null, // Initialize the state for policy data
  13. error: null, // Initialize the state for errors
  14. };
  15. }
  16.  
  17. // Function to fetch policy data from the second API
  18. fetchPolicyData = () => {
  19. // Replace 'your-second-api-endpoint' with the actual URL of the second API.
  20. fetch('http://192.0.1.23:5000/scheme?id=12020')
  21. .then((response) => {
  22. if (!response.ok) {
  23. throw new Error('Network response was not ok');
  24. }
  25. return response.json();
  26. })
  27. .then((data) => {
  28. // Update the policyData state with the fetched data
  29. this.setState({ policyData: data, error: null });
  30. console.log('Fetched Data:', data);
  31. })
  32. .catch((error) => {
  33. // Handle errors here
  34. this.setState({ error: 'There was a problem fetching policy data: ' + error.message });
  35. });
  36. };
  37.  
  38. componentDidMount() {
  39. // Fetch policy data when the component mounts
  40. this.fetchPolicyData();
  41. }
  42.  
  43. render() {
  44. const tabNames = [
  45. 'Details',
  46. 'Rules',
  47. 'Providers',
  48. 'Insurers',
  49. 'Inclusions and Exclusions',
  50. 'Benefits',
  51. 'Family Structure',
  52. 'Self Fund Payment',
  53. 'SLAs',
  54. ];
  55.  
  56. const { policyData, error } = this.state;
  57.  
  58. return (
  59. <>
  60. <section className='Layout'>
  61. {/* ... Your existing JSX code ... */}
  62. {/* Add the code to display policy data */}
  63. <div className='main-content'>
  64. <Tabs tabNames={tabNames} />
  65. {error ? (
  66. <p>Error: {error}</p>
  67. ) : policyData ? (
  68. <div>
  69. {/* Display policy data here */}
  70. <h2>Policy Information</h2>
  71. <p>Policy Holder: {policyData.policyHolder}</p>
  72. <p>Policy Number: {policyData.policyNumber}</p>
  73. {/* Add more fields as needed */}
  74. </div>
  75. ) : (
  76. <p>Loading policy data...</p>
  77. )}
  78. </div>
  79. </section>
  80. </>
  81. );
  82. }
  83. }
  84.  
  85. export default Policy;
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement