mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-01 15:23:58 +00:00
refactor: implement session checking utility, enhance device queries with session validation, and improve UI interactions for device management
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 6m36s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 6m36s
This commit is contained in:
@ -1,25 +1,28 @@
|
||||
'use client'
|
||||
import { deviceCartAtom } from '@/lib/atoms'
|
||||
import type { Device } from '@prisma/client'
|
||||
import { useAtomValue, useSetAtom } from 'jotai'
|
||||
import React from 'react'
|
||||
"use client";
|
||||
import { deviceCartAtom } from "@/lib/atoms";
|
||||
import type { Device } from "@/lib/backend-types";
|
||||
import { useAtomValue, useSetAtom } from "jotai";
|
||||
import React from "react";
|
||||
|
||||
export default function AddDevicesToCartButton({ device }: { device: Device }) {
|
||||
const setDeviceCart = useSetAtom(deviceCartAtom)
|
||||
const devices = useAtomValue(deviceCartAtom)
|
||||
const setDeviceCart = useSetAtom(deviceCartAtom);
|
||||
const devices = useAtomValue(deviceCartAtom);
|
||||
|
||||
const isChecked = devices.some((d) => d.id === device.id);
|
||||
const isChecked = devices.some((d) => d.id === device.id);
|
||||
|
||||
return (
|
||||
<input
|
||||
type="checkbox"
|
||||
className='peer accent-[#f49d1b] size-4'
|
||||
checked={isChecked}
|
||||
onChange={() => setDeviceCart((prev) =>
|
||||
isChecked
|
||||
? prev.filter((d) => d.id !== device.id)
|
||||
: [...prev, device]
|
||||
)}
|
||||
/>
|
||||
)
|
||||
return (
|
||||
<input
|
||||
type="checkbox"
|
||||
disabled={device.blocked || device.is_active}
|
||||
className="peer accent-[#f49d1b] size-4"
|
||||
checked={isChecked}
|
||||
onChange={() =>
|
||||
setDeviceCart((prev) =>
|
||||
isChecked
|
||||
? prev.filter((d) => d.id !== device.id)
|
||||
: [...prev, device],
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user