Skip to content

Commit 889a7e3

Browse files
committed
chore: define dashboard metadata in layout
1 parent e76f7b9 commit 889a7e3

6 files changed

Lines changed: 30 additions & 52 deletions

File tree

src/app/[locale]/(auth)/dashboard/layout.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import { SignOutButton } from '@clerk/nextjs';
2+
import type { Metadata } from 'next';
23
import { getTranslations, setRequestLocale } from 'next-intl/server';
34
import { LocaleSwitcher } from '@/components/LocaleSwitcher';
45
import { Link } from '@/libs/I18nNavigation';
56
import { BaseTemplate } from '@/templates/BaseTemplate';
67

7-
export default async function DashboardLayout(props: {
8+
type DashboardLayoutProps = {
89
children: React.ReactNode;
910
params: Promise<{ locale: string }>;
10-
}) {
11+
};
12+
13+
export async function generateMetadata(props: DashboardLayoutProps): Promise<Metadata> {
14+
const { locale } = await props.params;
15+
const t = await getTranslations({
16+
locale,
17+
namespace: 'DashboardLayout',
18+
});
19+
20+
return {
21+
title: t('meta_title'),
22+
description: t('meta_description'),
23+
};
24+
}
25+
26+
export default async function DashboardLayout(props: DashboardLayoutProps) {
1127
const { locale } = await props.params;
1228
setRequestLocale(locale);
1329
const t = await getTranslations({

src/app/[locale]/(auth)/dashboard/page.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
import type { Metadata } from 'next';
2-
import { getTranslations, setRequestLocale } from 'next-intl/server';
1+
import { setRequestLocale } from 'next-intl/server';
32
import { Hello } from '@/components/Hello';
43

5-
type DashboardPageProps = {
6-
params: Promise<{ locale: string }>;
7-
};
8-
9-
export async function generateMetadata(props: DashboardPageProps): Promise<Metadata> {
10-
const { locale } = await props.params;
11-
const t = await getTranslations({
12-
locale,
13-
namespace: 'Dashboard',
14-
});
15-
16-
return {
17-
title: t('meta_title'),
18-
};
19-
}
20-
21-
export default async function DashboardPage(props: DashboardPageProps) {
4+
export default async function DashboardPage(props: { params: Promise<{ locale: string }> }) {
225
const { locale } = await props.params;
236
setRequestLocale(locale);
247

src/app/[locale]/(auth)/dashboard/user-profile/[[...user-profile]]/page.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
import { UserProfile } from '@clerk/nextjs';
2-
import type { Metadata } from 'next';
3-
import { getTranslations, setRequestLocale } from 'next-intl/server';
2+
import { setRequestLocale } from 'next-intl/server';
43
import { getI18nPath } from '@/utils/Helpers';
54

6-
type UserProfilePageProps = {
7-
params: Promise<{ locale: string }>;
8-
};
9-
10-
export async function generateMetadata(props: UserProfilePageProps): Promise<Metadata> {
11-
const { locale } = await props.params;
12-
const t = await getTranslations({
13-
locale,
14-
namespace: 'UserProfile',
15-
});
16-
17-
return {
18-
title: t('meta_title'),
19-
};
20-
}
21-
22-
export default async function UserProfilePage(props: UserProfilePageProps) {
5+
export default async function UserProfilePage(props: { params: Promise<{ locale: string }> }) {
236
const { locale } = await props.params;
247
setRequestLocale(locale);
258

src/locales/en.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@
6161
"meta_description": "Effortlessly create an account through our intuitive sign-up process."
6262
},
6363
"Dashboard": {
64-
"meta_title": "Dashboard",
6564
"hello_message": "Hello {email}!",
6665
"alternative_message": "Need advanced features? Multi-tenancy & Teams, Roles & Permissions, Shadcn UI, End-to-End Typesafety with oRPC, Stripe Payment, Light / Dark mode. Try <url></url>.",
6766
"max_message": "Or, need a Self-hosted auth stack (Better Auth)? Try <url></url>."
6867
},
69-
"UserProfile": {
70-
"meta_title": "User Profile"
71-
},
7268
"DashboardLayout": {
69+
"meta_title": "Dashboard",
70+
"meta_description": "Manage your account from the dashboard.",
7371
"dashboard_link": "Dashboard",
7472
"user_profile_link": "Manage your account",
7573
"sign_out": "Sign out"

src/locales/fr.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@
6161
"meta_description": "Créez un compte facilement grâce à notre processus d'inscription intuitif."
6262
},
6363
"Dashboard": {
64-
"meta_title": "Tableau de bord",
6564
"hello_message": "Bonjour {email}!",
6665
"alternative_message": "Besoin de fonctionnalités avancées ? Multi-tenant et équipes, rôles et permissions, Shadcn UI, typage de bout en bout avec oRPC, paiement Stripe, mode clair / sombre. Essayez <url></url>.",
6766
"max_message": "Ou, besoin d'une stack d'auth auto-hébergée (Better Auth) ? Essayez <url></url>."
6867
},
69-
"UserProfile": {
70-
"meta_title": "Profil de l'utilisateur"
71-
},
7268
"DashboardLayout": {
69+
"meta_title": "Tableau de bord",
70+
"meta_description": "Gérez votre compte depuis le tableau de bord.",
7371
"dashboard_link": "Tableau de bord",
7472
"user_profile_link": "Gérer votre compte",
7573
"sign_out": "Se déconnecter"

src/utils/Helpers.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { routing } from '@/libs/I18nRouting';
33
import { getI18nPath } from './Helpers';
44

55
describe('Helpers', () => {
6-
describe('getI18nPath function', () => {
7-
it('should not change the path for default language', () => {
6+
describe('I18n path helper', () => {
7+
it('keeps path unchanged when locale is default', () => {
88
const url = '/random-url';
99
const locale = routing.defaultLocale;
1010

1111
expect(getI18nPath(url, locale)).toBe(url);
1212
});
1313

14-
it('should prepend the locale to the path for non-default language', () => {
14+
it('prefixes path with locale when locale is not default', () => {
1515
const url = '/random-url';
1616
const locale = 'fr';
1717

18-
expect(getI18nPath(url, locale)).toMatch(/^\/fr/u);
18+
expect(getI18nPath(url, locale)).toBe(`/fr${url}`);
1919
});
2020
});
2121
});

0 commit comments

Comments
 (0)