2024-12-06 14:16:05 +05:00
|
|
|
'use client'
|
|
|
|
import { deviceCartAtom } from '@/lib/atoms'
|
|
|
|
import type { Device } from '@prisma/client'
|
|
|
|
import { useAtomValue, useSetAtom } from 'jotai'
|
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
export default function AddDevicesToCartButton({ device }: { device: Device }) {
|
|
|
|
const setDeviceCart = useSetAtom(deviceCartAtom)
|
|
|
|
const devices = useAtomValue(deviceCartAtom)
|
|
|
|
|
2024-12-26 00:43:39 +05:00
|
|
|
const isChecked = devices.some((d) => d.id === device.id);
|
2024-12-06 14:16:05 +05:00
|
|
|
|
2024-12-26 00:43:39 +05:00
|
|
|
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]
|
2024-12-06 14:16:05 +05:00
|
|
|
)}
|
2024-12-26 00:43:39 +05:00
|
|
|
/>
|
2024-12-06 14:16:05 +05:00
|
|
|
)
|
|
|
|
}
|