Skip to content

Commit

Permalink
refactor: use streamable in cart
Browse files Browse the repository at this point in the history
  • Loading branch information
apledger committed Jan 17, 2025
1 parent 65b4c57 commit d8665f0
Show file tree
Hide file tree
Showing 5 changed files with 459 additions and 490 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { parseWithZod } from '@conform-to/zod';
import { FragmentOf } from 'gql.tada';
import { getTranslations } from 'next-intl/server';

import { CartLineItem } from '@/vibes/soul/sections/cart';
import { cartLineItemActionFormDataSchema } from '@/vibes/soul/sections/cart/schema';
import { CartLineItem } from '@/vibes/soul/sections/cart/types';

import { DigitalItemFragment, PhysicalItemFragment } from '../page-data';

Expand Down
49 changes: 27 additions & 22 deletions core/app/[locale]/(default)/cart/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cookies } from 'next/headers';
import { getFormatter, getTranslations } from 'next-intl/server';

import { Cart as CartComponent, CartEmptyState } from '@/vibes/soul/sections/cart';
import { exists } from '~/lib/utils';

import { redirectToCheckout } from './_actions/redirect-to-checkout';
import { updateLineItem } from './_actions/update-line-item';
Expand Down Expand Up @@ -88,7 +89,32 @@ export default async function Cart() {
return (
<>
<CartComponent
cart={{
lineItems: formattedLineItems,
total: format.number(checkout?.grandTotal?.value || 0, {
style: 'currency',
currency: cart.currencyCode,
}),
totalLabel: t('CheckoutSummary.grandTotal'),
summaryItems: [
{
label: t('CheckoutSummary.subTotal'),
value: format.number(checkout?.subtotal?.value ?? 0, {
style: 'currency',
currency: cart.currencyCode,
}),
},
checkout?.taxTotal && {
label: 'Tax',
value: format.number(checkout.taxTotal.value, {
style: 'currency',
currency: cart.currencyCode,
}),
},
].filter(exists),
}}
checkoutAction={redirectToCheckout}
checkoutLabel={t('proceedToCheckout')}
decrementLineItemLabel={t('decrement')}
deleteLineItemLabel={t('removeItem')}
emptyState={{
Expand All @@ -98,28 +124,7 @@ export default async function Cart() {
}}
incrementLineItemLabel={t('increment')}
lineItemAction={updateLineItem}
lineItems={formattedLineItems}
summary={{
title: t('CheckoutSummary.title'),
taxLabel: t('CheckoutSummary.tax'),
tax: checkout?.taxTotal
? format.number(checkout.taxTotal.value, {
style: 'currency',
currency: cart.currencyCode,
})
: '',
subtotalLabel: t('CheckoutSummary.subTotal'),
subtotal: format.number(checkout?.subtotal?.value ?? 0, {
style: 'currency',
currency: cart.currencyCode,
}),
grandTotalLabel: t('CheckoutSummary.grandTotal'),
grandTotal: format.number(checkout?.grandTotal?.value || 0, {
style: 'currency',
currency: cart.currencyCode,
}),
ctaLabel: t('proceedToCheckout'),
}}
summaryTitle={t('CheckoutSummary.title')}
title={t('title')}
/>
<CartViewed
Expand Down
Loading

0 comments on commit d8665f0

Please sign in to comment.