исключила добавление повторяющихся

This commit is contained in:
Ino 2023-04-28 11:16:11 +04:00
parent 5364651da2
commit 2b40c29f36
3 changed files with 16 additions and 4 deletions

View File

@ -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
}

View File

@ -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 ('Такой продукт уже был добавлен')
})
}

View File

@ -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)])