Admin.js 2.11 KB
Newer Older
kusang96's avatar
kusang96 committed
1
2
import React, { useState, useEffect, useRef } from 'react';
import { Redirect } from 'react-router-dom';
kusang96's avatar
DSAD    
kusang96 committed
3
import AllCard from '../Components/AllCard';
Kim, Subin's avatar
Kim, Subin committed
4
import Pagination from '../Components/Pagination';
kusang96's avatar
kusang96 committed
5
6
import axios from 'axios';
import catchError from '../utils/catchErrors';
kusang96's avatar
DSAD    
kusang96 committed
7
import { Row, Form, FormControl, Button, Container } from 'react-bootstrap';
Kim, Subin's avatar
Kim, Subin committed
8
9

function Admin() {
kusang96's avatar
kusang96 committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    const [productlist, setProductlist] = useState([])
    const [error, setError] = useState('')

    useEffect(() => {
        getProductlist()
    }, [])

    async function getProductlist() {
        try {
            const response = await axios.get(`/api/product/getproduct/all`)
            console.log("response.data=", response.data)
            setProductlist(response.data)
        } catch (error) {
            catchError(error, setError)
        }
    }

    function handleSearch() {

kusang96's avatar
kusang96 committed
29
30
31
32
    }

    function handleSubmit(e) {
        e.preventDefault()
33
    }
Kim, Subin's avatar
Kim, Subin committed
34
35

    return (
kusang96's avatar
kusang96 committed
36
        <Container>
37
38
39
40
41
42
43
44
45
46
47
48
49
            <style type="text/css">
                {`
                .btn {
                    background-color: #CDC5C2;
                    border-color: #CDC5C2;
                }

                .btn:hover, .btn:active, .btn:focus {
                    background-color: #91877F;
                    border-color: #91877F;
                }
                `}
            </style>
kusang96's avatar
kusang96 committed
50
51
52
53
54
55
56
57
58
            <Row as={Form} onSubmit={handleSubmit} className="justify-content-end mx-0 my-5">
                <FormControl type="text" placeholder="Search" style={{ width: "13rem" }} />
                <Button type="submit" className="px-2">
                    <img src="icon/search.svg" width="20" height="20" />
                </Button>
                <Button sm={2} xs={6} type="button" href="/regist" className="ml-1">상품 등록</Button>
            </Row>
            <Row className="justify-content-center m-5">
                {productlist.map(pro => (
kusang96's avatar
DSAD    
kusang96 committed
59
                    <AllCard id={pro._id} name={pro.pro_name} price={pro.price} main_img={pro.main_imgUrl} />
kusang96's avatar
kusang96 committed
60
61
62
63
                ))}
            </Row>
            <Pagination />
        </Container>
Kim, Subin's avatar
Kim, Subin committed
64
65
66
67
    )
}

export default Admin