import { useState } from 'react' import { useMutation } from '@tanstack/react-query' import { Search, AlertCircle } from 'lucide-react' import { devicesApi, type SubnetScanResponse } from '@/lib/api' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' interface Props { tenantId: string onResults: (results: SubnetScanResponse) => void } export function SubnetScanForm({ tenantId, onResults }: Props) { const [cidr, setCidr] = useState('') const [error, setError] = useState(null) const mutation = useMutation({ mutationFn: () => devicesApi.scan(tenantId, cidr), onSuccess: (data) => { onResults(data) }, onError: (err: unknown) => { const detail = (err as { response?: { data?: { detail?: string } } })?.response?.data?.detail ?? 'Scan failed. Check the CIDR format.' setError(detail) }, }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (!cidr.trim()) { setError('CIDR is required (e.g. 192.168.1.0/24)') return } setError(null) mutation.mutate() } return (

Scan Subnet

Discover MikroTik devices on a network range (max /20 — 4096 IPs)

{ setCidr(e.target.value) if (error) setError(null) }} placeholder="e.g., 192.168.1.0/24" autoFocus />

CIDR notation — /24 scans 254 addresses

{error && (

{error}

)} {mutation.isPending && (
Scanning {cidr}... This may take up to 30 seconds for larger ranges.
)}
) }