import React from 'react' import Link from 'next/link' import * as Icon from 'react-feather' import { useSelector, useDispatch } from 'react-redux' import { useToasts } from 'react-toast-notifications' import { useRouter } from 'next/router' import QtyForm from './QtyForm' //library yarn import NumberFormat from 'react-number-format'; //sweet alert import swal from 'sweetalert'; const CartContent = function ({ backend, cart_product, ...props }) { const router = useRouter() const { addToast } = useToasts() const dispatch = useDispatch() const cart = useSelector((state) => state.cart) const total = useSelector((state) => state.total) // console.log(cart) const [qty, setQty] = React.useState(1) const increment = () => { setQty(qty + 1) } const decrement = () => { setQty(qty - 1) } const removeItem = () => { dispatch({ type: 'REMOVE_ITEM', id: pId }) addToast('Cart Removed Successfully', { appearance: 'error' }) } const reset = () => { dispatch({ type: 'RESET' }) addToast('Thanks for your order.', { appearance: 'success' }) router.push('/') } const [formValue, setFormValue] = React.useState({ transaction_id: GenerateID(), product_img: "", product_name: "", product_color: "", product_quantity: "", product_total: "", }); function GenerateID() { var dt = new Date().getTime(); var uuid = 'Trx-Ord-yyyyyyyy'.replace(/[y]/g, function (c) { var r = (dt + Math.random() * 16) % 16 | 0; dt = Math.floor(dt / 16); return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); return uuid; } return (
{ e.preventDefault(); var newformValue = { ...formValue, product_name: cart_product[0].product_name, product_color: cart_product[0].product_color, } setFormValue(newformValue) console.log(JSON.stringify(newformValue)); const response = await fetch( "/api/transaction/AddToCheckout", { method: "POST", headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(newformValue), } ); if (response.ok) { var res = await response.json(); console.log("cek response :", res); if (res["STATUS"] === 1) { res["DATA"]["checkout"]; swal("Produk Berhasil Ditambah ke Keranjang", "Silahkan Cek Keranjang Belanja Anda", "success"); router.push("/yamaha/Shop/Checkout"); } else { swal("Produk Gagal di Checkout", "Silahkan Coba Lagi", "error"); } } else { swal("Transaksi Gagal", "Silahkan Coba Lagi", "error"); } return false; }} >
{cart_product.length ? cart_product.map(data => ( {/* */} )) : ( )}
Product Nama Product Warna Product Harga Product Jumlah Total
{/* item */} {data.product_name} {data.product_color}
e} name="product_quantity" onInput={(e) => { setFormValue({ ...formValue, product_quantity: e.target.value.toString(), }) }} />
{removeItem(data.id)}}> { setFormValue({ ...formValue, product_total: e.target.value, }) }} /> { removeItem(data) }}>
Tidak Ada Product di Keranjang
Continue Shopping

Cart Totals

{/* { e.preventDefault(); reset() }} className="btn btn-primary">Proceed to Checkout */}
) } export default CartContent