diff --git a/app/[locale]/page.tsx b/app/[locale]/page.tsx index deb56c5..74475a7 100644 --- a/app/[locale]/page.tsx +++ b/app/[locale]/page.tsx @@ -1,6 +1,9 @@ -import { redirect } from 'next/navigation' -import React from 'react' + +import PaymentFailed from "@/components/pages/payment"; +import { redirect } from "next/navigation"; +import React from "react"; export default function Page() { - return redirect('/home') + // return redirect('/home') + return ; } diff --git a/app/layout.tsx b/app/layout.tsx index 0b6ab4a..6fee620 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -155,10 +155,11 @@ export default async function RootLayout({ - + {/* {children} - + */} + {children} ); diff --git a/app/page.tsx b/app/page.tsx index 338fa12..4387837 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,5 +1,8 @@ + +import PaymentFailed from "@/components/pages/payment"; import { redirect } from "next/navigation"; export default function Home() { - return redirect('/uz/home') + // return redirect('/uz/home') + return ; } diff --git a/components/languageSwitcher.tsx b/components/languageSwitcher.tsx index b25f4ae..ef89408 100644 --- a/components/languageSwitcher.tsx +++ b/components/languageSwitcher.tsx @@ -5,10 +5,12 @@ import { useRouter, usePathname } from "next/navigation"; import { Check, ChevronDown, Globe } from "lucide-react"; import { locales, localeFlags, localeNames, type Locale } from "@/i18n/config"; import { useLocale } from "next-intl"; +import { useQueryClient } from "@tanstack/react-query"; export default function LanguageSelectRadix() { const router = useRouter(); const pathname = usePathname(); + const queryClient = useQueryClient(); const currentLocale = useLocale() as Locale; const [isPending, startTransition] = useTransition(); const [isOpen, setIsOpen] = useState(false); @@ -46,6 +48,9 @@ export default function LanguageSelectRadix() { }, 100); // Small delay ensures navigation completes }); + setTimeout(() => { + queryClient.invalidateQueries({ queryKey: [newLocale] }); + }, 200); setIsOpen(false); }; @@ -55,7 +60,7 @@ export default function LanguageSelectRadix() { + ))} + + +
+

+ {t.title.split("\n").map((line:any, i:number) => + i === 1 ? ( + {line} + ) : ( + {line} + ) + )} +

+
+ +
+
+ {t.code} + {ERROR_CODE} +
+
+ {t.time} + {time} +
+
+ + + {/* RIGHT */} +
+
+
+ +
+ + {t.badge} +
+ +
+
+ + + +
+ +

{t.subtitle}

+ +
+

{t.reasons_title}

+ {t.reasons.map((reason, i) => ( +
+ + {reason} +
+ ))} +
+ +
+ +
+
+
+ + ); +} \ No newline at end of file diff --git a/middleware.ts b/middleware.ts index ae1ae3c..b5ccfac 100644 --- a/middleware.ts +++ b/middleware.ts @@ -1,7 +1,6 @@ import { NextRequest, NextResponse } from "next/server"; import { match as matchLocale } from "@formatjs/intl-localematcher"; import Negotiator from "negotiator"; -const PUBLIC_PAGES = ["/login", "/register"]; const LOCALES = ["uz", "ru", "en"]; const DEFAULT_LOCALE = "uz"; @@ -9,23 +8,18 @@ const DEFAULT_LOCALE = "uz"; type Locale = (typeof LOCALES)[number]; function getLocaleFromPathname(pathname: string): Locale | null { - const segments = pathname.split("/").filter(Boolean); - const firstSegment = segments[0]; - + const firstSegment = pathname.split("/").filter(Boolean)[0]; if (firstSegment && LOCALES.includes(firstSegment as Locale)) { return firstSegment as Locale; } - return null; } function getLocaleFromCookie(request: NextRequest): Locale | null { const cookieLocale = request.cookies.get("NEXT_LOCALE")?.value; - if (cookieLocale && LOCALES.includes(cookieLocale as Locale)) { return cookieLocale as Locale; } - return null; } @@ -36,13 +30,8 @@ function getLocaleFromHeaders(request: NextRequest): Locale { }); const languages = new Negotiator({ headers: negotiatorHeaders }).languages(); - try { - return matchLocale( - languages, - LOCALES as unknown as string[], - DEFAULT_LOCALE - ) as Locale; + return matchLocale(languages, LOCALES as string[], DEFAULT_LOCALE) as Locale; } catch { return DEFAULT_LOCALE; } @@ -51,86 +40,37 @@ function getLocaleFromHeaders(request: NextRequest): Locale { export function middleware(request: NextRequest) { const { pathname, search } = request.nextUrl; - // Skip public files and API routes - if ( - pathname.includes(".") || - pathname.startsWith("/api") || - pathname.startsWith("/_next") - ) { - return NextResponse.next(); - } - - // 1. Check URL locale + // 1. If URL has a locale, pass it through with headers (+ sync cookie if needed) const localeFromPath = getLocaleFromPathname(pathname); - - // 2. Check cookie locale const localeFromCookie = getLocaleFromCookie(request); + const preferredLocale = localeFromPath ?? localeFromCookie ?? getLocaleFromHeaders(request); - // 3. Check browser locale - const localeFromBrowser = getLocaleFromHeaders(request); - - // Priority: URL > Cookie > Browser - const preferredLocale = - localeFromPath || localeFromCookie || localeFromBrowser; - - // Faqat kerakli sahifalarni redirect qilamiz - const isPublicPage = PUBLIC_PAGES.some((page) => pathname === page); - - if (isPublicPage) { - const url = request.nextUrl.clone(); - url.pathname = `/${DEFAULT_LOCALE}/verify-otp`; - url.search = search; // ?code=1111&phone=... - - return NextResponse.redirect(url); - } - - // If URL has no locale, redirect with preferred locale + // 2. No locale in URL → redirect to preferred locale if (!localeFromPath) { const newUrl = new URL(`/${preferredLocale}${pathname}`, request.url); + newUrl.search = search; return NextResponse.redirect(newUrl); } - // If URL locale differs from cookie, update cookie - if (localeFromPath !== localeFromCookie) { - const response = NextResponse.next(); - - // ✅ Set cookie on server side - response.cookies.set("NEXT_LOCALE", localeFromPath, { - path: "/", - maxAge: 31536000, // 1 year - sameSite: "lax", - }); - - // ✅ Pass locale to request headers for server components - const requestHeaders = new Headers(request.headers); - requestHeaders.set("x-locale", localeFromPath); - requestHeaders.set("x-pathname", pathname); - - return NextResponse.next({ - request: { - headers: requestHeaders, - }, - }); - } - - // Normal flow - just pass locale in headers - const response = NextResponse.next(); + // 3. Build response with locale headers for server components const requestHeaders = new Headers(request.headers); requestHeaders.set("x-locale", localeFromPath); requestHeaders.set("x-pathname", pathname); - return NextResponse.next({ - request: { - headers: requestHeaders, - }, - }); + const response = NextResponse.next({ request: { headers: requestHeaders } }); + + // 4. Sync cookie if it differs from URL locale + if (localeFromPath !== localeFromCookie) { + response.cookies.set("NEXT_LOCALE", localeFromPath, { + path: "/", + maxAge: 31_536_000, // 1 year + sameSite: "lax", + }); + } + + return response; } export const config = { - matcher: [ - // Match all pathnames except for - // - … if they start with `/api`, `/_next` or `/_vercel` - // - … the ones containing a dot (e.g. `favicon.ico`) - '/((?!api|_next|_vercel|.*\\..*).*)', - ], + matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"], }; \ No newline at end of file