From ae43fdae602faef35a1ffa06c9b156bb6b7b194f Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Wed, 18 Nov 2026 14:22:49 +0300 Subject: [PATCH] Updated telephony page --- src/lib/telephony.ts | 16 ++++ src/pages/telephony/TelephonyPage.tsx | 8 ++ src/pages/telephony/components/Notes.tsx | 115 +++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 src/pages/telephony/components/Notes.tsx diff --git a/src/lib/telephony.ts b/src/lib/telephony.ts index 7af630e..05ac52f 100644 --- a/src/lib/telephony.ts +++ b/src/lib/telephony.ts @@ -19,6 +19,7 @@ export interface ReportRow { last_message?: string | null // SMS / чат manager: string manager_id?: number | null + notes_count?: number // число заметок, для индикатора в таблице status: string // «Отвечен», «Пропущен, перезвон не совершен», … } @@ -37,13 +38,28 @@ export interface ChatSummary { messages_count: number } +export interface Note { + id: number + text: string + author: string + created_at: string + can_delete: boolean // права решает сервер: автор или суперадмин +} + 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), + // Заметки общие: видны всем, у кого есть доступ к разделу. id — id строки отчёта + notes: (id: string) => + api.get<{ data: Note[] }>(`/telephony/report/${id}/notes`).then((r) => r.data.data), + addNote: (id: string, text: string) => api.post(`/telephony/report/${id}/notes`, { text }), + deleteNote: (id: string, noteId: number) => api.delete(`/telephony/report/${id}/notes/${noteId}`), + // Диалоги менеджера в одном канале 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), + // Переписка постранично: before — id самого раннего из уже загруженных сообщений 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) => diff --git a/src/pages/telephony/TelephonyPage.tsx b/src/pages/telephony/TelephonyPage.tsx index 07a6296..40bd11b 100644 --- a/src/pages/telephony/TelephonyPage.tsx +++ b/src/pages/telephony/TelephonyPage.tsx @@ -29,6 +29,7 @@ import type { ManagerSession } from '@/types/api' // Эти три компонента нужно вынести из старой MessengersPage в отдельные файлы без изменений import AddManagerModal from './components/AddManagerModal' import DeleteManagerModal from './components/DeleteManagersModal' +import { NoteButton, NotesPanel } from './components/Notes' import { ChatsDrawer, MessageThread } from './components/ChatsDrawer' import { AddWhatsappModal, EditManagerModal } from './components/ManagerModals' import classes from '@/components/UserDrawer.module.css' @@ -99,6 +100,12 @@ function ConversationDrawer({ row, onClose }: { row: ReportRow | null; onClose: + {row && ( + + Заметки + + + )} @@ -211,6 +218,7 @@ function ReportView({ onTotal }: { onTotal: (n: number | undefined) => void }) { width: 230, cell: (r) => {r.status}, }, + { key: 'notes', header: '', width: 56, cell: (r) => }, { key: 'action', header: '', diff --git a/src/pages/telephony/components/Notes.tsx b/src/pages/telephony/components/Notes.tsx new file mode 100644 index 0000000..e04dab6 --- /dev/null +++ b/src/pages/telephony/components/Notes.tsx @@ -0,0 +1,115 @@ +import { useState } from 'react' +import { ActionIcon, Button, Group, Indicator, Popover, Skeleton, Stack, Text, Textarea } from '@mantine/core' +import { notifications } from '@mantine/notifications' +import { IconNote, IconTrash } from '@tabler/icons-react' +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' +import { useAuth } from '@/hooks/useAuth' +import { telephonyApi } from '@/lib/telephony' +import { formatMsk } from '@/utils/date' + +/** Общие заметки к звонку, SMS или диалогу: видны всем, у кого есть доступ к разделу. */ +export function NotesPanel({ id }: { id: string }) { + const queryClient = useQueryClient() + const { user } = useAuth() + const canWrite = user?.is_observer !== true + const [text, setText] = useState('') + + const { data: notes, isLoading } = useQuery({ + queryKey: ['telephony-notes', id], + queryFn: () => telephonyApi.notes(id), + }) + + // Обновляем и список заметок, и счётчик в таблице отчёта + const refresh = () => { + queryClient.invalidateQueries({ queryKey: ['telephony-notes', id] }) + queryClient.invalidateQueries({ queryKey: ['telephony-report'] }) + } + const onError = () => notifications.show({ title: 'Ошибка', message: 'Не удалось сохранить заметку', color: 'red' }) + + const add = useMutation({ + mutationFn: () => telephonyApi.addNote(id, text.trim()), + onSuccess: () => { setText(''); refresh() }, + onError, + }) + const remove = useMutation({ + mutationFn: (noteId: number) => telephonyApi.deleteNote(id, noteId), + onSuccess: refresh, + onError, + }) + + const submit = () => { if (text.trim() && !add.isPending) add.mutate() } + + return ( + + {isLoading ? ( + + ) : !notes?.length ? ( + Заметок пока нет + ) : ( + notes.map((n) => ( + + + + {n.author} + {formatMsk(n.created_at)} + + {n.can_delete && ( + remove.mutate(n.id)} + > + + + )} + + {n.text} + + )) + )} + + {canWrite && ( + +