-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #434 from Cognigy/feature/63342-queue-updates-ui
Queue Updates - v3
- Loading branch information
Showing
16 changed files
with
353 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference | ||
/// <reference path="../support/index.d.ts" /> | ||
|
||
const getDummyEvent = payload => ({ | ||
data: { | ||
_cognigy: { | ||
_webchat3: { | ||
type: "queueUpdate", | ||
payload, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
describe("Queue Updates", () => { | ||
beforeEach(() => { | ||
cy.visitWebchat().initMockWebchat().openWebchat().startConversation(); | ||
}); | ||
|
||
it("should render queue updates Alternative Text", () => { | ||
cy.receiveMessage( | ||
"", | ||
getDummyEvent({ | ||
alternativeText: "Alternative Text", | ||
}), | ||
); | ||
|
||
cy.get(".webchat-queue-updates").should("be.visible"); | ||
cy.get(".webchat-queue-updates").contains("Alternative Text"); | ||
}); | ||
|
||
it("should render queue updates Position and Wait Time", () => { | ||
cy.receiveMessage( | ||
"", | ||
getDummyEvent({ | ||
position: 3, | ||
estimatedWaitTime: 600000, | ||
}), | ||
); | ||
|
||
cy.get(".webchat-queue-updates").should("be.visible"); | ||
cy.get(".webchat-queue-updates").contains("10 minutes"); | ||
}); | ||
|
||
it("should render LiveAgent Join event and play bell sound", () => { | ||
cy.receiveMessage( | ||
"", | ||
getDummyEvent({ | ||
position: 3, | ||
estimatedWaitTime: 600000, | ||
}), | ||
); | ||
|
||
cy.get(".webchat-queue-updates").should("be.visible"); | ||
|
||
cy.receiveMessage( | ||
"Hello!", | ||
{ | ||
_cognigy: { | ||
_webchat: { | ||
message: { | ||
text: "Hello!", | ||
}, | ||
}, | ||
}, | ||
}, | ||
"agent", | ||
); | ||
|
||
// Render ChatEvent chip | ||
cy.get(".webchat-message-row").should("be.visible"); | ||
cy.get(".webchat-message-row").contains("Agent joined"); | ||
|
||
// Play bell sound | ||
cy.get("audio").should(els => { | ||
let audible = false; | ||
els.each((_, el) => { | ||
// console.log(el) | ||
if (el.duration > 0 && el.id === "uifx-813465923") { | ||
audible = true; | ||
} | ||
}); | ||
expect(audible).to.eq(true); | ||
}); | ||
|
||
// Render agent message | ||
cy.get(".webchat-message-row.agent").contains("Hello!"); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { TWebchat3Event } from "@cognigy/socket-client"; | ||
|
||
export interface IMessageEvent { | ||
text?: string; | ||
source?: string; | ||
timestamp?: number; | ||
data: { | ||
_cognigy: { | ||
_webchat3: TWebchat3Event; | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { FC, useEffect } from "react"; | ||
import styled from "@emotion/styled"; | ||
import { Typography } from "@cognigy/chat-components"; | ||
import { useSelector } from "../../../webchat/helper/useSelector"; | ||
import { formatWaitTime } from "../../utils/formatWaitTime"; | ||
|
||
const QueueUpdatesWrapper = styled(Typography)(({ theme }) => ({ | ||
marginBottom: "var(--webchat-message-margin-block, 24px)", | ||
marginInline: "var(--webchat-message-margin-inline, 20px)", | ||
padding: "12px", | ||
textAlign: "center", | ||
color: theme.black40, | ||
"& span": { | ||
display: "block", | ||
}, | ||
})); | ||
|
||
interface IQueueUpdatesProps { | ||
handleScroll?: (position?: number, instant?: boolean) => void; | ||
} | ||
|
||
const QueueUpdates: FC<IQueueUpdatesProps> = props => { | ||
const queueUpdates = useSelector(state => state.queueUpdates ?? {}); | ||
const { handleScroll } = props; | ||
|
||
useEffect(() => { | ||
if (queueUpdates?.isQueueActive) { | ||
handleScroll?.(undefined, true); | ||
} | ||
}, [queueUpdates?.isQueueActive]); | ||
|
||
if (!queueUpdates?.isQueueActive) return null; | ||
|
||
return ( | ||
<QueueUpdatesWrapper | ||
variant="body-regular" | ||
id="webchatQueueUpdates" | ||
className="webchat-queue-updates" | ||
component="div" | ||
> | ||
{queueUpdates?.alternativeText ? ( | ||
<span>{queueUpdates.alternativeText}</span> | ||
) : ( | ||
<> | ||
<span> | ||
Current queue position: <strong>{queueUpdates?.position || ""}</strong> | ||
</span> | ||
<span> | ||
Estimated waiting time:{" "} | ||
<strong>{formatWaitTime(queueUpdates?.estimatedWaitTime)}</strong> | ||
</span> | ||
</> | ||
)} | ||
</QueueUpdatesWrapper> | ||
); | ||
}; | ||
|
||
export default QueueUpdates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Message notification imports | ||
import UIfx from 'uifx'; | ||
|
||
const fileUrl = require('../assets/bell-sound.mp3').default as string; | ||
const bellSound = new UIfx(fileUrl); | ||
|
||
export default bellSound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// used on Queue Updates | ||
export const formatWaitTime = (ms: number | null) => { | ||
if (!ms) return ""; | ||
const seconds = ms / 1000; | ||
|
||
const getMinutes = (minutes: number) => { | ||
return `${minutes} ${minutes > 1 ? "minutes" : "minute"}`; | ||
}; | ||
|
||
if (seconds < 60) { | ||
return `${seconds} seconds`; | ||
} | ||
const minutes = Math.floor(seconds / 60); | ||
if (minutes < 60) { | ||
return getMinutes(minutes); | ||
} | ||
|
||
const hours = Math.floor(seconds / 3600); | ||
const restMinutes = minutes - hours * 60; | ||
|
||
return `${hours} ${hours > 1 ? "hours" : "hour"}${ | ||
restMinutes > 0 ? ` and ${getMinutes(restMinutes)}` : "" | ||
}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.