fix(frontend): resolve set-state-in-effect lint errors

This commit is contained in:
Michael Chihlas
2026-02-11 19:09:29 -05:00
parent ca4ce7cad6
commit 06c66f5595
2 changed files with 15 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react'
import { useRef } from 'react'
import { Modal } from '@/components/common/Modal'
import { cn } from '@/lib/utils'
import type { SessionOutcome } from '@/types'
@@ -23,19 +23,17 @@ export function SessionOutcomeModal({
onSubmit,
isSubmitting = false,
}: SessionOutcomeModalProps) {
const [outcome, setOutcome] = useState<SessionOutcome>('resolved')
const [outcomeNotes, setOutcomeNotes] = useState('')
useEffect(() => {
if (!isOpen) return
setOutcome('resolved')
setOutcomeNotes('')
}, [isOpen])
const formRef = useRef<HTMLFormElement | null>(null)
const handleSubmit = async () => {
if (!formRef.current) return
const formData = new FormData(formRef.current)
const outcome = (formData.get('session-outcome') as SessionOutcome | null) ?? 'resolved'
const outcomeNotes = ((formData.get('outcome-notes') as string | null) ?? '').trim()
await onSubmit({
outcome,
outcome_notes: outcomeNotes.trim() || undefined,
outcome_notes: outcomeNotes || undefined,
})
}
@@ -71,7 +69,7 @@ export function SessionOutcomeModal({
</div>
)}
>
<div className="space-y-4">
<form key={String(isOpen)} ref={formRef} className="space-y-4">
<p className="text-sm text-white/70">
Select the session outcome before completion.
</p>
@@ -89,8 +87,7 @@ export function SessionOutcomeModal({
type="radio"
name="session-outcome"
value={option.value}
checked={outcome === option.value}
onChange={() => setOutcome(option.value)}
defaultChecked={option.value === 'resolved'}
className="mt-1 h-4 w-4"
/>
<div>
@@ -105,8 +102,8 @@ export function SessionOutcomeModal({
<div>
<label className="block text-sm font-medium text-white">Outcome Notes (optional)</label>
<textarea
value={outcomeNotes}
onChange={(e) => setOutcomeNotes(e.target.value)}
name="outcome-notes"
defaultValue=""
rows={3}
placeholder="Add context for this outcome..."
className={cn(
@@ -116,7 +113,7 @@ export function SessionOutcomeModal({
)}
/>
</div>
</div>
</form>
</Modal>
)
}

View File

@@ -11,10 +11,7 @@ export function useSessionTimer(startedAt: string | undefined | null): string |
intervalRef.current = null
}
if (!startedAt) {
setElapsed(null)
return
}
if (!startedAt) return
const parsedStartTime = new Date(startedAt).getTime()
// If the server timestamp is invalid or ahead of the local clock, fall back to "now"
@@ -40,5 +37,5 @@ export function useSessionTimer(startedAt: string | undefined | null): string |
}
}, [startedAt])
return elapsed
return startedAt ? elapsed : null
}