vandasche

Untitled

Jun 4th, 2020
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { connect } from "react-redux";
  3. import * as actOrder from "../_actions/order";
  4. import { Table } from "react-bootstrap";
  5. import NumberFormat from "react-number-format";
  6. import ModalTransaction from "./modalOrder";
  7.  
  8. class Transaction extends Component {
  9. state = {
  10. modal: false,
  11. };
  12. showModal = () => {
  13. this.setState({ modal: true });
  14. };
  15. hideModal = () => {
  16. this.setState({ modal: false });
  17. };
  18.  
  19. componentDidMount() {
  20. this.props.dispatch(actOrder.getOrders());
  21. }
  22.  
  23. render() {
  24. const { data: order, loading, error } = this.props.order;
  25. console.log(order);
  26. if (loading) return <h1>Loading</h1>;
  27. if (error) return <h1>ERROR</h1>;
  28.  
  29. return (
  30. <div>
  31. <ModalTransaction show={this.showModal} onHide={this.hideModal}/>
  32. <h1>DATA PENJUALAN</h1>
  33. <Table striped bordered hover>
  34. <thead>
  35. <tr>
  36. <th>No</th>
  37. <th>Customer</th>
  38. <th>Total Barang</th>
  39. <th>Total Harga</th>
  40. <th>Action</th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. {order &&
  45. order.length > 0 &&
  46. order.map((item, index) => (
  47. <tr key={index}>
  48. <th>{index + 1}</th>
  49. <td>{item.customer.nama}</td>
  50. <td>{item.quantity}</td>
  51. <td>
  52. <NumberFormat
  53. value={item.total}
  54. displayType={"text"}
  55. thousandSeparator={true}
  56. prefix={"Rp. "}
  57. />
  58. </td>
  59. <td>
  60. <button className="button" onClick={this.showModal}>
  61. VIEW
  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. order: state.order,
  79. };
  80. };
  81.  
  82. export default connect(mapStateToProps)(Transaction);
Add Comment
Please, Sign In to add comment