import axios from 'axios'; import React, { useState, useEffect, useRef } from 'react'; import { Row, Col, Form, Card, Button } from 'react-bootstrap'; import catchErrors from '../utils/catchErrors'; const preCart = [] function Product({ match, location }) { const [product, setProduct] = useState(location.state) const [cart, setCart] = useState(location.state) const [error, setError] = useState('') const [selected, setSelected] = useState({ sizes: false, colors: false }) const [price, setPrice] = useState(0) useEffect(() => { if (selected.sizes === true && selected.colors === true) { pushOptions() console.log(preCart) } }, [cart]) function handleClick(e) { const box = e.target.parentNode.parentNode box.style.display = "none" } function pushOptions() { preCart.push(cart) selected.sizes = false selected.colors = false setPrice(product.price+price) } function handleChange(e) { const { name, value } = e.target if (e.target.name === "sizes") { setCart({ ...cart, [name]: value }) selected.sizes = true } else if (e.target.name === "colors") { setCart({ ...cart, [name]: value }) selected.colors = true } // setCart({ ...cart, [name]: value }) // handleCreate() } function listDelete(e) { e.preventDefault() const parent = e.target.parentNode parent.remove() } function handleCreate() { // if (product !== undefined) { // if (product.colors !== "" && product.sizes !== "") { // cart.push( //
//

{product.color} {product.size}

// //

{product.price}

//
// ) // const list = document.getElementById('list') // list.style.borderBottom = "1px solid" // const shopping = document.createElement('div') // shopping.className = "d-flex justify-content-between my-2" // shopping.innerHTML = `${product.color} / ${product.size} // //

14,000원

` // const deleteA = document.createElement('a') // deleteA.innerText = 'X' // deleteA.addEventListener('click', listDelete) // shopping.appendChild(deleteA) // list.appendChild(shopping) // } // } } async function addCart() { // preCart(color, size, count), productId(productlist에서 props), userId(로컬) 를 보내줌 try { setError('') const response = await axios.put('/api/cart/addcart', { userId: localStorage.getItem('loginStatus'), productId: "a8f4d63ead77717f940a2b27deb707a6", products: preCart }) console.log(response) } catch (error) { catchErrors(error, setError) } } // useEffect(() => { // handleCreate() // }, [product]) return (
{console.log("match=",match.params, "location=",location.state, "product=",product)}

{product.name}

가격 : {product.price}원
색상 {product.colors.map((e) => ( ))} 사이즈 {product.sizes.map((e) => ( ))} {preCart.map((e) => (
{e.colors}/{e.sizes}
))} 총 금액 {price}원

설명

회원님이 선호할만한 상품 추천 handleClick(e)} style={{ fontSize: "1rem" }}>X
클로타탄원피스 구매자 수: 30 클로타탄원피스 구매자 수: 30 클로타탄원피스 구매자 수: 30 클로타탄원피스 구매자 수: 30
) } export default Product