Commit 4323bde1 authored by Kim, Subin's avatar Kim, Subin
Browse files

추천상품 없을 시 사라짐

parent 0fbcbeaf
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { Redirect, Link, useHistory } from 'react-router-dom'; import { Redirect, Link, useHistory } from 'react-router-dom';
import ListCard from "../Components/ListCard"; import ListCard from "../Components/ListCard";
import axios from 'axios'; import axios from 'axios';
...@@ -6,7 +6,7 @@ import catchErrors from '../utils/catchErrors'; ...@@ -6,7 +6,7 @@ import catchErrors from '../utils/catchErrors';
import { Row, Col, Form, Card, Button, Modal, Image } from 'react-bootstrap'; import { Row, Col, Form, Card, Button, Modal, Image } from 'react-bootstrap';
function Product({ match, location }) { function Product({ location }) {
const [product, setProduct] = useState(location.state) const [product, setProduct] = useState(location.state)
const [productList, setProductList] = useState([]) const [productList, setProductList] = useState([])
const [color, setColor] = useState("") const [color, setColor] = useState("")
...@@ -18,8 +18,8 @@ function Product({ match, location }) { ...@@ -18,8 +18,8 @@ function Product({ match, location }) {
const [price, setPrice] = useState(0) const [price, setPrice] = useState(0)
const [show, setShow] = useState(false); const [show, setShow] = useState(false);
let history = useHistory(); let history = useHistory();
const boxRef = useRef(null);
const handleClose = () => setShow(false); const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
useEffect(() => { useEffect(() => {
getRecommend() getRecommend()
...@@ -39,14 +39,16 @@ function Product({ match, location }) { ...@@ -39,14 +39,16 @@ function Product({ match, location }) {
try { try {
const response = await axios.get(`/api/order/recommend?products=${product.id}`) const response = await axios.get(`/api/order/recommend?products=${product.id}`)
setProductList(response.data) setProductList(response.data)
if (response.data.length == 0) {
boxRef.current.style.display = "none"
}
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
} }
} }
function handleClick(e) { function handleClick() {
const box = e.target.parentNode.parentNode boxRef.current.style.display = "none"
box.style.display = "none"
} }
function pushOptions() { function pushOptions() {
...@@ -267,10 +269,10 @@ function Product({ match, location }) { ...@@ -267,10 +269,10 @@ function Product({ match, location }) {
</Col> </Col>
</Col> </Col>
</Row> </Row>
<Row className="justify-content-center mx-0 pt-3 px-2" style={{ position: "fixed", bottom: "0", width: "100%", backgroundColor: "#fff" }}> <Row ref={boxRef} className="justify-content-center mx-0 pt-3 px-2" style={{ position: "fixed", bottom: "0", width: "100%", backgroundColor: "#fff" }}>
<Col sm={12} md={8}> <Col sm={12} md={8}>
<h6 style={{ borderBottom: "1px solid", paddingBottom: "5px", marginBottom: "1em" }}>회원님이 선호할만한 상품 추천 <h6 style={{ borderBottom: "1px solid", paddingBottom: "5px", marginBottom: "1em" }}>회원님이 선호할만한 상품 추천
<a className="close float-right" onClick={(e) => handleClick(e)} style={{ fontSize: "1rem", cursor: "pointer" }}>X</a> <a className="close float-right" onClick={handleClick} style={{ fontSize: "1rem", cursor: "pointer" }}>X</a>
</h6> </h6>
<Row className="justify-content-lg-center mx-auto" style={{ flexWrap: "nowrap", width: "100%", overflowX: "auto" }}> <Row className="justify-content-lg-center mx-auto" style={{ flexWrap: "nowrap", width: "100%", overflowX: "auto" }}>
{productList.map(pro => ( {productList.map(pro => (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment