исключила добавление повторяющихся
This commit is contained in:
parent
5364651da2
commit
2b40c29f36
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 ('Такой продукт уже был добавлен')
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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)])
|
||||
|
Loading…
Reference in New Issue
Block a user