fix(frontend): resolve set-state-in-effect lint errors
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useRef } from 'react'
|
||||||
import { Modal } from '@/components/common/Modal'
|
import { Modal } from '@/components/common/Modal'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import type { SessionOutcome } from '@/types'
|
import type { SessionOutcome } from '@/types'
|
||||||
@@ -23,19 +23,17 @@ export function SessionOutcomeModal({
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
isSubmitting = false,
|
isSubmitting = false,
|
||||||
}: SessionOutcomeModalProps) {
|
}: SessionOutcomeModalProps) {
|
||||||
const [outcome, setOutcome] = useState<SessionOutcome>('resolved')
|
const formRef = useRef<HTMLFormElement | null>(null)
|
||||||
const [outcomeNotes, setOutcomeNotes] = useState('')
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isOpen) return
|
|
||||||
setOutcome('resolved')
|
|
||||||
setOutcomeNotes('')
|
|
||||||
}, [isOpen])
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
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({
|
await onSubmit({
|
||||||
outcome,
|
outcome,
|
||||||
outcome_notes: outcomeNotes.trim() || undefined,
|
outcome_notes: outcomeNotes || undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +69,7 @@ export function SessionOutcomeModal({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="space-y-4">
|
<form key={String(isOpen)} ref={formRef} className="space-y-4">
|
||||||
<p className="text-sm text-white/70">
|
<p className="text-sm text-white/70">
|
||||||
Select the session outcome before completion.
|
Select the session outcome before completion.
|
||||||
</p>
|
</p>
|
||||||
@@ -89,8 +87,7 @@ export function SessionOutcomeModal({
|
|||||||
type="radio"
|
type="radio"
|
||||||
name="session-outcome"
|
name="session-outcome"
|
||||||
value={option.value}
|
value={option.value}
|
||||||
checked={outcome === option.value}
|
defaultChecked={option.value === 'resolved'}
|
||||||
onChange={() => setOutcome(option.value)}
|
|
||||||
className="mt-1 h-4 w-4"
|
className="mt-1 h-4 w-4"
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
@@ -105,8 +102,8 @@ export function SessionOutcomeModal({
|
|||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-white">Outcome Notes (optional)</label>
|
<label className="block text-sm font-medium text-white">Outcome Notes (optional)</label>
|
||||||
<textarea
|
<textarea
|
||||||
value={outcomeNotes}
|
name="outcome-notes"
|
||||||
onChange={(e) => setOutcomeNotes(e.target.value)}
|
defaultValue=""
|
||||||
rows={3}
|
rows={3}
|
||||||
placeholder="Add context for this outcome..."
|
placeholder="Add context for this outcome..."
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -116,7 +113,7 @@ export function SessionOutcomeModal({
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ export function useSessionTimer(startedAt: string | undefined | null): string |
|
|||||||
intervalRef.current = null
|
intervalRef.current = null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!startedAt) {
|
if (!startedAt) return
|
||||||
setElapsed(null)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedStartTime = new Date(startedAt).getTime()
|
const parsedStartTime = new Date(startedAt).getTime()
|
||||||
// If the server timestamp is invalid or ahead of the local clock, fall back to "now"
|
// 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])
|
}, [startedAt])
|
||||||
|
|
||||||
return elapsed
|
return startedAt ? elapsed : null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user