vandasche

Untitled

Jun 4th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { connect } from "react-redux";
  3. import * as actStock from "../_actions/storage";
  4. import NumberFormat from "react-number-format";
  5. import { Table } from "react-bootstrap";
  6.  
  7. class Storage extends Component {
  8. state = {
  9. modal: false,
  10. };
  11.  
  12. componentDidMount() {
  13. this.props.dispatch(actStock.getStocks());
  14. }
  15.  
  16. showModal = () => {
  17. this.setState({ modal: true });
  18. };
  19. hideModal = () => {
  20. this.setState({ modal: true });
  21. };
  22.  
  23. render() {
  24. const { data: stocks, loading, error } = this.props.stock;
  25. console.log(stocks);
  26. if (loading) return <h1>Loading</h1>;
  27. if (error) return <h1>ERROR</h1>;
  28.  
  29. return (
  30. <div>
  31. <h1>DATA STOCK BARANG</h1>
  32. <Table striped bordered hover>
  33. <thead>
  34. <tr>
  35. <th>No</th>
  36. <th>Barang</th>
  37. <th>Jenis</th>
  38. <th>Harga</th>
  39. <th>Quantity</th>
  40. <th>Action</th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. {stocks.map((item, index) => (
  45. <tr key={index}>
  46. <th>{index + 1}</th>
  47. <td>{item.namaProduk}</td>
  48. <td>{item.category.jenisProduk}</td>
  49. <td>
  50. <NumberFormat
  51. value={item.harga}
  52. displayType={"text"}
  53. thousandSeparator={true}
  54. prefix={"Rp. "}
  55. />
  56. </td>
  57. <td>{item.quantity}</td>
  58.  
  59. <td>
  60. <button className="button" onClick={this.showModal}>
  61. EDIT
  62. </button>
  63. <button style={{ marginLeft: 20 }} className="button">
  64. DELETE
  65. </button>
  66. </td>
  67. </tr>
  68. ))}
  69. </tbody>
  70. </Table>
  71. </div>
  72. );
  73. }
  74. }
  75.  
  76. const mapStateToProps = (state) => {
  77. return {
  78. stock: state.stock,
  79. };
  80. };
  81.  
  82. export default connect(mapStateToProps)(Storage);
Add Comment
Please, Sign In to add comment