WIP feat(admin-devices): enhance device management from admin with dynamic filters and improved blocking functionality

This commit is contained in:
2025-06-30 15:16:36 +05:00
parent 0157eccd57
commit 01b064aee7
7 changed files with 266 additions and 307 deletions

View File

@ -1,12 +1,12 @@
"use server";
import { revalidatePath } from "next/cache";
import { getServerSession } from "next-auth";
import { authOptions } from "@/app/auth";
import type { AddDeviceFormState, initialState } from "@/components/user/add-device-dialog";
import type { ApiError, ApiResponse, Device } from "@/lib/backend-types";
import { checkSession } from "@/utils/session";
import { handleApiResponse } from "@/utils/tryCatch";
import { getServerSession } from "next-auth";
import { revalidatePath } from "next/cache";
type GetDevicesProps = {
name?: string;
@ -17,7 +17,7 @@ type GetDevicesProps = {
status?: string;
[key: string]: string | number | undefined; // Allow additional properties for flexibility
};
export async function getDevices(params: GetDevicesProps) {
export async function getDevices(params: GetDevicesProps, allDevices = false) {
const session = await checkSession();
// Build query string from all defined params
@ -27,7 +27,7 @@ export async function getDevices(params: GetDevicesProps) {
.join("&");
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/devices/?${query}`,
`${process.env.SARLINK_API_BASE_URL}/api/devices/?${query}&all_devices=${allDevices}`,
{
method: "GET",
headers: {
@ -123,6 +123,7 @@ export async function blockDevice({
reason_for_blocking: string;
blocked_by: "ADMIN" | "PARENT";
}) {
console.log("Blocking device:", deviceId, reason_for_blocking, blocked_by);
const session = await getServerSession(authOptions);
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/devices/${deviceId}/block/`,