Fix dynamic default locale routing
This commit is contained in:
@@ -5,7 +5,7 @@ import { isRedirectError } from "next/dist/client/components/redirect-error";
|
||||
import { z } from "zod";
|
||||
|
||||
import { enforceContactRateLimit, verifyTurnstileToken } from "@/lib/contact-guard";
|
||||
import { getContactProtectionSettings } from "@/lib/app-config";
|
||||
import { getContactProtectionSettings, getSiteSettings } from "@/lib/app-config";
|
||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||
import { sendContactMessage } from "@/lib/mail";
|
||||
|
||||
@@ -60,7 +60,8 @@ function getStringValue(formData: FormData, key: string) {
|
||||
|
||||
export async function submitContactFormAction(formData: FormData) {
|
||||
const locale = resolveLocale(String(formData.get("locale") ?? ""));
|
||||
const contactPath = getLocalizedPath(locale, "/contact");
|
||||
const siteSettings = await getSiteSettings();
|
||||
const contactPath = getLocalizedPath(locale, "/contact", siteSettings.defaultLocale);
|
||||
|
||||
try {
|
||||
const protectionSettings = await getContactProtectionSettings();
|
||||
@@ -86,7 +87,13 @@ export async function submitContactFormAction(formData: FormData) {
|
||||
message: values.message,
|
||||
});
|
||||
|
||||
redirect(withMessage(getLocalizedPath(locale, "/success"), "success", contactSuccessMessages[locale]));
|
||||
redirect(
|
||||
withMessage(
|
||||
getLocalizedPath(locale, "/success", siteSettings.defaultLocale),
|
||||
"success",
|
||||
contactSuccessMessages[locale],
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
if (isRedirectError(error)) {
|
||||
throw error;
|
||||
|
||||
@@ -7,7 +7,7 @@ import { PageHero } from "@/components/layout/page-hero";
|
||||
import { MotionFade } from "@/components/motion-fade";
|
||||
import { ContactForm } from "@/components/site/contact-form";
|
||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||
import { getPublicContactProtectionSettings } from "@/lib/app-config";
|
||||
import { getPublicContactProtectionSettings, getSiteSettings } from "@/lib/app-config";
|
||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||
import { AppCard } from "@/components/ui/app-card";
|
||||
import { CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
@@ -36,9 +36,10 @@ export async function generateMetadata({ params }: ContactPageProps): Promise<Me
|
||||
export default async function ContactPage({ params }: ContactPageProps) {
|
||||
const { locale } = await params;
|
||||
const localeKey = resolveLocale(locale);
|
||||
const [t, protection] = await Promise.all([
|
||||
const [t, protection, siteSettings] = await Promise.all([
|
||||
getTranslations({ locale: localeKey, namespace: "contactPage" }),
|
||||
getPublicContactProtectionSettings(),
|
||||
getSiteSettings(),
|
||||
]);
|
||||
|
||||
return (
|
||||
@@ -82,7 +83,7 @@ export default async function ContactPage({ params }: ContactPageProps) {
|
||||
<ContactForm
|
||||
action={submitContactFormAction}
|
||||
locale={localeKey}
|
||||
previewHref={getLocalizedPath(localeKey, "/success")}
|
||||
previewHref={getLocalizedPath(localeKey, "/success", siteSettings.defaultLocale)}
|
||||
protection={protection}
|
||||
copy={{
|
||||
name: t("name"),
|
||||
|
||||
@@ -6,7 +6,7 @@ import { SiteAmbientBackdrop } from "@/components/layout/site-ambient-backdrop";
|
||||
import { SiteFooter } from "@/components/layout/site-footer";
|
||||
import { SiteHeader } from "@/components/layout/site-header";
|
||||
import { isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { getMaintenanceMode, getSiteSettingsMediaBindings } from "@/lib/app-config";
|
||||
import { getMaintenanceMode, getSiteSettings, getSiteSettingsMediaBindings } from "@/lib/app-config";
|
||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||
|
||||
type SiteLayoutProps = {
|
||||
@@ -24,14 +24,15 @@ export default async function SiteLayout({ children, params }: SiteLayoutProps)
|
||||
const { locale } = await params;
|
||||
|
||||
const localeKey = resolveLocale(locale);
|
||||
const [maintenanceEnabled, mediaBindings] = await Promise.all([
|
||||
const [maintenanceEnabled, mediaBindings, siteSettings] = await Promise.all([
|
||||
getMaintenanceMode(),
|
||||
getSiteSettingsMediaBindings(),
|
||||
getSiteSettings(),
|
||||
]);
|
||||
const authenticated = await isAdminAuthenticated();
|
||||
|
||||
if (maintenanceEnabled && !authenticated) {
|
||||
redirect(getLocalizedPath(localeKey, "/coming-soon"));
|
||||
redirect(getLocalizedPath(localeKey, "/coming-soon", siteSettings.defaultLocale));
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -40,9 +41,10 @@ export default async function SiteLayout({ children, params }: SiteLayoutProps)
|
||||
<SiteHeader
|
||||
lightLogoUrl={mediaBindings.siteLogoLight?.url}
|
||||
darkLogoUrl={mediaBindings.siteLogoDark?.url}
|
||||
defaultLocale={siteSettings.defaultLocale}
|
||||
/>
|
||||
<main className="flex-1">{children}</main>
|
||||
<SiteFooter />
|
||||
<SiteFooter defaultLocale={siteSettings.defaultLocale} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,9 +61,10 @@ export async function generateMetadata({ params }: HomePageProps): Promise<Metad
|
||||
export default async function HomePage({ params }: HomePageProps) {
|
||||
const { locale } = await params;
|
||||
const localeKey = resolveLocale(locale);
|
||||
const [t, marqueeSettings] = await Promise.all([
|
||||
const [t, marqueeSettings, siteSettings] = await Promise.all([
|
||||
getTranslations({ locale: localeKey, namespace: "homepage" }),
|
||||
getMarqueeSettings(),
|
||||
getSiteSettings(),
|
||||
]);
|
||||
const serviceItems = [
|
||||
t("serviceBrand"),
|
||||
@@ -108,7 +109,7 @@ export default async function HomePage({ params }: HomePageProps) {
|
||||
</p>
|
||||
<div className="mt-8 flex flex-wrap gap-3">
|
||||
<Button asChild size="lg" className="min-w-[11rem]">
|
||||
<Link href={getLocalizedPath(localeKey, "/contact")}>
|
||||
<Link href={getLocalizedPath(localeKey, "/contact", siteSettings.defaultLocale)}>
|
||||
{t("servicesPrimaryCta")}
|
||||
<ArrowRight className="h-4 w-4" />
|
||||
</Link>
|
||||
@@ -119,7 +120,7 @@ export default async function HomePage({ params }: HomePageProps) {
|
||||
variant="outline"
|
||||
className="min-w-[11rem] border-border/80 bg-background/70 hover:bg-background"
|
||||
>
|
||||
<Link href={getLocalizedPath(localeKey, "/portfolio")}>
|
||||
<Link href={getLocalizedPath(localeKey, "/portfolio", siteSettings.defaultLocale)}>
|
||||
{t("servicesSecondaryCta")}
|
||||
</Link>
|
||||
</Button>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/layout/container";
|
||||
import { MotionFade } from "@/components/motion-fade";
|
||||
import { HeroShell, HeroTitle } from "@/components/layout/site-hero";
|
||||
import { getSiteSettings } from "@/lib/app-config";
|
||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||
import { AppCard } from "@/components/ui/app-card";
|
||||
@@ -34,7 +35,10 @@ export async function generateMetadata({ params }: SuccessPageProps): Promise<Me
|
||||
export default async function SuccessPage({ params }: SuccessPageProps) {
|
||||
const { locale } = await params;
|
||||
const localeKey = resolveLocale(locale);
|
||||
const t = await getTranslations({ locale: localeKey, namespace: "successPage" });
|
||||
const [t, siteSettings] = await Promise.all([
|
||||
getTranslations({ locale: localeKey, namespace: "successPage" }),
|
||||
getSiteSettings(),
|
||||
]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -51,10 +55,10 @@ export default async function SuccessPage({ params }: SuccessPageProps) {
|
||||
</p>
|
||||
<div className="mt-8 flex flex-wrap items-center justify-center gap-3">
|
||||
<Button asChild>
|
||||
<Link href={getLocalizedPath(localeKey)}>{t("home")}</Link>
|
||||
<Link href={getLocalizedPath(localeKey, "/", siteSettings.defaultLocale)}>{t("home")}</Link>
|
||||
</Button>
|
||||
<Button asChild variant="outline">
|
||||
<Link href={getLocalizedPath(localeKey, "/contact")}>{t("contact")}</Link>
|
||||
<Link href={getLocalizedPath(localeKey, "/contact", siteSettings.defaultLocale)}>{t("contact")}</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user