Skip to content

Commit

Permalink
Merge pull request #619 from VitNode/perf/next-intl_v4
Browse files Browse the repository at this point in the history
perf(frontend)!: Update to next-intl v4
  • Loading branch information
aXenDeveloper authored Dec 23, 2024
2 parents 4a56616 + 432e409 commit 04fdeeb
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 79 deletions.
6 changes: 4 additions & 2 deletions apps/frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type welcome from '@/plugins/welcome/langs/en.json';

type Messages = typeof core & typeof admin & typeof welcome;

declare global {
interface IntlMessages extends Messages {}
declare module 'next-intl' {
interface AppConfig {
Messages: Messages;
}
}
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"geist": "^1.3.1",
"lucide-react": "^0.468.0",
"next": "^15.1.2",
"next-intl": "^3.26.2",
"next-intl": "4.0.0-beta-ddd5ae5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const createPackagesJSON = async ({
geist: '^1.3.1',
'lucide-react': '^0.469.0',
next: '^15.1.2',
'next-intl': '^3.26.2',
'next-intl': '4.0.0-beta-ddd5ae5',
react: '^19.0.0',
'react-dom': '^19.0.0',
'react-hook-form': '^7.54.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type welcome from '@/plugins/welcome/langs/en.json';

type Messages = typeof core & typeof admin & typeof welcome;

declare global {
interface IntlMessages extends Messages {}
declare module 'next-intl' {
interface AppConfig {
Messages: Messages;
}
}
6 changes: 4 additions & 2 deletions packages/frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type welcome from '../../apps/frontend/src/plugins/welcome/langs/en.json'

type Messages = typeof core & typeof admin & typeof welcome;

declare global {
interface IntlMessages extends Messages {}
declare module 'next-intl' {
interface AppConfig {
Messages: Messages;
}
}
4 changes: 2 additions & 2 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"@hookform/resolvers": "^3.9.1",
"lucide-react": "*",
"next": "^15.1.2",
"next-intl": "^3.26.2",
"next-intl": "4.0.0-beta-ddd5ae5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.1",
Expand All @@ -119,7 +119,7 @@
"eslint-config-typescript-vitnode": "workspace:*",
"lucide-react": "^0.469.0",
"next": "^15.1.2",
"next-intl": "^3.26.3",
"next-intl": "4.0.0-beta-ddd5ae5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.2",
Expand Down
12 changes: 7 additions & 5 deletions packages/frontend/src/components/translations-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { NamespaceKeys, NestedKeyOf, NextIntlClientProvider } from 'next-intl';
import {
Messages,
NamespaceKeys,
NestedKeyOf,
NextIntlClientProvider,
} from 'next-intl';
import { getLocale, getMessages } from 'next-intl/server';
import 'server-only';

Expand Down Expand Up @@ -30,10 +35,7 @@ const pick = (obj: object, paths: string[]) => {
};

export async function TranslationsProvider<
NestedKey extends NamespaceKeys<
IntlMessages,
NestedKeyOf<IntlMessages>
> = never,
NestedKey extends NamespaceKeys<Messages, NestedKeyOf<Messages>> = never,
>({
children,
namespaces,
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const i18nConfigVitNode = async ({
}) => Promise<{ default: object }>;
requestLocale: Promise<string | undefined>;
}) => {
let locale = await requestLocale;
let defaultLocale = 'en';
let locale = (await requestLocale) ?? 'en';

if (!locale) {
locale = 'en';
Expand All @@ -28,7 +28,7 @@ export const i18nConfigVitNode = async ({
const defaultLanguage = data.languages.find(lang => lang.default);
defaultLocale = defaultLanguage?.code ?? 'en';
if (!data.languages.find(lang => lang.code === locale)) {
locale = defaultLanguage?.code;
locale = defaultLanguage?.code ?? defaultLocale;
}
} catch (_) {
// If the request fails, we will use the default plugins
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/src/navigation/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createNavigation } from 'next-intl/navigation';
import { createNavigation, QueryParams } from 'next-intl/navigation';
import { getLocale } from 'next-intl/server';
import { RedirectType } from 'next/navigation';
import { QueryParams } from 'node_modules/next-intl/dist/types/src/navigation/shared/utils';
import React from 'react';

import { usePathname, useRouter } from './router';
Expand Down
46 changes: 27 additions & 19 deletions packages/frontend/src/views/admin/layout/sidebar/item-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,39 @@ export const ItemNavSidebarAdmin = ({
);
if (!textAndIcon) return null;

const button = (
<SidebarMenuButton
asChild
isActive={pathname.startsWith(href)}
onClick={() => {
setOpenMobile(false);
}}
>
<Link
href={item.children?.length ? `${href}/${item.children[0].code}` : href}
>
{textAndIcon.icon}
<span>{textAndIcon.text}</span>
</Link>
</SidebarMenuButton>
);

if (!item.children?.length) {
return <SidebarMenuItem>{button}</SidebarMenuItem>;
return (
<SidebarMenuItem>
<SidebarMenuButton
asChild
isActive={pathname.startsWith(href)}
onClick={() => {
setOpenMobile(false);
}}
>
<Link
href={
item.children?.length ? `${href}/${item.children[0].code}` : href
}
>
{textAndIcon.icon}
<span>{textAndIcon.text}</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
);
}

return (
<Collapsible asChild defaultOpen={pathname.startsWith(href)}>
<SidebarMenuItem>
{button}
<CollapsibleTrigger asChild>
<SidebarMenuButton isActive={pathname.startsWith(href)}>
{textAndIcon.icon}
<span>{textAndIcon.text}</span>
</SidebarMenuButton>
</CollapsibleTrigger>

<>
<CollapsibleTrigger asChild>
<SidebarMenuAction className="data-[state=open]:rotate-90">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const DescFieldContentMainSettingsCoreAdmin = ({
onLanguageChange={setSelectedLanguage}
/>

<div className="flex w-32 items-center justify-center">
<div className="flex w-32 items-center justify-start">
<TooltipWrapper content={t('description.seo')}>
<Badge
className="mt-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ContentMainSettingsCoreAdmin = (props: ShowMiddlewareObj) => {
component: props => (
<>
<AutoFormInput {...props} />
<div className="flex w-32 items-center justify-center">
<div className="flex w-32 items-center justify-start">
<TooltipWrapper content={t('name.seo')}>
<Badge
className="mt-1"
Expand All @@ -50,7 +50,7 @@ export const ContentMainSettingsCoreAdmin = (props: ShowMiddlewareObj) => {
component: props => (
<>
<AutoFormInput {...props} />
<div className="flex w-32 items-center justify-center">
<div className="flex w-32 items-center justify-start">
<TooltipWrapper content={t('short_name.seo')}>
<Badge
className="mt-1"
Expand Down
63 changes: 25 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04fdeeb

Please sign in to comment.