Skip to content

Commit

Permalink
fix: fetch locale using async function
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemoya committed Apr 23, 2024
1 parent 9020c09 commit 7c50e09
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextIntlClientProvider } from 'next-intl';
import { getFormatter, getMessages } from 'next-intl/server';
import { getFormatter, getLocale, getMessages } from 'next-intl/server';

import { getCart } from '~/client/queries/get-cart';
import { ExistingResultType } from '~/client/util';
Expand All @@ -15,12 +15,11 @@ export type Product =
export const CartItem = async ({
currencyCode,
product,
locale,
}: {
currencyCode: string;
product: Product;
locale: string;
}) => {
const locale = await getLocale();
const messages = await getMessages({ locale });
const format = await getFormatter({ locale });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AlertCircle } from 'lucide-react';
import { NextIntlClientProvider } from 'next-intl';
import { getFormatter, getMessages, getTranslations } from 'next-intl/server';
import { getFormatter, getLocale, getMessages, getTranslations } from 'next-intl/server';
import { toast } from 'react-hot-toast';

import { getCheckout } from '~/client/queries/get-checkout';
Expand All @@ -10,7 +10,8 @@ import { getShippingCountries } from '../_actions/get-shipping-countries';
import { CouponCode } from './coupon-code';
import { ShippingEstimator } from './shipping-estimator';

export const CheckoutSummary = async ({ cartId, locale }: { cartId: string; locale: string }) => {
export const CheckoutSummary = async ({ cartId }: { cartId: string }) => {
const locale = await getLocale();
const t = await getTranslations({ locale, namespace: 'Cart.CheckoutSummary' });
const format = await getFormatter({ locale });
const messages = await getMessages({ locale });
Expand Down
16 changes: 3 additions & 13 deletions apps/core/app/[locale]/(default)/cart/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,16 @@ export default async function CartPage({ params: { locale } }: Props) {
<div className="pb-12 md:grid md:grid-cols-2 md:gap-8 lg:grid-cols-3">
<ul className="col-span-2">
{cart.lineItems.physicalItems.map((product) => (
<CartItem
currencyCode={cart.currencyCode}
key={product.entityId}
locale={locale}
product={product}
/>
<CartItem currencyCode={cart.currencyCode} key={product.entityId} product={product} />
))}

{cart.lineItems.digitalItems.map((product) => (
<CartItem
currencyCode={cart.currencyCode}
key={product.entityId}
locale={locale}
product={product}
/>
<CartItem currencyCode={cart.currencyCode} key={product.entityId} product={product} />
))}
</ul>

<div className="col-span-1 col-start-2 lg:col-start-3">
<CheckoutSummary cartId={cartId} locale={locale} />
<CheckoutSummary cartId={cartId} />

<Suspense fallback={t('loading')}>
<CheckoutButton cartId={cartId} label={t('proceedToCheckout')} />
Expand Down

0 comments on commit 7c50e09

Please sign in to comment.