Skip to content

Commit 1cead1d

Browse files
authored
Streamable cart (#1913)
* fix: toaster position * refactor: use streamable in cart * chore: changeset
1 parent 0098c6b commit 1cead1d

File tree

7 files changed

+465
-491
lines changed

7 files changed

+465
-491
lines changed

.changeset/smooth-flowers-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-core": patch
3+
---
4+
5+
Applied streamable pattern to Cart.

core/app/[locale]/(default)/cart/_actions/update-line-item.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { parseWithZod } from '@conform-to/zod';
66
import { FragmentOf } from 'gql.tada';
77
import { getTranslations } from 'next-intl/server';
88

9+
import { CartLineItem } from '@/vibes/soul/sections/cart';
910
import { cartLineItemActionFormDataSchema } from '@/vibes/soul/sections/cart/schema';
10-
import { CartLineItem } from '@/vibes/soul/sections/cart/types';
1111

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

core/app/[locale]/(default)/cart/page.tsx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getFormatter, getTranslations } from 'next-intl/server';
33

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

78
import { redirectToCheckout } from './_actions/redirect-to-checkout';
89
import { updateLineItem } from './_actions/update-line-item';
@@ -89,7 +90,32 @@ export default async function Cart() {
8990
return (
9091
<>
9192
<CartComponent
93+
cart={{
94+
lineItems: formattedLineItems,
95+
total: format.number(checkout?.grandTotal?.value || 0, {
96+
style: 'currency',
97+
currency: cart.currencyCode,
98+
}),
99+
totalLabel: t('CheckoutSummary.grandTotal'),
100+
summaryItems: [
101+
{
102+
label: t('CheckoutSummary.subTotal'),
103+
value: format.number(checkout?.subtotal?.value ?? 0, {
104+
style: 'currency',
105+
currency: cart.currencyCode,
106+
}),
107+
},
108+
checkout?.taxTotal && {
109+
label: 'Tax',
110+
value: format.number(checkout.taxTotal.value, {
111+
style: 'currency',
112+
currency: cart.currencyCode,
113+
}),
114+
},
115+
].filter(exists),
116+
}}
92117
checkoutAction={redirectToCheckout}
118+
checkoutLabel={t('proceedToCheckout')}
93119
decrementLineItemLabel={t('decrement')}
94120
deleteLineItemLabel={t('removeItem')}
95121
emptyState={{
@@ -100,28 +126,7 @@ export default async function Cart() {
100126
incrementLineItemLabel={t('increment')}
101127
key={`${cart.entityId}-${cart.version}`}
102128
lineItemAction={updateLineItem}
103-
lineItems={formattedLineItems}
104-
summary={{
105-
title: t('CheckoutSummary.title'),
106-
taxLabel: t('CheckoutSummary.tax'),
107-
tax: checkout?.taxTotal
108-
? format.number(checkout.taxTotal.value, {
109-
style: 'currency',
110-
currency: cart.currencyCode,
111-
})
112-
: '',
113-
subtotalLabel: t('CheckoutSummary.subTotal'),
114-
subtotal: format.number(checkout?.subtotal?.value ?? 0, {
115-
style: 'currency',
116-
currency: cart.currencyCode,
117-
}),
118-
grandTotalLabel: t('CheckoutSummary.grandTotal'),
119-
grandTotal: format.number(checkout?.grandTotal?.value || 0, {
120-
style: 'currency',
121-
currency: cart.currencyCode,
122-
}),
123-
ctaLabel: t('proceedToCheckout'),
124-
}}
129+
summaryTitle={t('CheckoutSummary.title')}
125130
title={t('title')}
126131
/>
127132
<CartViewed

core/vibes/soul/primitives/toaster/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const Toaster = ({ ...props }: ToasterProps) => {
2323
toastOptions={{
2424
unstyled: true,
2525
classNames: {
26-
toast: 'group focus-visible:ring-0',
26+
toast: 'group focus-visible:ring-0 right-0',
2727
},
2828
}}
2929
{...props}

0 commit comments

Comments
 (0)