DcruzQ

Untitled

Jul 3rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component, Fragment } from "react";
  2. import { connect } from "react-redux";
  3. import PropTypes from "prop-types";
  4.  
  5. import { getLeads, deleteLead } from "../../actions/leads";
  6.  
  7. class Leads extends Component {
  8.   static propTypes = {
  9.     leads: PropTypes.array.isRequired
  10.   };
  11.  
  12.   componentDidMount() {
  13.     this.props.getLeads();
  14.   }
  15.  
  16.   render() {
  17.     return (
  18.       <Fragment>
  19.         <h2>Leads</h2>
  20.         <table className="table table-striped">
  21.           <thead>
  22.             <tr>
  23.               <th>ID</th>
  24.               <th>Namne</th>
  25.               <th>Email</th>
  26.               <th>Message</th>
  27.               <th />
  28.             </tr>
  29.           </thead>
  30.           <tbody>
  31.             {this.props.leads.map(lead => (
  32.               <tr key="{lead.id}">
  33.                 <td>{lead.id}</td>
  34.                 <td>{lead.name}</td>
  35.                 <td>{lead.email}</td>
  36.                 <td>{lead.message}</td>
  37.                 <td>
  38.                   <button
  39.                     onClick={this.props.deleteLead.bind(this, lead.id)}
  40.                     className="btn btn-danger btn-asset"
  41.                   >
  42.                     Delete
  43.                   </button>
  44.                 </td>
  45.               </tr>
  46.             ))}
  47.           </tbody>
  48.         </table>
  49.       </Fragment>
  50.     );
  51.   }
  52. }
  53.  
  54. const mapStateToProps = state => ({
  55.   leads: state.leads.leads
  56. });
  57.  
  58. export default connect(
  59.   mapStateToProps,
  60.   { getLeads }
  61. )(Leads);
Advertisement
Add Comment
Please, Sign In to add comment