Commit 32e08aba authored by 박상호's avatar 박상호 🎼
Browse files

Merge remote-tracking branch 'origin/ourMaster' into sangho

parents fe776813 81cf0c68
import './App.css';
import { BrowserRouter as Router, Route, Redirect, Switch } from 'react-router-dom';
import PrivateRoute from "./Components/PrivateRoute";
import AdminRoute from "./Components/AdminRoute";
import Home from './Pages/Home';
import Login from './Pages/Login';
import Signup from './Pages/Signup';
......@@ -26,12 +27,25 @@ function App() {
<Route path="/product/:productId" component={Product} />
<Route path="/categories/:main/:sub" component={ProductsList} />
<Route path="/categories/:main" component={ProductsList} />
<Route path="/admin" component={Admin} />
<Route path="/regist" component={ProductRegist} />
<Route path="/shoppingcart" component={ShoppingCart} />
<Route path="/payment" component={Payment} />
<Route path="/account" component={Account} />
<Route path='/kakao' component={() => { window.location.href = 'https://compmath.korea.ac.kr'; return null; }} />
<AdminRoute path="/admin">
<Admin />
</AdminRoute>
<AdminRoute path="/regist">
<ProductRegist />
</AdminRoute>
<PrivateRoute path="/shoppingcart">
<ShoppingCart />
</PrivateRoute>
<PrivateRoute path="/payment">
<Payment />
</PrivateRoute>
<PrivateRoute path="/account">
<Account />
</PrivateRoute>
{/* <PrivateRoute path='/kakao'>
</PrivateRoute>
<Route component={() => { window.location.href = 'https://compmath.korea.ac.kr'; return null; }} /> */}
<Redirect path="/" to="/" />
</Switch>
</Router>
......
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import { isAdmin } from '../utils/auth';
function PrivateRoute({path, children}) {
if (isAdmin()) {
return (
<Route path={path}>
{children}
</Route>
)
} else {
alert('궈한이 없습니다. 죄송합니다.');
return (
<Redirect to='/' />
)
}
}
export default PrivateRoute
\ No newline at end of file
import React from 'react';
import { Navbar, Nav } from 'react-bootstrap';
import { handleLogout, isAuthenticated } from '../utils/auth';
import { handleLogout, isAuthenticated, isAdmin } from '../utils/auth';
function MainNav() {
const user = isAuthenticated()
const admin = isAdmin()
return (
<Navbar sticky="top" style={{ background: "#CDC5C2" }}>
......@@ -15,6 +15,9 @@ function MainNav() {
<Nav className="ml-auto">
{user ? <> <Nav.Link className="text-light" onClick={() => handleLogout()}>Logout</Nav.Link>
<Nav.Link className="text-light" href="/account"> Mypage </Nav.Link>
<Nav.Link href="/shoppingcart">
<img alt="카트" src="/icon/cart.svg" width="30" height="30" />
</Nav.Link>
</>
: (
<>
......@@ -22,12 +25,9 @@ function MainNav() {
<Nav.Link className="text-light" href='/signup'>Sign Up</Nav.Link>
</>
)}
<Nav.Link href="/shoppingcart">
<img alt="카트" src="/icon/cart.svg" width="30" height="30" />
</Nav.Link>
<Nav.Link href="/admin">
{admin ? <Nav.Link href="/admin">
<img alt="관리자" src="/icon/option.svg" width="30" height="30" />
</Nav.Link>
</Nav.Link> : ''}
</Nav>
</Navbar>
)
......
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import { isAuthenticated } from '../utils/auth';
function PrivateRoute({path, children}) {
if (isAuthenticated()) {
return (
<Route path={path}>
{children}
</Route>
)
} else {
alert('회원이 아닙니다. 로그인 및 회원가입을 진행해 주세요.');
return (
<Redirect to='/' />
)
}
}
export default PrivateRoute
\ No newline at end of file
......@@ -26,7 +26,7 @@ function SubNav() {
}, [])
return (
<Navbar sticky="top" className="flex-nowrap" style={{ top: "62px", paddingTop: "0", paddingBottom: "0", backgroundColor: "#fff" }}>
<Navbar sticky="top" className="flex-nowrap" style={{ top: "56px", paddingTop: "0", paddingBottom: "0", backgroundColor: "#fff" }}>
<style type="text/css">
{`
.nav-link, .nav-link:hover, .nav-link:active {
......
......@@ -16,6 +16,7 @@ function Account() {
const [proshow, setProshow] = useState(false)
const [error, setError] = useState("")
const userId = isAuthenticated()
const [ordered, setOrdered] = useState('')
async function getUsername(user) {
// console.log("tlg")
......@@ -31,6 +32,7 @@ function Account() {
useEffect(() => {
getUsername(userId)
getOrdered(userId)
}, [userId])
const handleChange = (event) => {
......@@ -81,6 +83,17 @@ function Account() {
}
}
async function getOrdered({}) {
console.log("object")
try {
const response = await axios.get(`/api/users/addorder`)
setOrdered(response.data)
console.log('@@@@', response.data);
} catch (error) {
catchError(error, setError)
}
}
return (
<Container className="px-3">
<style type="text/css">
......@@ -105,7 +118,7 @@ function Account() {
)}
</Button>
<Modal show={show} onHide={() => setShow(false)}>
<Modal.Header closeButton style={{background:"#F7F3F3"}}>
<Modal.Header closeButton style={{ background: "#F7F3F3" }}>
<Modal.Title >이미지를 변경하시겠습니까?</Modal.Title>
</Modal.Header>
<Form onSubmit={handleSubmit}>
......@@ -136,7 +149,7 @@ function Account() {
size="sm"
show={proshow}
onHide={() => setProshow(false)}>
<Modal.Header closeButton style={{background:"#F7F3F3"}}>
<Modal.Header closeButton style={{ background: "#F7F3F3" }}>
<Modal.Title>회원정보</Modal.Title>
</Modal.Header>
<Modal.Body>
......
......@@ -8,9 +8,8 @@ import { isAuthenticated } from '../utils/auth';
import catchErrors from '../utils/catchErrors';
function Payment({ match, location }) {
const [cart, setCart] = useState([])
const [order, setOrder] = useState({ products: [] })
const [order, setOrder] = useState({products: []})
const [userData, setUserData] = useState({})
const [error, setError] = useState()
const [paymentWay, setPaymentWay] = useState([])
......@@ -202,6 +201,8 @@ function Payment({ match, location }) {
return <Redirect to={'/kakao'} />
}
return (
<div>
{/* {console.log(order)} */}
......
import React, { useState, useEffect, useRef } from 'react';
import { Link, Redirect } from 'react-router-dom';
import { Card, Button, Container, Row, Col } from 'react-bootstrap';
import { Button, Container, Row, Col } from 'react-bootstrap';
import axios from 'axios';
import catchErrors from '../utils/catchErrors';
import { isAuthenticated } from '../utils/auth'
import { isAuthenticated } from '../utils/auth';
import CartCard from '../Components/CartCard';
function ShoppingCart() {
......@@ -134,7 +134,6 @@ function ShoppingCart() {
}} className="px-5" style={{ background: "#91877F", borderColor: '#91877F' }} onClick={putCheckedCart} block>결제하기</Button>
</div>
</Container>
</div>
)
}
......
......@@ -118,9 +118,7 @@ function Signup() {
onChange={handleChange}>
</Form.Control>
</Col>
<Col xs={2}>
<div className='font-weight-bold d-flex align-items-center'>* * * * * * </div>
</Col>
<Form.Control.Feedback type="invalid">주민등록번호를 입력하세요.</Form.Control.Feedback>
</Form.Row>
</Form.Group>
......
......@@ -32,12 +32,15 @@ const changeCart = async (req, res) => {
const showCart = async (req, res) => {
try {
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
const cart = await Cart.findOne({ userId: req.id }).populate({
path: 'products.productId',
model: 'Product'
})
res.status(200).json(cart.products)
console.log("cart-products : ", cart.products);
} catch (error) {
console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
console.log(error)
res.status(500).send('쇼핑카트를 불러오지 못했습니다.')
}
......
......@@ -12,7 +12,7 @@ const getCategory = async (req, res) => {
}
const getSubCategory = async (req, res) => {
// console.log("req.params=", req.params);
console.log("req.params=", req.params);
const { sub } = req.params
try {
const subcategory = await Category.findOne({}, { _id: 0}).select(`${sub}`)
......
......@@ -13,6 +13,17 @@ const addorder = async (req, res) => {
}
}
const Ordered = async (req, res) => {
const { db } = req.body
try {
const ordered = await req.body.findOne({}, { _id: 0}).select(`${db}`)
console.log("sub= ",ordered);
res.json(ordered);
} catch (error) {
res.status(500).send('카테고리를 불러오지 못했습니다.')
}
}
const showorder = async (req, res) => {
try {
const order = await Order.findOne({ userId: req.id }).populate({
......@@ -30,4 +41,4 @@ const showorder = async (req, res) => {
export default { addorder, showorder }
\ No newline at end of file
export default { addorder, showorder, Ordered }
\ No newline at end of file
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