From efb999d811512f94383afa9461315a250d81bf74 Mon Sep 17 00:00:00 2001 From: Alexander Saiannyi Date: Thu, 4 Apr 2024 17:04:23 +0200 Subject: [PATCH] update AccountTabs component to improve content's rendering --- .../account/[tab]/_components/account-tabs.tsx | 10 ++++++---- .../app/[locale]/(default)/account/[tab]/layout.tsx | 11 +++++++---- .../app/[locale]/(default)/account/[tab]/page.tsx | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/core/app/[locale]/(default)/account/[tab]/_components/account-tabs.tsx b/apps/core/app/[locale]/(default)/account/[tab]/_components/account-tabs.tsx index 136297de6..dcfedc16a 100644 --- a/apps/core/app/[locale]/(default)/account/[tab]/_components/account-tabs.tsx +++ b/apps/core/app/[locale]/(default)/account/[tab]/_components/account-tabs.tsx @@ -1,10 +1,11 @@ 'use client'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@bigcommerce/components/tabs'; -import { useRouter } from 'next/navigation'; import { useTranslations } from 'next-intl'; import { PropsWithChildren } from 'react'; +import { Link } from '~/components/link'; + import { TabType } from '../layout'; interface Props extends PropsWithChildren { @@ -13,15 +14,16 @@ interface Props extends PropsWithChildren { } export const AccountTabs = ({ children, activeTab, tabs }: Props) => { - const router = useRouter(); const t = useTranslations('Account.Home'); return ( {tabs.map((tab) => ( - router.replace(`/account/${tab}`)} value={tab}> - {tab === 'recently-viewed' ? t('recentlyViewed') : t(tab)} + + + {tab === 'recently-viewed' ? t('recentlyViewed') : t(tab)} + ))} diff --git a/apps/core/app/[locale]/(default)/account/[tab]/layout.tsx b/apps/core/app/[locale]/(default)/account/[tab]/layout.tsx index 32e1e6d29..a09fa233b 100644 --- a/apps/core/app/[locale]/(default)/account/[tab]/layout.tsx +++ b/apps/core/app/[locale]/(default)/account/[tab]/layout.tsx @@ -1,5 +1,5 @@ -import { NextIntlClientProvider, useMessages } from 'next-intl'; -import { unstable_setRequestLocale } from 'next-intl/server'; +import { NextIntlClientProvider } from 'next-intl'; +import { getMessages, getTranslations, unstable_setRequestLocale } from 'next-intl/server'; import { PropsWithChildren } from 'react'; import { LocaleType } from '~/i18n'; @@ -21,13 +21,16 @@ interface Props extends PropsWithChildren { params: { locale: LocaleType; tab?: TabType }; } -export default function AccountTabLayout({ children, params: { locale, tab } }: Props) { +export default async function AccountTabLayout({ children, params: { locale, tab } }: Props) { unstable_setRequestLocale(locale); - const messages = useMessages(); + const t = await getTranslations({ locale, namespace: 'Account.Home' }); + + const messages = await getMessages(); return ( +

{t('heading')}

{children} diff --git a/apps/core/app/[locale]/(default)/account/[tab]/page.tsx b/apps/core/app/[locale]/(default)/account/[tab]/page.tsx index cc3ff4443..30e522d05 100644 --- a/apps/core/app/[locale]/(default)/account/[tab]/page.tsx +++ b/apps/core/app/[locale]/(default)/account/[tab]/page.tsx @@ -24,7 +24,7 @@ export async function generateMetadata({ params: { tab, locale } }: Props): Prom const tabHeading = async (heading: string, locale: LocaleType) => { const t = await getTranslations({ locale, namespace: 'Account.Home' }); - return

{t(heading)}

; + return

{t(heading)}

; }; export default async function AccountTabPage({ params: { tab, locale } }: Props) {