From bbdff10c5980368014f29dd95bc95c27c47f6d2a Mon Sep 17 00:00:00 2001 From: Martin Schoeler <martin.schoeler@rocket.chat> Date: Fri, 16 Aug 2024 18:22:56 -0300 Subject: [PATCH] refactor(Livechat): transcript.js to TS (#32087) --- .../src/lib/{transcript.js => transcript.ts} | 21 ++++++++++++++----- packages/livechat/src/store/index.tsx | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) rename packages/livechat/src/lib/{transcript.js => transcript.ts} (68%) diff --git a/packages/livechat/src/lib/transcript.js b/packages/livechat/src/lib/transcript.ts similarity index 68% rename from packages/livechat/src/lib/transcript.js rename to packages/livechat/src/lib/transcript.ts index 970aab2ee9b..33260edd62e 100644 --- a/packages/livechat/src/lib/transcript.js +++ b/packages/livechat/src/lib/transcript.ts @@ -9,9 +9,19 @@ const promptTranscript = async () => { config: { messages: { transcriptMessage }, }, - user: { token, visitorEmails }, - room: { _id }, + user, + room, } = store.state; + + if (!room || !user) { + console.warn('Only call promptTranscript when there is a room and a user'); + return; + } + + const { visitorEmails } = user; + + const { _id } = room; + const email = visitorEmails && visitorEmails.length > 0 ? visitorEmails[0].address : ''; if (!email) { return; @@ -23,12 +33,12 @@ const promptTranscript = async () => { text: message, }).then((result) => { if (typeof result.success === 'boolean' && result.success) { - return Livechat.requestTranscript(email, { token, rid: _id }); + return Livechat.requestTranscript(email, { rid: _id }); } }); }; -const transcriptSentAlert = (message) => +const transcriptSentAlert = (message: string) => ModalManager.alert({ text: message, timeout: 1000, @@ -45,7 +55,8 @@ export const handleTranscript = async () => { const result = await promptTranscript(); - if (result && result.success) { + // TODO: Check why the api results are not returning the correct type + if ((result as { message: string; success: boolean })?.success) { transcriptSentAlert(i18next.t('transcript_success')); } }; diff --git a/packages/livechat/src/store/index.tsx b/packages/livechat/src/store/index.tsx index abc05f7101a..f8629ce693c 100644 --- a/packages/livechat/src/store/index.tsx +++ b/packages/livechat/src/store/index.tsx @@ -58,6 +58,7 @@ export type StoreState = { hiddenSystemMessages?: LivechatHiddenSytemMessageType[]; hideWatermark?: boolean; livechatLogo?: { url: string }; + transcript?: boolean; }; online?: boolean; departments: Department[]; -- GitLab