Skip to content

Commit

Permalink
fix: Pass locale explicitly to shadcn pagination links (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
karolkarolka authored Jan 3, 2025
1 parent 971dbff commit 6985144
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useTranslations } from "next-intl";
import { useLocale, useTranslations } from "next-intl";

import type { PageInfo } from "@nimara/infrastructure/use-cases/search/types";
import {
Expand All @@ -11,8 +11,10 @@ import {
PaginationPrevious,
} from "@nimara/ui/components/pagination";

import { localePrefixes } from "@/i18n/routing";
import { paths } from "@/lib/paths";
import { cn } from "@/lib/utils";
import { DEFAULT_LOCALE, type Locale } from "@/regions/types";

type Props = {
pageInfo: PageInfo;
Expand All @@ -21,6 +23,7 @@ type Props = {

export const SearchPagination = ({ pageInfo, searchParams }: Props) => {
const t = useTranslations("common");
const locale = useLocale();

const getPathName = (direction: "next" | "previous") => {
const params = new URLSearchParams(searchParams);
Expand All @@ -45,7 +48,8 @@ export const SearchPagination = ({ pageInfo, searchParams }: Props) => {
params.set("page", page.toString());
}

return `${paths.search.asPath()}?${params.toString()}`;
// Shadcn use simple <a> tag instead of next-intl <Link> so we need to pass locale explicitly
return `${locale !== DEFAULT_LOCALE ? localePrefixes[locale as Exclude<Locale, typeof DEFAULT_LOCALE>] : ""}${paths.search.asPath()}?${params.toString()}`;
};

return (
Expand Down

0 comments on commit 6985144

Please sign in to comment.