/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/chat/components/SessionList.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 13, 2025 │ │ Contact: contato@evolution-api.com │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @copyright © Evolution API 2025. All rights reserved. │ │ Licensed under the Apache License, Version 2.0 │ │ │ │ You may not use this file except in compliance with the License. │ │ You may obtain a copy of the License at │ │ │ │ http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ Unless required by applicable law or agreed to in writing, software │ │ distributed under the License is distributed on an "AS IS" BASIS, │ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @important │ │ For any future changes to the code in this file, it is recommended to │ │ include, together with the modification, the information of the developer │ │ who changed it and the date of modification. │ └──────────────────────────────────────────────────────────────────────────────┘ */ "use client"; import { Input } from "@/components/ui/input"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Search, Filter, Plus, Loader2 } from "lucide-react"; import { ChatSession } from "@/services/sessionService"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; interface SessionListProps { sessions: ChatSession[]; agents: any[]; selectedSession: string | null; isLoading: boolean; searchTerm: string; selectedAgentFilter: string; showAgentFilter: boolean; setSearchTerm: (value: string) => void; setSelectedAgentFilter: (value: string) => void; setShowAgentFilter: (value: boolean) => void; setSelectedSession: (value: string | null) => void; setIsNewChatDialogOpen: (value: boolean) => void; } export function SessionList({ sessions, agents, selectedSession, isLoading, searchTerm, selectedAgentFilter, showAgentFilter, setSearchTerm, setSelectedAgentFilter, setShowAgentFilter, setSelectedSession, setIsNewChatDialogOpen, }: SessionListProps) { const filteredSessions = sessions.filter((session) => { const matchesSearchTerm = session.id .toLowerCase() .includes(searchTerm.toLowerCase()); if (selectedAgentFilter === "all") { return matchesSearchTerm; } const sessionAgentId = session.id.split("_")[1]; return matchesSearchTerm && sessionAgentId === selectedAgentFilter; }); const sortedSessions = [...filteredSessions].sort((a, b) => { const updateTimeA = new Date(a.update_time).getTime(); const updateTimeB = new Date(b.update_time).getTime(); return updateTimeB - updateTimeA; }); const formatDateTime = (dateTimeStr: string) => { try { const date = new Date(dateTimeStr); const day = date.getDate().toString().padStart(2, "0"); const month = (date.getMonth() + 1).toString().padStart(2, "0"); const year = date.getFullYear(); const hours = date.getHours().toString().padStart(2, "0"); const minutes = date.getMinutes().toString().padStart(2, "0"); return `${day}/${month}/${year} ${hours}:${minutes}`; } catch (error) { return "Invalid date"; } }; const getExternalId = (sessionId: string) => { return sessionId.split("_")[0]; }; return (