access body prop before desc
This commit is contained in:
+14
-12
@@ -8,7 +8,7 @@ import './styles/app.css';
|
|||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
const [data, setData] = useState([]);
|
const [data, setData] = useState([]);
|
||||||
const [boxID, setBoxID] = useState();
|
const [boxID, setBoxID] = useState(undefined);
|
||||||
const [boxName, setBoxName] = useState('');
|
const [boxName, setBoxName] = useState('');
|
||||||
const [boxDescription, setBoxDescription] = useState('');
|
const [boxDescription, setBoxDescription] = useState('');
|
||||||
const [showModalBox, setShowModalBox] = useState(false);
|
const [showModalBox, setShowModalBox] = useState(false);
|
||||||
@@ -17,7 +17,7 @@ function App() {
|
|||||||
const [editBoxBool, setEditBoxBool] = useState(false);
|
const [editBoxBool, setEditBoxBool] = useState(false);
|
||||||
const [editItemBool, setEditItemBool] = useState(false);
|
const [editItemBool, setEditItemBool] = useState(false);
|
||||||
|
|
||||||
const [itemID, setItemID] = useState();
|
const [itemID, setItemID] = useState(undefined);
|
||||||
const [itemName, setItemName] = useState('');
|
const [itemName, setItemName] = useState('');
|
||||||
const [itemDescription, setItemDescription] = useState('');
|
const [itemDescription, setItemDescription] = useState('');
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ function App() {
|
|||||||
setData(response.data);
|
setData(response.data);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +109,7 @@ function App() {
|
|||||||
const handleSubmitBox = (event) => {
|
const handleSubmitBox = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setShowModalBox(false);
|
setShowModalBox(false);
|
||||||
|
setEditBoxBool(false);
|
||||||
const boxData = {
|
const boxData = {
|
||||||
id: boxID,
|
id: boxID,
|
||||||
name: boxName,
|
name: boxName,
|
||||||
@@ -127,7 +128,9 @@ function App() {
|
|||||||
removeBox(id);
|
removeBox(id);
|
||||||
}
|
}
|
||||||
const handleAddBox = () => {
|
const handleAddBox = () => {
|
||||||
|
clearFormBox();
|
||||||
setShowModalBox(true);
|
setShowModalBox(true);
|
||||||
|
setEditBoxBool(false);
|
||||||
}
|
}
|
||||||
const handleEditBox = (id) => {
|
const handleEditBox = (id) => {
|
||||||
const box = data.find(box => box._id === id);
|
const box = data.find(box => box._id === id);
|
||||||
@@ -138,10 +141,9 @@ function App() {
|
|||||||
setShowModalBox(true);
|
setShowModalBox(true);
|
||||||
}
|
}
|
||||||
const clearFormBox = () => {
|
const clearFormBox = () => {
|
||||||
setEditBoxBool(false);
|
|
||||||
setBoxName('');
|
setBoxName('');
|
||||||
setBoxDescription('');
|
setBoxDescription('');
|
||||||
setBoxID(null);
|
setBoxID(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -172,6 +174,7 @@ function App() {
|
|||||||
|
|
||||||
const editItem = async (boxID, itemID, itemData) => {
|
const editItem = async (boxID, itemID, itemData) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(itemData);
|
||||||
const response = await axios.put(`${api.baseApiUrl}/${boxID}/item/${itemID}`, itemData);
|
const response = await axios.put(`${api.baseApiUrl}/${boxID}/item/${itemID}`, itemData);
|
||||||
const boxData = [...data];
|
const boxData = [...data];
|
||||||
boxData.splice(boxData.findIndex(box => box._id === boxID), 1, response.data);
|
boxData.splice(boxData.findIndex(box => box._id === boxID), 1, response.data);
|
||||||
@@ -195,18 +198,19 @@ function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleAddItem = (id) => {
|
const handleAddItem = (id) => {
|
||||||
|
clearFormItem();
|
||||||
setBoxID(id);
|
setBoxID(id);
|
||||||
setEditItemBool(false);
|
setEditItemBool(false);
|
||||||
setShowModalItem(true);
|
setShowModalItem(true);
|
||||||
}
|
}
|
||||||
const handleEditItem = (boxID, itemID) => {
|
const handleEditItem = (boxID, itemID) => {
|
||||||
|
clearFormItem();
|
||||||
const box = data.find(box => box._id === boxID);
|
const box = data.find(box => box._id === boxID);
|
||||||
const item = box.item.find(item => item._id === itemID);
|
const item = box.item.find(item => item._id === itemID);
|
||||||
|
|
||||||
setBoxID(boxID);
|
setBoxID(boxID);
|
||||||
setItemID(itemID);
|
setItemID(itemID);
|
||||||
setItemName(item.name);
|
setItemName(item.name || '');
|
||||||
setItemDescription(item.description);
|
setItemDescription(item.description || '');
|
||||||
|
|
||||||
setEditItemBool(true);
|
setEditItemBool(true);
|
||||||
setShowModalItem(true);
|
setShowModalItem(true);
|
||||||
@@ -222,11 +226,9 @@ function App() {
|
|||||||
name: itemName,
|
name: itemName,
|
||||||
description: itemDescription
|
description: itemDescription
|
||||||
}
|
}
|
||||||
if (editItemBool) {
|
if (editItemBool)
|
||||||
console.log('edititem');
|
|
||||||
editItem(boxID, itemID, itemData);
|
editItem(boxID, itemID, itemData);
|
||||||
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
createItem(boxID, itemData);
|
createItem(boxID, itemData);
|
||||||
|
|
||||||
@@ -275,7 +277,7 @@ function App() {
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<input id="id" name="id" value={itemID} readOnly hidden></input>
|
<input id="id" name="id" value={itemID} readOnly hidden></input>
|
||||||
<label htmlFor="item-name">name
|
<label htmlFor="item-name">name
|
||||||
<input onChange={handleName} value={itemName} id="item-name" name="name" type="text"></input>
|
<input autoFocus onChange={handleName} value={itemName} id="item-name" name="name" type="text"></input>
|
||||||
</label>
|
</label>
|
||||||
<label htmlFor="item-description">description
|
<label htmlFor="item-description">description
|
||||||
<input onChange={handleDescription} value={itemDescription} id="item-description" name="description" type="text"></input>
|
<input onChange={handleDescription} value={itemDescription} id="item-description" name="description" type="text"></input>
|
||||||
|
|||||||
+1
-1
@@ -86,7 +86,7 @@ app.put('/box/:boxId/item/:itemId', async (request, response) => {
|
|||||||
await Box.updateOne({ '_id': boxID, 'item._id': itemID }, {
|
await Box.updateOne({ '_id': boxID, 'item._id': itemID }, {
|
||||||
$set: {
|
$set: {
|
||||||
'item.$.name': request.body.name,
|
'item.$.name': request.body.name,
|
||||||
'item.$.description': request.description
|
'item.$.description': request.body.description
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const updatedBox = await getBox(boxID);
|
const updatedBox = await getBox(boxID);
|
||||||
|
|||||||
Reference in New Issue
Block a user