import type {CartApiQueryFragment} from 'storefrontapi.generated'; import type {CartLayout} from '~/components/CartMain'; import {CartForm, Money, type OptimisticCart} from '@shopify/hydrogen'; import {useEffect, useRef} from 'react'; import {useFetcher} from 'react-router'; type CartSummaryProps = { cart: OptimisticCart; layout: CartLayout; }; export function CartSummary({cart, layout}: CartSummaryProps) { const className = layout === 'page' ? 'cart-summary-page' : 'cart-summary-aside'; return (

Totals

Subtotal
{cart?.cost?.subtotalAmount?.amount ? ( ) : ( '-' )}
); } function CartCheckoutActions({checkoutUrl}: {checkoutUrl?: string}) { if (!checkoutUrl) return null; return (

Continue to Checkout →


); } function CartDiscounts({ discountCodes, }: { discountCodes?: CartApiQueryFragment['discountCodes']; }) { const codes: string[] = discountCodes ?.filter((discount) => discount.applicable) ?.map(({code}) => code) || []; return (
{/* Have existing discount, display it with a remove option */} {/* Show an input to apply a discount */}
 
); } function UpdateDiscountForm({ discountCodes, children, }: { discountCodes?: string[]; children: React.ReactNode; }) { return ( {children} ); } function CartGiftCard({ giftCardCodes, }: { giftCardCodes: CartApiQueryFragment['appliedGiftCards'] | undefined; }) { const giftCardCodeInput = useRef(null); const giftCardAddFetcher = useFetcher({key: 'gift-card-add'}); useEffect(() => { if (giftCardAddFetcher.data) { giftCardCodeInput.current!.value = ''; } }, [giftCardAddFetcher.data]); return (
{giftCardCodes && giftCardCodes.length > 0 && (
Applied Gift Card(s)
{giftCardCodes.map((giftCard) => (
***{giftCard.lastCharacters}    
))}
)}
 
); } function AddGiftCardForm({ fetcherKey, children, }: { fetcherKey?: string; children: React.ReactNode; }) { return ( {children} ); } function RemoveGiftCardForm({ giftCardId, children, }: { giftCardId: string; children: React.ReactNode; }) { return ( {children} ); }