Skip to content

Commit

Permalink
fix: migrate the codebase to use await params
Browse files Browse the repository at this point in the history
  • Loading branch information
ixartz committed Nov 13, 2024
1 parent 9ec5886 commit 886a19e
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 119 deletions.
11 changes: 0 additions & 11 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import nextPlugin from '@next/eslint-plugin-next';
import jestDom from 'eslint-plugin-jest-dom';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import playwright from 'eslint-plugin-playwright';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import tailwind from 'eslint-plugin-tailwindcss';
import testingLibrary from 'eslint-plugin-testing-library';

Expand Down Expand Up @@ -34,14 +33,6 @@ export default antfu({
...nextPlugin.configs.recommended.rules,
...nextPlugin.configs['core-web-vitals'].rules,
},
}, {
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
},
}, {
files: [
'**/*.test.ts?(x)',
Expand All @@ -56,8 +47,6 @@ export default antfu({
...playwright.configs['flat/recommended'],
}, {
rules: {
'import/order': 'off', // Avoid conflicts with `simple-import-sort` plugin
'sort-imports': 'off', // Avoid conflicts with `simple-import-sort` plugin
'style/brace-style': ['error', '1tbs'], // Use the default brace style
'ts/consistent-type-definitions': ['error', 'type'], // Use `type` instead of `interface`
'react/prefer-destructuring-assignment': 'off', // Vscode doesn't support automatically destructuring, it's a pain to add a new variable
Expand Down
4 changes: 1 addition & 3 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export default withSentryConfig(
},
poweredByHeader: false,
reactStrictMode: true,
experimental: {
serverComponentsExternalPackages: ['@electric-sql/pglite'],
},
serverExternalPackages: ['@electric-sql/pglite'],
}),
),
{
Expand Down
18 changes: 11 additions & 7 deletions src/app/[locale]/(auth)/(center)/sign-in/[[...sign-in]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getI18nPath } from '@/utils/Helpers';
import { SignIn } from '@clerk/nextjs';
import { getTranslations } from 'next-intl/server';

import { getI18nPath } from '@/utils/Helpers';

export async function generateMetadata(props: { params: { locale: string } }) {
export async function generateMetadata(props: { params: Promise<{ locale: string }> }) {
const locale = (await props.params).locale;
const t = await getTranslations({
locale: props.params.locale,
locale,
namespace: 'SignIn',
});

Expand All @@ -15,8 +15,12 @@ export async function generateMetadata(props: { params: { locale: string } }) {
};
}

const SignInPage = (props: { params: { locale: string } }) => (
<SignIn path={getI18nPath('/sign-in', props.params.locale)} />
);
const SignInPage = async (props: { params: Promise<{ locale: string }> }) => {
const locale = (await props.params).locale;

return (
<SignIn path={getI18nPath('/sign-in', locale)} />
);
};

export default SignInPage;
18 changes: 11 additions & 7 deletions src/app/[locale]/(auth)/(center)/sign-up/[[...sign-up]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getI18nPath } from '@/utils/Helpers';
import { SignUp } from '@clerk/nextjs';
import { getTranslations } from 'next-intl/server';

import { getI18nPath } from '@/utils/Helpers';

export async function generateMetadata(props: { params: { locale: string } }) {
export async function generateMetadata(props: { params: Promise<{ locale: string }> }) {
const locale = (await props.params).locale;
const t = await getTranslations({
locale: props.params.locale,
locale,
namespace: 'SignUp',
});

Expand All @@ -15,8 +15,12 @@ export async function generateMetadata(props: { params: { locale: string } }) {
};
}

const SignUpPage = (props: { params: { locale: string } }) => (
<SignUp path={getI18nPath('/sign-up', props.params.locale)} />
);
const SignUpPage = async (props: { params: Promise<{ locale: string }> }) => {
const locale = (await props.params).locale;

return (
<SignUp path={getI18nPath('/sign-up', locale)} />
);
};

export default SignUpPage;
8 changes: 4 additions & 4 deletions src/app/[locale]/(auth)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getTranslations } from 'next-intl/server';

import { Hello } from '@/components/Hello';
import { getTranslations } from 'next-intl/server';

export async function generateMetadata(props: { params: { locale: string } }) {
export async function generateMetadata(props: { params: Promise<{ locale: string }> }) {
const locale = (await props.params).locale;
const t = await getTranslations({
locale: props.params.locale,
locale,
namespace: 'Dashboard',
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getI18nPath } from '@/utils/Helpers';
import { UserProfile } from '@clerk/nextjs';
import { getTranslations } from 'next-intl/server';

import { getI18nPath } from '@/utils/Helpers';

export async function generateMetadata(props: { params: { locale: string } }) {
export async function generateMetadata(props: { params: Promise<{ locale: string }> }) {
const locale = (await props.params).locale;
const t = await getTranslations({
locale: props.params.locale,
locale,
namespace: 'UserProfile',
});

Expand All @@ -14,12 +14,16 @@ export async function generateMetadata(props: { params: { locale: string } }) {
};
}

const UserProfilePage = (props: { params: { locale: string } }) => (
<div className="my-6 -ml-16">
<UserProfile
path={getI18nPath('/dashboard/user-profile', props.params.locale)}
/>
</div>
);
const UserProfilePage = async (props: { params: Promise<{ locale: string }> }) => {
const locale = (await props.params).locale;

return (
<div className="my-6 -ml-16">
<UserProfile
path={getI18nPath('/dashboard/user-profile', locale)}
/>
</div>
);
};

export default UserProfilePage;
20 changes: 10 additions & 10 deletions src/app/[locale]/(auth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { AppConfig } from '@/utils/AppConfig';
import { enUS, frFR } from '@clerk/localizations';
import { ClerkProvider } from '@clerk/nextjs';

import { AppConfig } from '@/utils/AppConfig';

export default function AuthLayout(props: {
export default async function AuthLayout(props: {
children: React.ReactNode;
params: { locale: string };
params: Promise<{ locale: string }>;
}) {
const locale = (await props.params).locale;
let clerkLocale = enUS;
let signInUrl = '/sign-in';
let signUpUrl = '/sign-up';
let dashboardUrl = '/dashboard';
let afterSignOutUrl = '/';

if (props.params.locale === 'fr') {
if (locale === 'fr') {
clerkLocale = frFR;
}

if (props.params.locale !== AppConfig.defaultLocale) {
signInUrl = `/${props.params.locale}${signInUrl}`;
signUpUrl = `/${props.params.locale}${signUpUrl}`;
dashboardUrl = `/${props.params.locale}${dashboardUrl}`;
afterSignOutUrl = `/${props.params.locale}${afterSignOutUrl}`;
if (locale !== AppConfig.defaultLocale) {
signInUrl = `/${locale}${signInUrl}`;
signUpUrl = `/${locale}${signUpUrl}`;
dashboardUrl = `/${locale}${dashboardUrl}`;
afterSignOutUrl = `/${locale}${afterSignOutUrl}`;
}

return (
Expand Down
18 changes: 11 additions & 7 deletions src/app/[locale]/(unauth)/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Image from 'next/image';
import { useTranslations } from 'next-intl';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
import { getTranslations, setRequestLocale } from 'next-intl/server';

export async function generateMetadata(props: { params: { locale: string } }) {
export async function generateMetadata(props: { params: Promise<{ locale: string }> }) {
const locale = (await props.params).locale;
const t = await getTranslations({
locale: props.params.locale,
locale,
namespace: 'About',
});

Expand All @@ -14,9 +14,13 @@ export async function generateMetadata(props: { params: { locale: string } }) {
};
}

const About = (props: { params: { locale: string } }) => {
unstable_setRequestLocale(props.params.locale);
const t = useTranslations('About');
const About = async (props: { params: Promise<{ locale: string }> }) => {
const locale = (await props.params).locale;
setRequestLocale(locale);
const t = await getTranslations({
locale,
namespace: 'About',
});

return (
<>
Expand Down
10 changes: 5 additions & 5 deletions src/app/[locale]/(unauth)/counter/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CounterForm } from '@/components/CounterForm';
import { CurrentCount } from '@/components/CurrentCount';
import Image from 'next/image';
import { useTranslations } from 'next-intl';
import { getTranslations } from 'next-intl/server';
import { Suspense } from 'react';

import { CounterForm } from '@/components/CounterForm';
import { CurrentCount } from '@/components/CurrentCount';

export async function generateMetadata(props: { params: { locale: string } }) {
export async function generateMetadata(props: { params: Promise<{ locale: string }> }) {
const locale = (await props.params).locale;
const t = await getTranslations({
locale: props.params.locale,
locale,
namespace: 'Counter',
});

Expand Down
18 changes: 10 additions & 8 deletions src/app/[locale]/(unauth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import Link from 'next/link';
import { useTranslations } from 'next-intl';
import { unstable_setRequestLocale } from 'next-intl/server';

import { DemoBanner } from '@/components/DemoBanner';
import { LocaleSwitcher } from '@/components/LocaleSwitcher';
import { BaseTemplate } from '@/templates/BaseTemplate';
import Link from 'next/link';
import { getTranslations, setRequestLocale } from 'next-intl/server';

export default function Layout(props: {
export default async function Layout(props: {
children: React.ReactNode;
params: { locale: string };
params: Promise<{ locale: string }>;
}) {
unstable_setRequestLocale(props.params.locale);
const t = useTranslations('RootLayout');
const locale = (await props.params).locale;
setRequestLocale(locale);
const t = await getTranslations({
locale,
namespace: 'RootLayout',
});

return (
<>
Expand Down
19 changes: 11 additions & 8 deletions src/app/[locale]/(unauth)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useTranslations } from 'next-intl';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { Sponsors } from '@/components/Sponsors';
import { getTranslations, setRequestLocale } from 'next-intl/server';

export async function generateMetadata(props: { params: { locale: string } }) {
export async function generateMetadata(props: { params: Promise<{ locale: string }> }) {
const locale = (await props.params).locale;
const t = await getTranslations({
locale: props.params.locale,
locale,
namespace: 'Index',
});

Expand All @@ -15,9 +14,13 @@ export async function generateMetadata(props: { params: { locale: string } }) {
};
}

const Index = (props: { params: { locale: string } }) => {
unstable_setRequestLocale(props.params.locale);
const t = useTranslations('Index');
const Index = async (props: { params: Promise<{ locale: string }> }) => {
const locale = (await props.params).locale;
setRequestLocale(locale);
const t = await getTranslations({
locale,
namespace: 'Index',
});

return (
<>
Expand Down
29 changes: 16 additions & 13 deletions src/app/[locale]/(unauth)/portfolio/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import Image from 'next/image';
import { useTranslations } from 'next-intl';
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';

import { AppConfig } from '@/utils/AppConfig';
import Image from 'next/image';
import { getTranslations, setRequestLocale } from 'next-intl/server';

type IPortfolioDetailProps = {
params: { slug: string; locale: string };
params: Promise<{ slug: string; locale: string }>;
};

export function generateStaticParams() {
return AppConfig.locales
.map(locale =>
Array.from(Array(6).keys()).map(elt => ({
Array.from(Array.from({ length: 6 }).keys()).map(elt => ({
slug: `${elt}`,
locale,
})),
Expand All @@ -20,24 +18,29 @@ export function generateStaticParams() {
}

export async function generateMetadata(props: IPortfolioDetailProps) {
const { locale, slug } = await props.params;
const t = await getTranslations({
locale: props.params.locale,
locale,
namespace: 'PortfolioSlug',
});

return {
title: t('meta_title', { slug: props.params.slug }),
description: t('meta_description', { slug: props.params.slug }),
title: t('meta_title', { slug }),
description: t('meta_description', { slug }),
};
}

const PortfolioDetail = (props: IPortfolioDetailProps) => {
unstable_setRequestLocale(props.params.locale);
const t = useTranslations('PortfolioSlug');
const PortfolioDetail = async (props: IPortfolioDetailProps) => {
const { locale, slug } = await props.params;
setRequestLocale(locale);
const t = await getTranslations({
locale,
namespace: 'PortfolioSlug',
});

return (
<>
<h1 className="capitalize">{t('header', { slug: props.params.slug })}</h1>
<h1 className="capitalize">{t('header', { slug })}</h1>
<p>{t('content')}</p>

<div className="mt-5 text-center text-sm">
Expand Down
Loading

0 comments on commit 886a19e

Please sign in to comment.