Couple of fixes and stuff
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import Button from '../components/Button'
|
||||
import { Button } from 'react-bootstrap';
|
||||
import SimpleItemList from "../components/SimpleItemList";
|
||||
import Ajouter from "../components/Ajouter";
|
||||
|
||||
@@ -55,6 +54,7 @@ const Inventaire = () => {
|
||||
console.log("Erreur leur du DELETE de " + id);
|
||||
};
|
||||
|
||||
|
||||
const handleModifyItem = async (morceau) => {
|
||||
const response = await fetch(`https://localhost:7292/api/Product`, {
|
||||
method: 'PATCH',
|
||||
@@ -65,13 +65,10 @@ const Inventaire = () => {
|
||||
body: JSON.stringify(morceau)
|
||||
})
|
||||
|
||||
const newMorceau = await response.json();
|
||||
console.log(newMorceau);
|
||||
const modifiedMorceau = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
setMorceaux(morceaux.filter((morceau) => morceau.id !== newMorceau.id));
|
||||
setMorceaux([...morceaux, { ...newMorceau }]);
|
||||
}
|
||||
if (response.ok)
|
||||
setMorceaux([...(morceaux.filter((morceau) => morceau.id !== modifiedMorceau.id)), { ...modifiedMorceau }].sort((a, b) => a.id - b.id));
|
||||
else
|
||||
console.log("Erreur de creation " + morceau);
|
||||
};
|
||||
@@ -81,10 +78,11 @@ const Inventaire = () => {
|
||||
<header className='header'>
|
||||
<h1>Inventaire</h1>
|
||||
<Button
|
||||
text={isFormvisible ? 'Fermer' : 'Ajouter'}
|
||||
color={isFormvisible ? 'red' : 'purple'}
|
||||
onClick={() => setFormVisibility(!isFormvisible)}
|
||||
/>
|
||||
className={isFormvisible ? 'btn-fermer' : 'btn-ajouter'}
|
||||
onClick={() => setFormVisibility(!isFormvisible)}>
|
||||
{isFormvisible ? 'Fermer' : 'Ajouter'}
|
||||
</Button>
|
||||
|
||||
</header>
|
||||
{isFormvisible && <Ajouter onCreation={handleAddItem}></Ajouter>}
|
||||
{morceaux.length > 0 ?
|
||||
|
||||
Reference in New Issue
Block a user