You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
5.2 KiB

  1. import React from 'react'
  2. import Link from 'next/link'
  3. import * as Icon from 'react-feather'
  4. import { useSelector, useDispatch } from 'react-redux'
  5. import { useToasts } from 'react-toast-notifications'
  6. import { useRouter } from 'next/router'
  7. import QtyForm from './QtyForm'
  8. //library yarn
  9. import NumberFormat from 'react-number-format';
  10. const CartContent = function ({ backend, cart_product, ...props }) {
  11. const router = useRouter()
  12. const { addToast } = useToasts()
  13. const dispatch = useDispatch()
  14. const cart = useSelector((state) => state.cart)
  15. const total = useSelector((state) => state.total)
  16. // console.log(cart)
  17. const removeItem = () => {
  18. dispatch({
  19. type: 'REMOVE_ITEM',
  20. id: pId
  21. })
  22. addToast('Cart Removed Successfully', { appearance: 'error' })
  23. }
  24. const reset = () => {
  25. dispatch({
  26. type: 'RESET'
  27. })
  28. addToast('Thanks for your order.', { appearance: 'success' })
  29. router.push('/')
  30. }
  31. return (
  32. <>
  33. <div className="cart-table table-responsive">
  34. <table className="table table-bordered">
  35. <thead>
  36. <tr>
  37. <th scope="col">Product</th>
  38. <th scope="col">Nama Product</th>
  39. <th scope="col">Warna Product</th>
  40. <th scope="col">Harga Product</th>
  41. <th scope="col">Jumlah</th>
  42. <th scope="col">Total</th>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. {cart_product.length ? cart_product.map(data => (
  47. <tr key={data.id}>
  48. <td className="product-thumbnail">
  49. <Link href="/product-details">
  50. <a>
  51. <img src={`${backend}${data.product_img["url"]}`} alt="item" />
  52. </a>
  53. </Link>
  54. </td>
  55. <td className="product-name">
  56. <Link href="/product-details">
  57. <a>{data.product_name}</a>
  58. </Link>
  59. </td>
  60. <td className="product-name">
  61. <Link href="/product-details">
  62. <a>{data.product_color}</a>
  63. </Link>
  64. </td>
  65. <td className="product-price">
  66. <span className="unit-amount"><NumberFormat value={data.product_price} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /></span>
  67. </td>
  68. <td className="product-quantity">
  69. <QtyForm {...data} />
  70. </td>
  71. <td className="product-subtotal">
  72. <span className="subtotal-amount"><NumberFormat value={(2 * data.product_price).toFixed(2)} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /></span>
  73. <a href="#" className="remove" onClick={() => {removeItem(data.id)}}>
  74. <Icon.Trash2 />
  75. </a>
  76. </td>
  77. </tr>
  78. )) : (
  79. <tr>
  80. <td colSpan="5" className="text-center">Tidak Ada Product di Keranjang</td>
  81. </tr>
  82. )}
  83. </tbody>
  84. </table>
  85. </div>
  86. <div className="cart-buttons">
  87. <div className="row align-items-center">
  88. <div className="col-lg-7 col-md-7 col-sm-7">
  89. <div className="continue-shopping-box">
  90. <a href="/yamaha/Product/Motor" className="btn btn-light" style={{ color: 'white' }}>Continue Shopping</a>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. <div className="cart-totals">
  96. <h3>Cart Totals</h3>
  97. <ul>
  98. <li>Subtotal <span>${total.toFixed(2)}</span></li>
  99. <li>Shipping <span>$10.00</span></li>
  100. <li>Total <span><b>${(total + 10).toFixed(2)}</b></span></li>
  101. </ul>
  102. <Link href="/yamaha/Shop/Checkout">
  103. {/* <a onClick={e => {
  104. e.preventDefault();
  105. reset()
  106. }} className="btn btn-primary">Proceed to Checkout</a> */}
  107. <a className="btn btn-primary">Proceed to Checkout</a>
  108. </Link>
  109. </div>
  110. </>
  111. )
  112. }
  113. export default CartContent