feat(devices): add proper filter handling and update shadcn 🔨

This commit is contained in:
2025-06-26 18:42:48 +05:00
parent 6aea54884d
commit 59adaaf281
46 changed files with 9472 additions and 1055 deletions

View File

@ -9,17 +9,25 @@ import { getServerSession } from "next-auth";
import { revalidatePath } from "next/cache";
type GetDevicesProps = {
query?: string;
name?: string;
offset?: number;
limit?: number;
page?: number;
sortBy?: string;
status?: string;
[key: string]: string | number | undefined; // Allow additional properties for flexibility
};
export async function getDevices({ query, offset, limit }: GetDevicesProps) {
export async function getDevices(params: GetDevicesProps) {
const session = await checkSession();
// Build query string from all defined params
const query = Object.entries(params)
.filter(([_, value]) => value !== undefined && value !== "")
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
.join("&");
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/devices/?name=${query}&offset=${offset}&limit=${limit}`,
`${process.env.SARLINK_API_BASE_URL}/api/devices/?${query}`,
{
method: "GET",
headers: {