diff --git a/package-lock.json b/package-lock.json index d01ddfa..bbd664e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "react-ecommerce", "version": "0.0.1", "dependencies": { "@headlessui/react": "^1.6.0", diff --git a/src/Components/Cart.jsx b/src/Components/Cart.jsx index 917b7a1..b7f4fbd 100644 --- a/src/Components/Cart.jsx +++ b/src/Components/Cart.jsx @@ -1,15 +1,16 @@ -import { Dialog, Transition } from "@headlessui/react"; -import { XIcon } from "@heroicons/react/outline"; -import React, { Fragment } from "react"; +import { Dialog, Transition } from "@headlessui/react" +import { XIcon } from "@heroicons/react/outline" +import React, { Fragment } from "react" export default function Cart({ open, setOpen, cart, updateCart }) { + let subtotal = cart.reduce((acc, product) => (acc + product.price*product.quantity), 0) return ( { - setOpen; + setOpen }} >
@@ -21,6 +22,7 @@ export default function Cart({ open, setOpen, cart, updateCart }) { leave="ease-in-out duration-500" leaveFrom="opacity-100" leaveTo="opacity-0" + onClick={() => setOpen(false)} > @@ -53,59 +55,67 @@ export default function Cart({ open, setOpen, cart, updateCart }) {
-
-
    - {cart.map((product) => ( -
  • -
    - {product.imageAlt} -
    + {cart.length > 0 ? ( -
    -
    -
    -

    {product.name}

    -

    ${product.price}

    -
    +
    +
      + {cart.map((product) => ( +
    • +
      + {product.imageAlt}
      -
      -

      Qty {product.quantity}

      -
      - + return p.quantity > 0 + }) + updateCart(newCart) + }} + type="button" + className="font-medium text-gray-500 hover:text-black" + > + Remove + +
    -
    -
  • - ))} -
-
+ + ))} + +
+ ) : ( +
+ Empty cart +
+ ) + }

Subtotal

-

$262.00

+

${subtotal}

Shipping and taxes calculated at checkout.

@@ -136,5 +146,5 @@ export default function Cart({ open, setOpen, cart, updateCart }) {
- ); + ) } diff --git a/src/Components/NavBar.jsx b/src/Components/NavBar.jsx index b1d0db9..37aebc0 100644 --- a/src/Components/NavBar.jsx +++ b/src/Components/NavBar.jsx @@ -1,7 +1,7 @@ import { ShoppingBagIcon } from "@heroicons/react/outline"; import React from "react"; -export default function NavBar({ setOpen }) { +export default function NavBar({ setOpen, items }) { return (
@@ -41,7 +41,7 @@ export default function NavBar({ setOpen }) { className="flex-shrink-0 h-6 w-6 text-gray-400 group-hover:text-gray-500" aria-hidden="true" /> - 0 + {items} items in cart, view bag
diff --git a/src/Components/ProductFilters.jsx b/src/Components/ProductFilters.jsx index 0f3262a..bde3dfb 100644 --- a/src/Components/ProductFilters.jsx +++ b/src/Components/ProductFilters.jsx @@ -7,6 +7,9 @@ function classNames(...classes) { } export default function ProductFilters({ filterOptions, setFilterOptions, sortOptions, setSortOptions }) { + const activePriceFilterOption = filterOptions.price.find((option) => option.checked) + const activeColorFilterOptions = filterOptions.color.find((option) => option.checked) + return (