diff --git a/src/components/HotelContext.jsx b/src/components/HotelContext.jsx index 4ab9622..c559ba2 100644 --- a/src/components/HotelContext.jsx +++ b/src/components/HotelContext.jsx @@ -190,7 +190,15 @@ export function HotelProvider({ accessToken, children, resClientId}) { } + async function updateItemAmount(item_id, item_amount) { + const res = await fetch ( `${API_BASE}/inventory/update_item/${item_id}/${item_amount}`, + { + method: "PUT", + headers: { Authorization: `Bearer ${accessTokenSingle}` } + }); + + } async function fetchHotelUsers() { const res = await fetch(`${API_BASE}/chat/hotel_users`, { @@ -252,7 +260,8 @@ export function HotelProvider({ accessToken, children, resClientId}) { fetchHotelUsers, addUserToConv, createConversation, - fetchHotelInventory + fetchHotelInventory, + updateItemAmount }} > {children} diff --git a/src/components/widget/inventoryWidget.jsx b/src/components/widget/inventoryWidget.jsx index 9164a95..3d40ac3 100644 --- a/src/components/widget/inventoryWidget.jsx +++ b/src/components/widget/inventoryWidget.jsx @@ -23,10 +23,54 @@ export default function InventoryWidget({}) { return ( - +
+ {items.map(item => ( + + + ))} +
) +} + + +function ItemCard({id, name, amount}) { + const [itemAmount, setItemAmount] = useState(amount); + const [editing, setEditing] = useState(false); + + const {updateItemAmount} = useHotel(); + + function submit(item_id, item_amount) { + updateItemAmount(item_id, item_amount); + console.log("submited from item card :" + item_id + item_amount ); + setEditing(false); + } + + return ( +
+
{name}
+ + {!editing ?( +

setEditing(true)} /*style={ cursor: "pointer" }*/>Amount :{amount}

+ ):( +
+ setItemAmount(e.target.value)} + onKeyDown={e => e.key == "Enter" && submit(id, itemAmount)} + /> +
+ )} + +
+ ) + } \ No newline at end of file