diff --git a/src/components/Item.js b/src/components/Item.js
index 2f40e63f..16849bda 100644
--- a/src/components/Item.js
+++ b/src/components/Item.js
@@ -1,16 +1,44 @@
import React from "react";
-function Item({ item }) {
+function Item({ item, onUpdateItem, onDeleteItem }) {
+
+ function handleAddToCartClick() {
+
+ fetch(`http://localhost:4000/items/${item.id}`, {
+ method: "PATCH",
+ headers: {
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify({
+ isInCart:!item.isInCart
+ })
+ })
+ .then((response) => response.json())
+ .then((updatedItem) => onUpdateItem(updatedItem))
+
+ }
+
+ function handleDeleteClick(){
+ fetch(`http://localhost:4000/items/${item.id}`, {
+ method: "DELETE"
+ })
+ .then((response) => response.json())
+ .then(() => onDeleteItem(item))
+ }
return (
{item.name}
{item.category}
-
);
}
-export default Item;
+export default Item;
\ No newline at end of file
diff --git a/src/components/ItemForm.js b/src/components/ItemForm.js
index 5b91f0b5..35843058 100644
--- a/src/components/ItemForm.js
+++ b/src/components/ItemForm.js
@@ -1,11 +1,30 @@
import React, { useState } from "react";
-function ItemForm() {
+function ItemForm({ onAddItem }) {
const [name, setName] = useState("");
- const [category, setCategory] = useState("Produce");
+ const [category, setCategory] = useState("");
+
+ function handleSubmit(e) {
+ e.preventDefault();
+ const itemData = {
+ name: name,
+ category: category,
+ isInCart: false,
+ };
+
+ fetch("http://localhost:4000/items", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(itemData),
+ })
+ .then((response) => response.json())
+ .then((newItem) => onAddItem(newItem));
+ }
return (
-