Extract shared pagination, search box, and escapeLike helpers
Pull PER_PAGE, parsePage, and halamanHref into lib/pagination, the search box into components/cari-master, and escapeLike into lib/utils so other master features can reuse them. Pelanggan switches to these helpers and its list now calls getCurrentUser() in its render chain.main
parent
930bfd2205
commit
6f1234aa49
@ -0,0 +1,19 @@
|
||||
export const PER_PAGE = 25;
|
||||
|
||||
// Batas atas mencegah offset melebihi BIGINT MariaDB (query error).
|
||||
export function parsePage(pageParam?: string): number {
|
||||
const parsed = Number.parseInt(pageParam ?? "1", 10);
|
||||
return Number.isSafeInteger(parsed) && parsed >= 1 ? parsed : 1;
|
||||
}
|
||||
|
||||
export function halamanHref(
|
||||
basePath: string,
|
||||
page: number,
|
||||
search?: string,
|
||||
): string {
|
||||
const params = new URLSearchParams();
|
||||
if (search) params.set("search", search);
|
||||
if (page > 1) params.set("page", String(page));
|
||||
const query = params.toString();
|
||||
return query ? `${basePath}?${query}` : basePath;
|
||||
}
|
||||
@ -1 +1,6 @@
|
||||
export { cn } from "cn"
|
||||
export { cn } from "cn";
|
||||
|
||||
// `\`, `%`, dan `_` adalah karakter khusus LIKE (escape default MariaDB `\`).
|
||||
export function escapeLike(value: string): string {
|
||||
return value.replace(/[\\%_]/g, "\\$&");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue