From 260a100619456c9c91f6d34c98e0ea3de4b39131 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Fri, 8 Nov 2024 17:08:08 +0500 Subject: [PATCH 1/2] remove agent from agents list after succesful deletion --- apps/chat/components/agents/list/AgentList.tsx | 5 +++-- apps/chat/components/agents/list/AgentRow.tsx | 4 +++- apps/chat/components/agents/list/index.tsx | 12 ++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/chat/components/agents/list/AgentList.tsx b/apps/chat/components/agents/list/AgentList.tsx index f3d3dc92a..caccffddd 100644 --- a/apps/chat/components/agents/list/AgentList.tsx +++ b/apps/chat/components/agents/list/AgentList.tsx @@ -7,9 +7,10 @@ export interface AgentListProps { loading: boolean range: number user: any + onAgentDelete: (agentId: number) => void } -export function AgentList({ agents, loading, range, user }: AgentListProps) { +export function AgentList({ agents, loading, range, user, onAgentDelete }: AgentListProps) { if (loading) return ( <> @@ -20,5 +21,5 @@ export function AgentList({ agents, loading, range, user }: AgentListProps) { ); if (!agents.length) return 'No agents found.'; - return agents.map((agent: any, index: number) => ); + return agents.map((agent: any, index: number) => ); } diff --git a/apps/chat/components/agents/list/AgentRow.tsx b/apps/chat/components/agents/list/AgentRow.tsx index af3a54b06..e959e7fe0 100644 --- a/apps/chat/components/agents/list/AgentRow.tsx +++ b/apps/chat/components/agents/list/AgentRow.tsx @@ -12,9 +12,10 @@ export interface AgentListProps { agent: any user: any author: string + onDelete: (agentId: number) => void; } -export function AgentRow({ agent, user, author }: AgentListProps) { +export function AgentRow({ agent, user, author, onDelete }: AgentListProps) { const [open, setOpen] = useState(false); const updateOpenState = () => { @@ -43,6 +44,7 @@ export function AgentRow({ agent, user, author }: AgentListProps) { const handleDelete = async () => { updateOpenState(); await deleteAgent(); + onDelete(agent.id); }; const handleDeleteClick = () => { diff --git a/apps/chat/components/agents/list/index.tsx b/apps/chat/components/agents/list/index.tsx index 065eec97d..25e34d526 100644 --- a/apps/chat/components/agents/list/index.tsx +++ b/apps/chat/components/agents/list/index.tsx @@ -105,6 +105,10 @@ export function Agents({ loadmore = false, search = true, range = 5, row = false fetchData(false, newRangeFrom, newRangeTo); }; + const handleAgentDelete = (deletedAgentId: number) => { + setAgents(agents => agents.filter(agent => agent.id !== deletedAgentId)); + }; + return ( <> {search && ( @@ -127,7 +131,7 @@ export function Agents({ loadmore = false, search = true, range = 5, row = false )}
- +
{loadmore && (
@@ -150,10 +154,14 @@ export function UserAgents({ agents = [], user, range = 5, row = false }: UserAg const [loading, setLoading] = useState(false); const [searchTerm, setSearchTerm] = useState(''); + const handleUserAgentDelete = (deletedAgentId: number) => { + setUserAgents(userAgents => userAgents.filter(agent => agent.id !== deletedAgentId)); + }; + return ( <>
- +
); From ae6d09c22bcfebe6864e6ec62e01ad94da4e6b2e Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Fri, 8 Nov 2024 20:40:36 +0500 Subject: [PATCH 2/2] update accounts profile page to include agent delete from accounts.agent array --- apps/chat/components/accounts/profile/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/chat/components/accounts/profile/index.tsx b/apps/chat/components/accounts/profile/index.tsx index c5608e670..206e23305 100644 --- a/apps/chat/components/accounts/profile/index.tsx +++ b/apps/chat/components/accounts/profile/index.tsx @@ -9,7 +9,7 @@ interface AgentImage { } interface Agent { - id: string; + id: number; name: string; images: AgentImage[]; } @@ -31,6 +31,10 @@ export function AccountProfile({ account }: AccountProps) { const agentUrl = `${origin}/accounts/${account.id}`; const randomAgentImage = account.agents[Math.floor(Math.random() * account.agents.length)]?.images[0].url; + const onDelete = (agentId: number) => { + account.agents = account.agents.filter((agent) => agent.id !== agentId); + }; + return (
@@ -63,7 +67,7 @@ export function AccountProfile({ account }: AccountProps) {
{account.agents.map((agent) => ( - + ))}