ldc-ovoteam/resources/ts/back/Components/Pagination/PaginationPerPage.tsx
Jérémy Munsch cd2d8ed397
refactor(i18n): replace GetTranslation with trans function
- Updated translation utility to improve consistency and reduce redundancy.
- Removed deprecated useTrans hook and related code.
- Introduced a new Zustand store for managing translations and locale settings.
- Cleaned up unused hooks and files related to localization.
2026-10-19 17:43:33 +02:00

60 lines
1.6 KiB
TypeScript

import { router, usePage } from "@inertiajs/react";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import trans from "@/hooks/use-translations";
export default function PaginationPerPage({
perPage,
total,
}: Readonly<{
perPage: number;
total: number;
}>) {
const enumItemsPerPagination = usePage().props
.enumItemsPerPagination as Record<
string,
{ label: string; name: string; value: number }
>;
const enumMinValue = Math.min(
...Object.values(enumItemsPerPagination).map((item) => item.value),
);
const paginationListTrans = trans("uwil-backend::pagination.paginate_list");
const handleSelectChange = (value: string) => {
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
params.set("pagination", value);
router.visit(`${url.pathname}?${params}`);
};
return (
total > enumMinValue && (
<Select
value={String(perPage)}
onValueChange={(value) => {
handleSelectChange(value);
}}
>
<SelectTrigger className="w-[4.5rem]">
<SelectValue placeholder={paginationListTrans} />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel className="me-7">{paginationListTrans}</SelectLabel>
{Object.values(enumItemsPerPagination).map((item) => (
<SelectItem key={item.value} value={String(item.value)}>
{item.value}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
)
);
}