move things around

This commit is contained in:
2024-07-14 13:52:15 +02:00
parent 709ac0296d
commit 1aee971c7c
7 changed files with 261 additions and 144 deletions

View File

@@ -1,3 +1,4 @@
import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from "@/lib/constants";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { z } from "zod";
@@ -42,3 +43,29 @@ const imageUrlRegex = new RegExp(
export function isImageUrl(value: string) {
return value.match(imageUrlRegex);
}
export const cleanEmptyParams = <T extends Record<string, unknown>>(
search: T,
) => {
const newSearch = { ...search };
for (const key of Object.keys(search)) {
const value = newSearch[key];
if (
value === undefined ||
value === "" ||
(typeof value === "number" && Number.isNaN(value))
)
delete newSearch[key];
}
if (search.pageIndex === DEFAULT_PAGE_INDEX) {
// @ts-ignore
newSearch.pageIndex = undefined;
}
if (search.pageSize === DEFAULT_PAGE_SIZE) {
// @ts-ignore
newSearch.pageSize = undefined;
}
return newSearch;
};