fix(lint): resolve ESLint errors in form dialogs and error boundary
- Replace useEffect setState pattern with initial state from props + key-based remount in SiteFormDialog and SectorFormDialog - Fix explicit-any violation in error boundary context assignment Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -249,6 +249,7 @@ export function SiteSectorView({ tenantId, siteId }: SiteSectorViewProps) {
|
||||
|
||||
{/* Form dialog */}
|
||||
<SectorFormDialog
|
||||
key={editSector?.id ?? 'new'}
|
||||
open={formOpen}
|
||||
onOpenChange={setFormOpen}
|
||||
tenantId={tenantId}
|
||||
|
||||
@@ -27,7 +27,7 @@ export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundarySt
|
||||
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||
console.error('[ErrorBoundary] Caught error:', error, errorInfo)
|
||||
if (typeof window !== 'undefined') {
|
||||
(window as any).__tod_err_ctx = { ts: Date.now(), cid: 'f7e2a' }
|
||||
(window as unknown as Record<string, unknown>).__tod_err_ctx = { ts: Date.now(), cid: 'f7e2a' }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ function SitesPage() {
|
||||
/>
|
||||
<SiteFormDialog open={createOpen} onOpenChange={setCreateOpen} tenantId={tenantId} />
|
||||
<SiteFormDialog
|
||||
key={editSite?.id ?? 'new'}
|
||||
open={!!editSite}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setEditSite(null)
|
||||
|
||||
Reference in New Issue
Block a user