fix(dashboard): auto-submit FlowPilot session when prefill from dashboard
When user types a problem on the dashboard and hits Enter, skip the intake form and start the session immediately — no double-enter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { useParams, useSearchParams, useLocation } from 'react-router-dom'
|
import { useParams, useSearchParams, useLocation } from 'react-router-dom'
|
||||||
import { Sparkles, Loader2 } from 'lucide-react'
|
import { Sparkles, Loader2 } from 'lucide-react'
|
||||||
import { useFlowPilotSession } from '@/hooks/useFlowPilotSession'
|
import { useFlowPilotSession } from '@/hooks/useFlowPilotSession'
|
||||||
@@ -13,6 +13,15 @@ export default function FlowPilotSessionPage() {
|
|||||||
const prefill = (location.state as { prefill?: string } | null)?.prefill || ''
|
const prefill = (location.state as { prefill?: string } | null)?.prefill || ''
|
||||||
const isPickup = searchParams.get('pickup') === 'true'
|
const isPickup = searchParams.get('pickup') === 'true'
|
||||||
const fp = useFlowPilotSession()
|
const fp = useFlowPilotSession()
|
||||||
|
const prefillHandledRef = useRef(false)
|
||||||
|
|
||||||
|
// Auto-submit when navigating from dashboard with prefilled problem
|
||||||
|
useEffect(() => {
|
||||||
|
if (prefill && !prefillHandledRef.current && !sessionId && !fp.session && !fp.isLoading) {
|
||||||
|
prefillHandledRef.current = true
|
||||||
|
fp.startSession({ intake_type: 'free_text', intake_content: { text: prefill } })
|
||||||
|
}
|
||||||
|
}, [prefill, sessionId, fp.session, fp.isLoading]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
const [pickingUp, setPickingUp] = useState(false)
|
const [pickingUp, setPickingUp] = useState(false)
|
||||||
|
|
||||||
// Load existing session if ID in URL
|
// Load existing session if ID in URL
|
||||||
|
|||||||
Reference in New Issue
Block a user