mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 09:48:22 +00:00
WIP feat(admin-devices): enhance device management from admin with dynamic filters and improved blocking functionality
This commit is contained in:
@ -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/`,
|
||||
|
Reference in New Issue
Block a user