Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamable cart #1913

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-flowers-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Applied streamable pattern to Cart.
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 @@ -3,6 +3,7 @@ import { getFormatter, getTranslations } from 'next-intl/server';

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

import { redirectToCheckout } from './_actions/redirect-to-checkout';
import { updateLineItem } from './_actions/update-line-item';
Expand Down Expand Up @@ -89,7 +90,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 @@ -100,28 +126,7 @@ export default async function Cart() {
incrementLineItemLabel={t('increment')}
key={`${cart.entityId}-${cart.version}`}
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
2 changes: 1 addition & 1 deletion core/vibes/soul/primitives/toaster/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Toaster = ({ ...props }: ToasterProps) => {
toastOptions={{
unstyled: true,
classNames: {
toast: 'group focus-visible:ring-0',
toast: 'group focus-visible:ring-0 right-0',
},
}}
{...props}
Expand Down
Loading