diff --git a/front/src/DataService.js b/front/src/DataService.js index afe502d..7cd5077 100644 --- a/front/src/DataService.js +++ b/front/src/DataService.js @@ -42,7 +42,7 @@ export default class DataService { static async create(url, data) { const response = await axios.post(getFullUrl(this.mainUrl + url, data)) const res = response.data - console.log(res) + //console.log(res) return res } diff --git a/front/src/Pages/CreateOrderPage.jsx b/front/src/Pages/CreateOrderPage.jsx index fafd740..c689918 100644 --- a/front/src/Pages/CreateOrderPage.jsx +++ b/front/src/Pages/CreateOrderPage.jsx @@ -43,6 +43,10 @@ export default function CreateOrderPage(props){ } const createOrder = () => { + if(order.supplierId === ''){ + window.alert ('Заказ был заполнен неверно, попробуйте еще раз') + return + } DataService.create(url, order) .then(data => { order.products.map(product =>{ @@ -54,8 +58,16 @@ export default function CreateOrderPage(props){ const addProductInOrder = () => { DataService.read(`${productUrl}${addsProduct.id}`, transformerProduct) .then(data => { - order.products.push(data) - setOrder({ ...order, products: order.products }) + let contains = false + order.products.map(product => { + if(product.id === data.id) contains = true + }) + if(!contains){ + order.products.push(data) + setOrder({ ...order, products: order.products }) + } + else + window.alert ('Такой продукт уже был добавлен') }) } diff --git a/front/src/Pages/OrdersPage.jsx b/front/src/Pages/OrdersPage.jsx index d0f9856..55d5b69 100644 --- a/front/src/Pages/OrdersPage.jsx +++ b/front/src/Pages/OrdersPage.jsx @@ -24,7 +24,7 @@ export default function OrderPage(){ const loadItems = () => { DataService.getOrders(url).then(data => { - console.log(data) + // console.log(data) setOrders([]) data.map(order => { setOrders(prevState => [...prevState, new Order(order)])