endPoint

the Other Object·2023년 2월 23일
0
import React, {useState} from "react";


interface Props {
  productNo: string,
  quantity: number
}


const InventoryOption = (props: Props) => {

  const [productNo, setProductNo] = useState(props.productNo);
  const [quantity, setQuantity] = useState(0);
  const stock = () => {
    fetch ("/api/inventory/item", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        service: "Inventory",
        command: "Stock"
      },
      body: JSON.stringify ({
        productNo: productNo,
        quantity: quantity
      })
    })
      .then((response) => response.status)
      .then((status) => {
        console.log("OK!")
      });
  };
  const reserve = () => {
    fetch ("/api/inventory/item", {
      method: "PUT",
      headers: {
        "Content-Type": "application/json",
        service: "Inventory"
      },
      body: JSON.stringify ({
        productNo: productNo,
        orderNo: "ORD001",
        quantity: 3
      })
    })
      .then((response) => response.status)
      .then((status) => {
        console.log("SAVE")
      });
  };


  return (
    <React.Fragment>
      <div className="row">
        <div className="col">
          <input
            type="text"
            style={{ width: 180 }}
            onChange = {(e: React.ChangeEvent<HTMLInputElement>) => { 
              setQuantity (parseInt(e.target.value))
            }}
            className="form-control"
            placeholder="변경 수량을 입력해주세요"
            aria-label="Username"
          ></input>
        </div>
        <div className="col">
          <button type="button" onClick={stock} className="btn btn-primary">
            입고
          </button>
          <button type="button" onClick={reserve} className="btn btn-danger">
            예약
          </button>
        </div>
      </div>
    </React.Fragment>
  );
};

0개의 댓글