diff --git a/client/src/app.js b/client/src/app.js index c23afc9..05e8b6f 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -14,11 +14,12 @@ function App() { fetchData(); }, []); - const [data, setData] = useState([]); + const [data, setData] = useState(); + const [boxName, setBoxName] = useState(''); const [boxDescription, setBoxDescription] = useState(''); - + const [showFormBox, setShowFormBox] = useState(false); const fetchDataAsync = async () => { try { @@ -40,10 +41,10 @@ function App() { } } - const deleteBox = async (id) => { + const removeBox = async (id) => { try { const response = await axios.delete(`${api.baseApiUrl}/${id}`); - setData(response.data); + setData(data.filter(box => box._id !== id)); } catch (error) { console.log(error); @@ -60,6 +61,8 @@ function App() { const handleSubmitBox = (event) => { event.preventDefault(); + setShowFormBox(false); + clearForm(); const boxData = { name: boxName, description: boxDescription @@ -69,29 +72,21 @@ function App() { } const handleRemoveBox = (id) => { - deleteBox(id); + removeBox(id); } - - - - + const handleAddBox = () => { + setShowFormBox(true); + } + const clearForm = () => { + setBoxName(); + setBoxDescription(); + } const boxHandler = { handleSubmit: handleSubmitBox, handleRemove: handleRemoveBox, handleName: handleBoxName, handleDescription: handleBoxDescription }; - - const lstBoxes = data.map((box) => { - return ( -