Skip to content

Commit

Permalink
refactor(Livechat): transcript.js to TS (#32087)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored Aug 16, 2024
1 parent 683b55b commit bbdff10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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'));
}
};
1 change: 1 addition & 0 deletions packages/livechat/src/store/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type StoreState = {
hiddenSystemMessages?: LivechatHiddenSytemMessageType[];
hideWatermark?: boolean;
livechatLogo?: { url: string };
transcript?: boolean;
};
online?: boolean;
departments: Department[];
Expand Down

0 comments on commit bbdff10

Please sign in to comment.