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) => ( - + ))}
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 ( <>
- +
);