import { DeleteIcon } from '@chakra-ui/icons' import { IconButton, Spinner, Table, TableContainer, Tbody, Td, Th, Thead, Tooltip, Tr, } from '@chakra-ui/react' import { useEffect } from 'react' import { useSelector } from 'react-redux' import { selectAuthUser } from '../../store/authSlice' import { deleteDevice, fetchDevices, selectDeviceList, selectDeviceLoading } from '../../store/deviceSlice' import { useAppDispatch } from '../../store/hooks' const DeviceRow = ({ device, onDelete }: any) => { const { enabled, model, brand, _id, createdAt } = device return ( {`${brand}/ ${model}`} {enabled ? 'enabled' : 'disabled'} {/* {}} /> */} } onDoubleClick={onDelete} disabled /> ) } const DeviceList = () => { const dispatch = useAppDispatch() const authUser = useSelector(selectAuthUser) useEffect(() => { if (authUser) { dispatch(fetchDevices()) } }, [authUser, dispatch]) const deviceList = useSelector(selectDeviceList) const loading = useSelector(selectDeviceLoading) const onDelete = (apiKeyId: string) => { dispatch(deleteDevice(apiKeyId)) } return ( {loading && ( )} {!loading && deviceList.length === 0 && ( )} {!loading && deviceList.length > 0 && deviceList.map((device) => ( onDelete(device._id)} /> ))}
Your Devices Status Actions
No Devices
) } export default DeviceList