From 4741e6bced836e87afd97958169b7fff4271207d Mon Sep 17 00:00:00 2001 From: Soumyadas15 Date: Sun, 1 Jun 2025 12:46:54 +0530 Subject: [PATCH] fix(ui): functional start chat button in agent dialog --- .../(dashboard)/agents/_components/agents-grid.tsx | 2 +- frontend/src/app/(dashboard)/dashboard/page.tsx | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/(dashboard)/agents/_components/agents-grid.tsx b/frontend/src/app/(dashboard)/agents/_components/agents-grid.tsx index 2eb61d57..b48709b2 100644 --- a/frontend/src/app/(dashboard)/agents/_components/agents-grid.tsx +++ b/frontend/src/app/(dashboard)/agents/_components/agents-grid.tsx @@ -185,7 +185,7 @@ export const AgentsGrid = ({ }; const handleChat = (agentId: string) => { - router.push(`/agents/new/${agentId}`); + router.push(`/dashboard?agent_id=${agentId}`); setSelectedAgent(null); }; diff --git a/frontend/src/app/(dashboard)/dashboard/page.tsx b/frontend/src/app/(dashboard)/dashboard/page.tsx index 19529abd..fff1574d 100644 --- a/frontend/src/app/(dashboard)/dashboard/page.tsx +++ b/frontend/src/app/(dashboard)/dashboard/page.tsx @@ -2,7 +2,7 @@ import React, { useState, Suspense, useEffect, useRef } from 'react'; import { Skeleton } from '@/components/ui/skeleton'; -import { useRouter } from 'next/navigation'; +import { useRouter, useSearchParams } from 'next/navigation'; import { Menu } from 'lucide-react'; import { ChatInput, @@ -40,6 +40,7 @@ function DashboardContent() { const { billingError, handleBillingError, clearBillingError } = useBillingError(); const router = useRouter(); + const searchParams = useSearchParams(); const isMobile = useIsMobile(); const { setOpenMobile } = useSidebar(); const { data: accounts } = useAccounts(); @@ -48,6 +49,16 @@ function DashboardContent() { const initiateAgentMutation = useInitiateAgentWithInvalidation(); const { onOpen } = useModal(); + useEffect(() => { + const agentIdFromUrl = searchParams.get('agent_id'); + if (agentIdFromUrl && agentIdFromUrl !== selectedAgentId) { + setSelectedAgentId(agentIdFromUrl); + const newUrl = new URL(window.location.href); + newUrl.searchParams.delete('agent_id'); + router.replace(newUrl.pathname + newUrl.search, { scroll: false }); + } + }, [searchParams, selectedAgentId, router]); + const secondaryGradient = 'bg-gradient-to-r from-blue-500 to-blue-500 bg-clip-text text-transparent';