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 { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
import { sectorsApi, type SectorResponse, type SectorCreate, type SectorUpdate } from '@/lib/api'
|
import { sectorsApi, type SectorResponse, type SectorCreate, type SectorUpdate } from '@/lib/api'
|
||||||
import {
|
import {
|
||||||
@@ -25,21 +25,9 @@ export function SectorFormDialog({ open, onOpenChange, tenantId, siteId, sector
|
|||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const isEdit = !!sector
|
const isEdit = !!sector
|
||||||
|
|
||||||
const [name, setName] = useState('')
|
const [name, setName] = useState(sector?.name ?? '')
|
||||||
const [azimuth, setAzimuth] = useState('')
|
const [azimuth, setAzimuth] = useState(sector?.azimuth != null ? String(sector.azimuth) : '')
|
||||||
const [description, setDescription] = useState('')
|
const [description, setDescription] = useState(sector?.description ?? '')
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (sector) {
|
|
||||||
setName(sector.name)
|
|
||||||
setAzimuth(sector.azimuth != null ? String(sector.azimuth) : '')
|
|
||||||
setDescription(sector.description ?? '')
|
|
||||||
} else {
|
|
||||||
setName('')
|
|
||||||
setAzimuth('')
|
|
||||||
setDescription('')
|
|
||||||
}
|
|
||||||
}, [sector, open])
|
|
||||||
|
|
||||||
const createMutation = useMutation({
|
const createMutation = useMutation({
|
||||||
mutationFn: (data: SectorCreate) => sectorsApi.create(tenantId, siteId, data),
|
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 { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
import { sitesApi, type SiteResponse, type SiteCreate, type SiteUpdate } from '@/lib/api'
|
import { sitesApi, type SiteResponse, type SiteCreate, type SiteUpdate } from '@/lib/api'
|
||||||
import {
|
import {
|
||||||
@@ -24,31 +24,12 @@ export function SiteFormDialog({ open, onOpenChange, tenantId, site }: SiteFormD
|
|||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const isEdit = !!site
|
const isEdit = !!site
|
||||||
|
|
||||||
const [name, setName] = useState('')
|
const [name, setName] = useState(site?.name ?? '')
|
||||||
const [address, setAddress] = useState('')
|
const [address, setAddress] = useState(site?.address ?? '')
|
||||||
const [latitude, setLatitude] = useState('')
|
const [latitude, setLatitude] = useState(site?.latitude != null ? String(site.latitude) : '')
|
||||||
const [longitude, setLongitude] = useState('')
|
const [longitude, setLongitude] = useState(site?.longitude != null ? String(site.longitude) : '')
|
||||||
const [elevation, setElevation] = useState('')
|
const [elevation, setElevation] = useState(site?.elevation != null ? String(site.elevation) : '')
|
||||||
const [notes, setNotes] = useState('')
|
const [notes, setNotes] = useState(site?.notes ?? '')
|
||||||
|
|
||||||
// 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 createMutation = useMutation({
|
const createMutation = useMutation({
|
||||||
mutationFn: (data: SiteCreate) => sitesApi.create(tenantId, data),
|
mutationFn: (data: SiteCreate) => sitesApi.create(tenantId, data),
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ export function SiteSectorView({ tenantId, siteId }: SiteSectorViewProps) {
|
|||||||
|
|
||||||
{/* Form dialog */}
|
{/* Form dialog */}
|
||||||
<SectorFormDialog
|
<SectorFormDialog
|
||||||
|
key={editSector?.id ?? 'new'}
|
||||||
open={formOpen}
|
open={formOpen}
|
||||||
onOpenChange={setFormOpen}
|
onOpenChange={setFormOpen}
|
||||||
tenantId={tenantId}
|
tenantId={tenantId}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundarySt
|
|||||||
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||||
console.error('[ErrorBoundary] Caught error:', error, errorInfo)
|
console.error('[ErrorBoundary] Caught error:', error, errorInfo)
|
||||||
if (typeof window !== 'undefined') {
|
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 open={createOpen} onOpenChange={setCreateOpen} tenantId={tenantId} />
|
||||||
<SiteFormDialog
|
<SiteFormDialog
|
||||||
|
key={editSite?.id ?? 'new'}
|
||||||
open={!!editSite}
|
open={!!editSite}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) setEditSite(null)
|
if (!open) setEditSite(null)
|
||||||
|
|||||||
Reference in New Issue
Block a user