4
0
forked from crowetic/commerce
Michael Novotny 9678306b23
Fixes cart closing and reopening with first interaction (#1053)
* Works

* Adds animation back
2023-06-21 13:13:10 -07:00

24 lines
639 B
TypeScript

import { createCart, getCart } from 'lib/shopify';
import { cookies } from 'next/headers';
import CartModal from './modal';
export default async function Cart() {
const cartId = cookies().get('cartId')?.value;
let cartIdUpdated = false;
let cart;
if (cartId) {
cart = await getCart(cartId);
}
// If the `cartId` from the cookie is not set or the cart is empty
// (old carts becomes `null` when you checkout), then get a new `cartId`
// and re-fetch the cart.
if (!cartId || !cart) {
cart = await createCart();
cartIdUpdated = true;
}
return <CartModal cart={cart} cartIdUpdated={cartIdUpdated} />;
}