From 35c91bca2b8355f4d7980fe69f40f2e0ff5c7fb8 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Tue, 6 Oct 2020 15:38:21 -0500 Subject: [PATCH] Added cart item and handle empty cart state --- components/cart/CartItem/CartItem.tsx | 28 +++++++++ components/cart/CartItem/index.ts | 1 + .../cart/CartSidebarView/CartSidebarView.tsx | 60 +++++++++---------- components/ui/Sidebar/Sidebar.tsx | 2 +- lib/bigcommerce/api/cart.ts | 2 +- 5 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 components/cart/CartItem/CartItem.tsx create mode 100644 components/cart/CartItem/index.ts diff --git a/components/cart/CartItem/CartItem.tsx b/components/cart/CartItem/CartItem.tsx new file mode 100644 index 000000000..d668c31bf --- /dev/null +++ b/components/cart/CartItem/CartItem.tsx @@ -0,0 +1,28 @@ +import { Trash } from '@components/icon' + +const CartItem = () => { + return ( +
  • +
    +
    + T-Shirt +
    + - + + + +
    +
    +
    + $50.00 + + + +
    +
  • + ) +} + +export default CartItem diff --git a/components/cart/CartItem/index.ts b/components/cart/CartItem/index.ts new file mode 100644 index 000000000..b5f6dc52f --- /dev/null +++ b/components/cart/CartItem/index.ts @@ -0,0 +1 @@ +export { default } from './CartItem' diff --git a/components/cart/CartSidebarView/CartSidebarView.tsx b/components/cart/CartSidebarView/CartSidebarView.tsx index f18144fa9..c918cf67a 100644 --- a/components/cart/CartSidebarView/CartSidebarView.tsx +++ b/components/cart/CartSidebarView/CartSidebarView.tsx @@ -4,10 +4,12 @@ import { Button } from '@components/ui' import { Trash, Cross } from '@components/icon' import { useUI } from '@components/ui/context' import { useCart } from '@lib/bigcommerce/cart' +import CartItem from '../CartItem' const CartSidebarView: FC = () => { const { data, isEmpty } = useCart() const { closeSidebar } = useUI() + const items = data?.line_items.physical_items ?? [] console.log('CART', data, isEmpty) @@ -28,39 +30,35 @@ const CartSidebarView: FC = () => { -

    - My Cart -

    + {isEmpty ? ( +

    + Your cart is currently empty +

    + ) : ( +

    + My Cart +

    + )} -
    -
      -
    • -
      -
      - T-Shirt -
      - - - - + -
      -
      -
      - $50.00 - - - -
      -
    • -
    -
    - -
    - -
    + {isEmpty ? ( +
    + +
    + ) : ( + <> +
    +
      + {items.map((item) => ( + + ))} +
    +
    +
    + +
    + + )} ) } diff --git a/components/ui/Sidebar/Sidebar.tsx b/components/ui/Sidebar/Sidebar.tsx index ddeaac56e..35b1e3700 100644 --- a/components/ui/Sidebar/Sidebar.tsx +++ b/components/ui/Sidebar/Sidebar.tsx @@ -15,7 +15,7 @@ const Sidebar: FC = ({ className, children }) => {
    -
    +
    {children}
    diff --git a/lib/bigcommerce/api/cart.ts b/lib/bigcommerce/api/cart.ts index d6666369c..739f90f22 100644 --- a/lib/bigcommerce/api/cart.ts +++ b/lib/bigcommerce/api/cart.ts @@ -35,7 +35,7 @@ export type Cart = { custom_items: any[] digital_items: any[] gift_certificates: any[] - psysical_items: any[] + physical_items: any[] } // TODO: add missing fields }