bd.json:
{
"Blocks": [
{
"Image": "img",
"Name": "blocks",
"PodBlocks": [
{
"BlockName": "noName",
"Prodduct": [],
"blockId": ""
},
{
"NameProductCategory": "yesName",
"Prodduct": [],
"blockId": ""
},
],
"id": "135c"
},
{
"Image": "img",
"Name": "blocks2",
"PodBlocks": [
{
"BlockName": "noName2",
"Prodduct": [],
"blockId": ""
},
{
"BlockName": "yesName2",
"Prodduct": [],
"blockId": ""
},
],
"id": "c137"
}
}
context:
async function createProduct(newProduct) {
const {data} = await axios(API)
let elem = data.find((el) => el.id === newProduct.blockId)
let obj = {
...elem, PodBlocks: [
...elem.PodBlocks, newProduct
]
}
console.log(elem)
await axios.patch(`${API}/${newProduct.categoryId}`, obj)
}
admin:
<select onChange={(e) => {
setInputValue({...inputValue, blockId: e.target.value })
} } name="Name" id="">
{
product.map((el) => (<option value={el.id}>
{
el.Name
}
</option>))
}
</select>
необходи сделать так, чтобы можно было добавить новый продукт выбирая варинты и под варианты