diff --git a/src/lib/telephony.ts b/src/lib/telephony.ts
index de0eb92..7af630e 100644
--- a/src/lib/telephony.ts
+++ b/src/lib/telephony.ts
@@ -28,13 +28,24 @@ export interface ReportParams {
status?: string; content?: string; date_from?: string; date_to?: string
}
+export interface ChatSummary {
+ id: string
+ contact_name?: string | null
+ phone: string
+ last_message?: string | null
+ last_at?: string | null
+ messages_count: number
+}
+
export interface ChatMessage { id: string; direction: 'in' | 'out'; text: string; at: string; author?: string }
export const telephonyApi = {
list: (params: ReportParams) =>
api.get<{ data: ReportRow[]; total_count: number }>('/telephony/report', { params }).then((r) => r.data),
- messages: (id: string) =>
- api.get<{ data: ChatMessage[] }>(`/telephony/report/${id}/messages`).then((r) => r.data.data),
+ chats: (p: { channel: Channel; manager_id: string | number; search?: string; limit?: number }) =>
+ api.get<{ data: ChatSummary[]; total_count: number }>('/telephony/chats', { params: p }).then((r) => r.data),
+ thread: (chatId: string, p: { before?: string; limit?: number }) =>
+ api.get<{ data: ChatMessage[]; has_more: boolean }>(`/telephony/chats/${chatId}/messages`, { params: p }).then((r) => r.data),
download: (params: ReportParams) =>
api.get('/telephony/report/xlsx', { params, responseType: 'blob' }).then((r) => r.data as BlobPart),
}
\ No newline at end of file
diff --git a/src/pages/telephony/TelephonyPage.tsx b/src/pages/telephony/TelephonyPage.tsx
index 4c31ade..07a6296 100644
--- a/src/pages/telephony/TelephonyPage.tsx
+++ b/src/pages/telephony/TelephonyPage.tsx
@@ -1,13 +1,13 @@
import { useEffect, useMemo, useState } from 'react'
import {
- ActionIcon, Avatar, Badge, Box, Button, Drawer, Group, Menu, Popover, Select, Skeleton, Stack, Tabs, Text,
+ ActionIcon, Avatar, Badge, Box, Button, Drawer, Group, Menu, Popover, Select, Stack, Tabs, Text,
TextInput, ThemeIcon,
} from '@mantine/core'
import { DatePickerInput } from '@mantine/dates'
import { useDebouncedValue } from '@mantine/hooks'
import { notifications } from '@mantine/notifications'
import {
- IconBrandTelegram, IconBrandWhatsapp, IconCalendar, IconDots, IconEdit, IconMessage, IconMessageCircle,
+ IconBrandTelegram, IconBrandWhatsapp, IconCalendar, IconDots, IconEdit, IconMessage, IconMessage2, IconMessageCircle,
IconPhone, IconPhoneIncoming, IconPhoneOutgoing, IconPlayerPlay, IconPlus, IconSearch, IconTrash,
type Icon,
} from '@tabler/icons-react'
@@ -19,7 +19,7 @@ import { PageHeader } from '@/components/ui/PageHeader'
import { FilterBar } from '@/components/ui/FilterBar'
import { DataTable, type Column } from '@/components/ui/DataTable'
import { ReportPopover, type DateRange } from '@/components/ui/ReportPopover'
-import { telephonyApi, type Channel, type ChatMessage, type ReportParams, type ReportRow } from '@/lib/telephony'
+import { telephonyApi, type Channel, type ReportParams, type ReportRow } from '@/lib/telephony'
import { formatMsk } from '@/utils/date'
import { useDeleteTelegramManager, useTelegramManagers } from '@/features/telegramManagers/useTelegramManagers'
import { useDeleteWhatsAppManager, useWhatsAppManagers } from '@/features/whatsappManagers/useWhatsappManagers'
@@ -29,6 +29,7 @@ import type { ManagerSession } from '@/types/api'
// Эти три компонента нужно вынести из старой MessengersPage в отдельные файлы без изменений
import AddManagerModal from './components/AddManagerModal'
import DeleteManagerModal from './components/DeleteManagersModal'
+import { ChatsDrawer, MessageThread } from './components/ChatsDrawer'
import { AddWhatsappModal, EditManagerModal } from './components/ManagerModals'
import classes from '@/components/UserDrawer.module.css'
@@ -81,11 +82,6 @@ function PlayButton({ url }: { url: string }) {
}
function ConversationDrawer({ row, onClose }: { row: ReportRow | null; onClose: () => void }) {
- const { data, isLoading } = useQuery({
- queryKey: ['telephony-messages', row?.id],
- queryFn: () => telephonyApi.messages(row!.id),
- enabled: !!row,
- })
const title = row?.contact_name && row.contact_name !== 'Неизвестно' ? row.contact_name : `+${row?.phone}`
return (
@@ -103,32 +99,7 @@ function ConversationDrawer({ row, onClose }: { row: ReportRow | null; onClose:
-
- {isLoading ? (
- <>>
- ) : !data?.length ? (
- Сообщений нет
- ) : (
- data.map((m: ChatMessage) => (
-
- {m.text}
- {formatMsk(m.at)}
-
- ))
- )}
-
+
@@ -309,6 +280,7 @@ function ManagersView({ onOnline }: { onOnline: (s: string | undefined) => void
const [adding, setAdding] = useState