diff --git a/lib/hooks/use-cart.ts b/lib/hooks/use-cart.ts deleted file mode 100644 index a0632d9bf..000000000 --- a/lib/hooks/use-cart.ts +++ /dev/null @@ -1,30 +0,0 @@ -import useBigCommerceCart from '@bigcommerce/storefront-data-hooks/cart/use-cart' -import useBigCommercePrice from '@bigcommerce/storefront-data-hooks/use-price' - -export const useCart = () => { - const { data, error, isEmpty } = useBigCommerceCart() - const items = data?.line_items.physical_items ?? [] - - const { price: subtotal } = useBigCommercePrice( - data && { - amount: data.base_amount, - currencyCode: data.currency.code, - } - ) - const { price: total } = useBigCommercePrice( - data && { - amount: data.cart_amount, - currencyCode: data.currency.code, - } - ) - - return { - items: data?.line_items.physical_items ?? [], - isLoading: data === undefined, - isError: error, - isEmpty: isEmpty && data === null, - subtotal, - total, - currency: data?.currency, - } -} diff --git a/pages/cart.tsx b/pages/cart.tsx index 427d8e844..e85543b33 100644 --- a/pages/cart.tsx +++ b/pages/cart.tsx @@ -1,10 +1,10 @@ import type { GetStaticPropsContext } from 'next' import { getConfig } from '@bigcommerce/storefront-data-hooks/api' import getAllPages from '@bigcommerce/storefront-data-hooks/api/operations/get-all-pages' -import { useCart } from '@lib/hooks/use-cart' +import useCart from '@bigcommerce/storefront-data-hooks/cart/use-cart' +import usePrice from '@bigcommerce/storefront-data-hooks/use-price' import { Layout } from '@components/core' import { Button } from '@components/ui' -import { Bag, Cross, Check } from '@components/icons' import { CartItem } from '@components/cart' import { Text } from '@components/ui' import CartSkeleton from '@components/cart/CartSkeleton' @@ -22,26 +22,31 @@ export async function getStaticProps({ } export default function Cart() { - const { - items, - isLoading, - isError, - isEmpty, - subtotal, - total, - currency, - } = useCart() + const { data, error } = useCart() + const isLoading = data === undefined + const items = data?.line_items.physical_items ?? [] + + const { price: subtotal } = usePrice( + data && { + amount: data.base_amount, + currencyCode: data.currency.code, + } + ) + const { price: total } = usePrice( + data && { + amount: data.cart_amount, + currencyCode: data.currency.code, + } + ) return (
My Cart - {isLoading ? ( - - ) : isError ? ( + {error ? (
Failed to load
- ) : isEmpty ? ( - - ) : ( + ) : isLoading ? ( + + ) : items.length > 0 ? (
@@ -51,7 +56,7 @@ export default function Cart() { ))} @@ -103,6 +108,8 @@ export default function Cart() {
+ ) : ( + )}
)