ProductRegist.js 4.64 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import React, { useState, useEffect, useRef } from 'react';
kusang96's avatar
kusang96 committed
2
3
import MainNav from '../Components/MainNav';
import SubNav from '../Components/SubNav';
Jiwon Yoon's avatar
Jiwon Yoon committed
4
import { Row, Col, Button, Form, Container } from 'react-bootstrap';
Jiwon Yoon's avatar
Jiwon Yoon committed
5
import axios from 'axios'
Jiwon Yoon's avatar
Jiwon Yoon committed
6

Kim, Subin's avatar
Kim, Subin committed
7
8

function ProductsRegist() {
Jiwon Yoon's avatar
Jiwon Yoon committed
9
10
11
12
    const [product, setProduct] = useState()

    function handleChange(event) {
        const { name, value } = event.target
kusang96's avatar
kusang96 committed
13
14
        console.log("file=",event.target.files)
        console.log("name=",name,"value=",value)
Jiwon Yoon's avatar
Jiwon Yoon committed
15
16
17
18
19
        setProduct({ ...product, [name]: value })
    }

    function handleSubmit(e) {
        e.preventDefault()
kusang96's avatar
kusang96 committed
20
21
22
23
24
25
        const formData = new FormData();
        for (let key of Object.keys(product)) {
            formData.append(key, product[key])
        }
        console.log("formData=",formData)
        axios.post('/api/product/regist',{data: formData}).then(function(res) {
Jiwon Yoon's avatar
Jiwon Yoon committed
26
27
28
29
            console.log("client의 res=", res)
        })
    }

Kim, Subin's avatar
Kim, Subin committed
30
31
    return (
        <div>
Jiwon Yoon's avatar
Jiwon Yoon committed
32
            {console.log(product)}
kusang96's avatar
kusang96 committed
33
34
            <MainNav />
            <SubNav />
Jiwon Yoon's avatar
Jiwon Yoon committed
35
36
            <Container>
                <Row className="justify-content-md-center">
Jiwon Yoon's avatar
Jiwon Yoon committed
37
                    <Col md={6} className="border m-5 p-3" style={{ background: '#F7F3F3' }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
38
                        <h2 className="text-center mt-5 font-weight-bold">상품등록</h2>
Jiwon Yoon's avatar
Jiwon Yoon committed
39
                        <Form className="p-5" onSubmit={handleSubmit}>
Jiwon Yoon's avatar
Jiwon Yoon committed
40
41
                            <Form.Group controlId="productNameform">
                                <Form.Label>상품명</Form.Label>
Jiwon Yoon's avatar
Jiwon Yoon committed
42
                                <Form.Control type="text" name="pro_name" placeholder="상품명" onChange={handleChange} />
Jiwon Yoon's avatar
Jiwon Yoon committed
43
44
                            </Form.Group>
                            <Form.Group controlId="productAmountform">
Jiwon Yoon's avatar
Jiwon Yoon committed
45
46
                                <Form.Label>재고</Form.Label>
                                <Form.Control type="text" name="stock" placeholder="숫자만 입력해주세요" onChange={handleChange} />
Jiwon Yoon's avatar
Jiwon Yoon committed
47
48
49
                            </Form.Group>
                            <Form.Group controlId="productPriceform">
                                <Form.Label>가격</Form.Label>
Jiwon Yoon's avatar
Jiwon Yoon committed
50
                                <Form.Control type="text" name="price" placeholder="숫자만 입력해주세요" onChange={handleChange} />
Jiwon Yoon's avatar
Jiwon Yoon committed
51
52
53
54
55
                            </Form.Group>
                            <Form.Group>
                                <Form.Label>분류</Form.Label>
                                <Row>
                                    <Col md={6}>
Jiwon Yoon's avatar
Jiwon Yoon committed
56
                                        <Form.Control as="select" name="main_category" placeholder="상위분류" onChange={handleChange}>
Jiwon Yoon's avatar
Jiwon Yoon committed
57
58
59
60
61
62
                                            <option>Pants</option>
                                            <option>Skirt</option>
                                            <option>Outer</option>
                                        </Form.Control>
                                    </Col>
                                    <Col md={6}>
Jiwon Yoon's avatar
Jiwon Yoon committed
63
                                        <Form.Control as="select" name="sub_category" placeholder="하위분류" onChange={handleChange}>
64
65
66
                                            <option>JEANS</option>
                                            <option>SKINNY JEANS</option>
                                            <option>BANDING PANTS</option>
Jiwon Yoon's avatar
Jiwon Yoon committed
67
68
69
70
71
72
                                        </Form.Control>
                                    </Col>
                                </Row>
                            </Form.Group>
                            <Form.Group controlId="productDescriptionform">
                                <Form.Label>상품설명</Form.Label>
Jiwon Yoon's avatar
Jiwon Yoon committed
73
                                <Form.Control as="textarea" name="description" rows={3} placeholder="상품을 설명해주세요" onChange={handleChange} />
Jiwon Yoon's avatar
Jiwon Yoon committed
74
75
76
                            </Form.Group>
                            <Form.Group>
                                <Form.Label>대표이미지</Form.Label>
Jiwon Yoon's avatar
Jiwon Yoon committed
77
78
79
80
81
                                <Form.File id="productImageform" name="main_image" onChange={handleChange} />
                            </Form.Group>
                            <Form.Group>
                                <Form.Label>상세이미지</Form.Label>
                                <Form.File id="productImageform" name="detail_image" onChange={handleChange} />
Jiwon Yoon's avatar
Jiwon Yoon committed
82
                            </Form.Group>
Jiwon Yoon's avatar
Jiwon Yoon committed
83
                            <Button className="float-right" variant="primary" type="submit" style={{ background: '#91877F', borderColor: '#91877F' }}>등록</Button>
Jiwon Yoon's avatar
Jiwon Yoon committed
84
85
86
87
                        </Form>
                    </Col>
                </Row>
            </Container>
Kim, Subin's avatar
Kim, Subin committed
88
89
90
91
92
        </div>
    )
}

export default ProductsRegist