Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add missing locale in links #155

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { useLocale } from "next-intl";
import { useState } from "react";

import type { Menu } from "@nimara/domain/objects/Menu";
Expand All @@ -19,6 +20,7 @@ import type { Maybe } from "@/lib/types";
export const Navigation = ({ menu }: { menu: Maybe<Menu> }) => {
// Close menu manually
const [currentMenuItem, setCurrentMenuItem] = useState("");
const locale = useLocale();

if (!menu || menu?.items?.length === 0) {
return null;
Expand All @@ -36,6 +38,7 @@ export const Navigation = ({ menu }: { menu: Maybe<Menu> }) => {
<Link
href={item.url}
className="text-inherit no-underline hover:underline"
locale={locale}
>
<NavigationMenuTrigger showIcon={!!item.children?.length}>
{item.label}
Expand All @@ -53,6 +56,7 @@ export const Navigation = ({ menu }: { menu: Maybe<Menu> }) => {
key={child.id}
href={child.url}
className="group block space-y-1 rounded-md p-3 hover:bg-accent"
locale={locale}
>
<div className="text-sm font-medium leading-none">
{child.label}
Expand Down Expand Up @@ -83,6 +87,7 @@ export const Navigation = ({ menu }: { menu: Maybe<Menu> }) => {
href={child.url}
className="group relative min-h-[270px] overflow-hidden rounded-lg bg-accent"
onClick={() => setCurrentMenuItem("")}
locale={locale}
>
<div
className="h-1/2 bg-cover bg-center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getTranslations } from "next-intl/server";

import { Button } from "@nimara/ui/components/button";

import { Link } from "@/i18n/routing";
import { paths } from "@/lib/paths";

import { CheckoutRemover } from "./components/checkout-remover";
Expand All @@ -26,7 +27,7 @@ export default async function Page() {
{t.rich("order-confirmation.paragraph", { br: () => <br /> })}
</p>
<Button className="justify-self-center" asChild>
<a href={paths.home.asPath()}>{t("common.back-to-homepage")}</a>
<Link href={paths.home.asPath()}>{t("common.back-to-homepage")}</Link>
</Button>
<CheckoutRemover />
</div>
Expand Down
14 changes: 10 additions & 4 deletions apps/storefront/src/components/footer/footer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTranslations } from "next-intl/server";
import { getLocale, getTranslations } from "next-intl/server";

import NimaraLogo from "@/assets/nimara-logo.svg";
import { CACHE_TTL } from "@/config";
Expand All @@ -8,7 +8,8 @@ import { getCurrentRegion } from "@/regions/server";
import { cmsMenuService } from "@/services/cms";

export const Footer = async () => {
const [region, t] = await Promise.all([
const [locale, region, t] = await Promise.all([
getLocale(),
getCurrentRegion(),
getTranslations(),
]);
Expand Down Expand Up @@ -47,6 +48,7 @@ export const Footer = async () => {
className="flex justify-start align-middle"
href={paths.home.asPath()}
title={t("common.go-to-homepage")}
locale={locale}
>
<NimaraLogo height={36} />
</Link>
Expand All @@ -73,7 +75,9 @@ export const Footer = async () => {
<ul className="grid gap-4">
{categories?.menu.items.map((item) => (
<li key={item.id}>
<Link href={item.url}>{item.label}</Link>
<Link href={item.url} locale={locale}>
{item.label}
</Link>
</li>
))}
</ul>
Expand All @@ -84,7 +88,9 @@ export const Footer = async () => {
<ul className="grid gap-4">
{pages?.menu.items.map((item) => (
<li key={item.id}>
<Link href={item.url}>{item.label}</Link>
<Link href={item.url} locale={locale}>
{item.label}
</Link>
</li>
))}
</ul>
Expand Down
18 changes: 14 additions & 4 deletions apps/storefront/src/lib/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { headers } from "next/headers";
import { getLocale } from "next-intl/server";

export const getStoreUrl = async () =>
`${(await headers()).get("x-forwarded-proto")}://${(await headers()).get(
"x-forwarded-host",
)}`;
import { localePrefixes } from "@/i18n/routing";
import { DEFAULT_LOCALE, type Locale } from "@/regions/types";

export const getStoreUrl = async () => {
const locale = await getLocale();
const domain = `${(await headers()).get("x-forwarded-proto")}://${(
await headers()
).get("x-forwarded-host")}`;

return locale === DEFAULT_LOCALE
? domain
: `${domain}${localePrefixes[locale as Exclude<Locale, typeof DEFAULT_LOCALE>]}`;
};
Loading