React

by kvarma1012

HTML

<div id="app"></div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

.done {
  color: rgba(0, 0, 0, 0.3);
  text-decoration: line-through;
}

input {
  margin-right: 5px;
}

React

import React, { useState, useCallback } from 'react';
import 'handsontable/dist/handsontable.min.css';
import { HotTable  } from '@handsontable/react';
import axios from 'axios'; 

const HandsonTableComponent = () => {
  const [tableData, setTableData] = useState([
    ['', '', '', '', '', ''],
    ['', '', '','', '', ''],
  ]);

  const optionsForSystems = [
    'Substructure',
    'Superstructure',
    'Mechanical Services',
    'Electrical Services',
    'Public Health & Hydraulics',
  ];

  const optionsForSubSystem = {
    'Mechanical Services': ['Cooling', 'Heating', 'Process', 'Ventilation'],
    'Superstructure': ['Floorplate', 'Vertical Structure', 'Roof', 'Stability', 'Stairs'],
    'Substructure': ['Basement Frame', 'Ground Slab', 'Foundation', 'Basement Perimeter'],
    'Electrical Services': ['Electrical', 'Renewables', 'Lighting', 'Security', 'Vertical Transport'],
    'Public Health & Hydraulics': ['Cold Water', 'Hot Water', 'Piped Fire Systems', 'Piped Fuel'],
  };

    // Function to handle button click event
    const handleButtonClick = (row) => {
      const rowData = tableData[row];
      console.log('Button clicked for row:', row, rowData);
  
      // Example API call using Axios
      axios.post(`${process.env.REACT_APP_APPLICATION_API}/handsontable/submit`, { rowData })
        .then(response => {
          console.log('API response:', response.data);
          const updatedData = tableData.map((row) => [...row]); // Clone the data
          updatedData[row][4] = response.data['response1']
          updatedData[row][5] = response.data['response2']
          setTableData(updatedData);
          // Handle the response here
        })
        .catch(error => {
          console.error('API error:', error);
          // Handle the error here
        });
    };

  const columns = [
    {
      type: 'dropdown',
      source: optionsForSystems,
    },
    {
      type: 'dropdown',
     source: (query, process) => {
        // Adding debug logs...