From d986ede817f52b3e9a186ca28465dae301baba97 Mon Sep 17 00:00:00 2001 From: tonyco97 Date: Wed, 4 Dec 2024 16:26:52 +0100 Subject: [PATCH] fix: Added missing action for recording inside history --- lib/history.ts | 32 ++++++++++ pages/history.tsx | 93 +++++++++++++++++++++++++----- public/locales/en/translation.json | 3 +- public/locales/it/translation.json | 3 +- 4 files changed, 115 insertions(+), 16 deletions(-) diff --git a/lib/history.ts b/lib/history.ts index 15683733..1f00df14 100644 --- a/lib/history.ts +++ b/lib/history.ts @@ -238,6 +238,38 @@ export const getLastCalls = async ( } } +export const downloadCallRec = async (idRecording: string) => { + try { + const requestUrl = `${getHistoryUrl()}/webrest/historycall/down_callrec/${idRecording}` + const { data, status } = await axios.get(requestUrl) + + if (status === 200) { + return data + } else { + throw 'Error retrieving recording' + } + } catch (error) { + handleNetworkError(error) + throw error + } +} + +export const deleteRec = async (idRecording: string) => { + try { + const requestUrl = `${getHistoryUrl()}/webrest/historycall/delete_callrec` + const { data, status } = await axios.post(requestUrl, { id: idRecording }) + + if (status === 200) { + return data + } else { + throw 'Error removing recording' + } + } catch (error) { + handleNetworkError(error) + throw error + } +} + export interface CallTypes { time: number channel: string diff --git a/pages/history.tsx b/pages/history.tsx index 767653fc..19ea35d7 100644 --- a/pages/history.tsx +++ b/pages/history.tsx @@ -3,9 +3,9 @@ import type { NextPage } from 'next' import { Filter } from '../components/history/Filter' -import { Button, EmptyState, InlineNotification } from '../components/common' +import { Button, Dropdown, EmptyState, InlineNotification } from '../components/common' import { useState, useEffect, useMemo } from 'react' -import { search, PAGE_SIZE, openDrawerHistory } from '../lib/history' +import { search, PAGE_SIZE, openDrawerHistory, downloadCallRec, deleteRec } from '../lib/history' import { RootState } from '../store' import { useSelector } from 'react-redux' import { debounce } from 'lodash' @@ -22,11 +22,15 @@ import { faVoicemail, faPhone, faArrowUpRightFromSquare, + faEllipsisVertical, + faFileImport, + faTrash, + faDownload, } from '@fortawesome/free-solid-svg-icons' import { formatDateLoc } from '../lib/dateTime' import { subDays, startOfDay } from 'date-fns' import { useTranslation } from 'react-i18next' -import { getApiScheme, getApiVoiceEndpoint, playFileAudio } from '../lib/utils' +import { getApiEndpoint, getApiScheme, getApiVoiceEndpoint, playFileAudio } from '../lib/utils' import { Tooltip } from 'react-tooltip' import { CallsDate } from '../components/history/CallsDate' import { MissingPermission } from '../components/common/MissingPermissionsPage' @@ -567,8 +571,53 @@ const History: NextPage = () => { const apiVoiceEnpoint = getApiVoiceEndpoint() const apiScheme = getApiScheme() + const apiEndpoint = getApiEndpoint() //report page link const pbxReportUrl = apiScheme + apiVoiceEnpoint + '/pbx-report/' + // URL for the recording file + const recordingUrlPath = apiScheme + apiEndpoint + '/webrest/static/' + + // Dropdown actions for the recording file + const getRecordingActions = (callId: string) => ( + <> + downloadRecordingFileAudio(callId)}> + {t('Common.Download')} + + deleteRecordingAudioFile(callId)}> + {t('Common.Delete')} + + + ) + + const downloadRecordingFileAudio = async (callIdInformation: any) => { + if (callIdInformation !== '') { + try { + let fileName = await downloadCallRec(callIdInformation) + + // Get the file URL + const fileUrl = `${recordingUrlPath + fileName}` + + const link = document.createElement('a') + link.href = fileUrl + link.download = fileName + link.click() + } catch (err) { + console.log(err) + } + } + } + + const deleteRecordingAudioFile = async (callIdInformation: string) => { + if (callIdInformation !== '') { + try { + await deleteRec(callIdInformation) + // reload the history + setHistoryLoaded(false) + } catch (err) { + console.log(err) + } + } + } return ( <> @@ -773,17 +822,33 @@ const History: NextPage = () => { {call?.recordingfile ? ( - +
+ + + + +
) : (
- diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 88dce910..ebc68b11 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -176,7 +176,8 @@ "Choose a date range": "Choose a date range", "Call in Voicemail": "Call in Voicemail", "Type to search contact": "Type to search contact", - "Groups": "Groups" + "Groups": "Groups", + "Open recording action modal": "Open recording action modal" }, "Operators": { "Operators": "Operators", diff --git a/public/locales/it/translation.json b/public/locales/it/translation.json index 7bd54a3c..9d87ac5b 100644 --- a/public/locales/it/translation.json +++ b/public/locales/it/translation.json @@ -155,7 +155,8 @@ "Start time": "Tempo di inizio", "End time": "Tempo di fine", "Choose a date range": "Scegli un intervallo", - "Groups": "Gruppi" + "Groups": "Gruppi", + "Open recording action modal": "Apri modale azioni registrazione" }, "Operators": { "Operators": "Operatori",