diff --git a/frontend/src/components/sites/SectorFormDialog.tsx b/frontend/src/components/sites/SectorFormDialog.tsx index 40fc4f4..1d747ec 100644 --- a/frontend/src/components/sites/SectorFormDialog.tsx +++ b/frontend/src/components/sites/SectorFormDialog.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react' +import { useState } from 'react' import { useMutation, useQueryClient } from '@tanstack/react-query' import { sectorsApi, type SectorResponse, type SectorCreate, type SectorUpdate } from '@/lib/api' import { @@ -25,21 +25,9 @@ export function SectorFormDialog({ open, onOpenChange, tenantId, siteId, sector const queryClient = useQueryClient() const isEdit = !!sector - const [name, setName] = useState('') - const [azimuth, setAzimuth] = useState('') - const [description, setDescription] = useState('') - - useEffect(() => { - if (sector) { - setName(sector.name) - setAzimuth(sector.azimuth != null ? String(sector.azimuth) : '') - setDescription(sector.description ?? '') - } else { - setName('') - setAzimuth('') - setDescription('') - } - }, [sector, open]) + const [name, setName] = useState(sector?.name ?? '') + const [azimuth, setAzimuth] = useState(sector?.azimuth != null ? String(sector.azimuth) : '') + const [description, setDescription] = useState(sector?.description ?? '') const createMutation = useMutation({ mutationFn: (data: SectorCreate) => sectorsApi.create(tenantId, siteId, data), diff --git a/frontend/src/components/sites/SiteFormDialog.tsx b/frontend/src/components/sites/SiteFormDialog.tsx index 3257c60..5303178 100644 --- a/frontend/src/components/sites/SiteFormDialog.tsx +++ b/frontend/src/components/sites/SiteFormDialog.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react' +import { useState } from 'react' import { useMutation, useQueryClient } from '@tanstack/react-query' import { sitesApi, type SiteResponse, type SiteCreate, type SiteUpdate } from '@/lib/api' import { @@ -24,31 +24,12 @@ export function SiteFormDialog({ open, onOpenChange, tenantId, site }: SiteFormD const queryClient = useQueryClient() const isEdit = !!site - const [name, setName] = useState('') - const [address, setAddress] = useState('') - const [latitude, setLatitude] = useState('') - const [longitude, setLongitude] = useState('') - const [elevation, setElevation] = useState('') - const [notes, setNotes] = useState('') - - // Populate form when editing or reset when dialog opens/closes - useEffect(() => { - if (site) { - setName(site.name) - setAddress(site.address ?? '') - setLatitude(site.latitude != null ? String(site.latitude) : '') - setLongitude(site.longitude != null ? String(site.longitude) : '') - setElevation(site.elevation != null ? String(site.elevation) : '') - setNotes(site.notes ?? '') - } else { - setName('') - setAddress('') - setLatitude('') - setLongitude('') - setElevation('') - setNotes('') - } - }, [site, open]) + const [name, setName] = useState(site?.name ?? '') + const [address, setAddress] = useState(site?.address ?? '') + const [latitude, setLatitude] = useState(site?.latitude != null ? String(site.latitude) : '') + const [longitude, setLongitude] = useState(site?.longitude != null ? String(site.longitude) : '') + const [elevation, setElevation] = useState(site?.elevation != null ? String(site.elevation) : '') + const [notes, setNotes] = useState(site?.notes ?? '') const createMutation = useMutation({ mutationFn: (data: SiteCreate) => sitesApi.create(tenantId, data), diff --git a/frontend/src/components/sites/SiteSectorView.tsx b/frontend/src/components/sites/SiteSectorView.tsx index acd15e4..0bacd73 100644 --- a/frontend/src/components/sites/SiteSectorView.tsx +++ b/frontend/src/components/sites/SiteSectorView.tsx @@ -249,6 +249,7 @@ export function SiteSectorView({ tenantId, siteId }: SiteSectorViewProps) { {/* Form dialog */} ).__tod_err_ctx = { ts: Date.now(), cid: 'f7e2a' } } } diff --git a/frontend/src/routes/_authenticated/tenants/$tenantId/sites/index.tsx b/frontend/src/routes/_authenticated/tenants/$tenantId/sites/index.tsx index cc658a5..a6cab2d 100644 --- a/frontend/src/routes/_authenticated/tenants/$tenantId/sites/index.tsx +++ b/frontend/src/routes/_authenticated/tenants/$tenantId/sites/index.tsx @@ -39,6 +39,7 @@ function SitesPage() { /> { if (!open) setEditSite(null)