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

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

    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
31
32
33
34
    }

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

kusang96's avatar
kusang96 committed
37
38
39
40
41
    if(!role) {
        alert('죄송합니다.접근 권한이 없습니다.')
        return <Redirect to="/" />
    }

Kim, Subin's avatar
Kim, Subin committed
42
    return (
kusang96's avatar
kusang96 committed
43
        <Container>
44
45
46
47
48
49
50
51
52
53
54
55
56
            <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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
            <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 => (
                    <ListCard id={pro._id} name={pro.pro_name} price={pro.price} main_img={pro.main_imgUrl} />
                ))}
            </Row>
            <Pagination />
        </Container>
Kim, Subin's avatar
Kim, Subin committed
71
72
73
74
    )
}

export default Admin