-
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.
implement and style QueueUpdates component
- Loading branch information
Fabio Colajanni
committed
Jul 1, 2024
1 parent
156111b
commit 40d9129
Showing
4 changed files
with
79 additions
and
3 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
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,50 @@ | ||
import React, { FC } 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 StyledQueueUpdates = styled.div(() => ({ | ||
marginBottom: "var(--webchat-message-margin-block, 24px)", | ||
marginInline: "var(--webchat-message-margin-inline, 20px)", | ||
padding: "12px", | ||
textAlign: "center", | ||
color: "var(--cc-black-40, #666)", | ||
lineHeight: "140%", | ||
"& span": { | ||
display: "block", | ||
}, | ||
})); | ||
|
||
const QueueUpdates: FC = () => { | ||
const queueUpdates = useSelector(state => state.queueUpdates ?? {}); | ||
|
||
if (!queueUpdates || !queueUpdates?.isQueueActive) return null; | ||
|
||
return ( | ||
<StyledQueueUpdates> | ||
<Typography | ||
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> | ||
</> | ||
)} | ||
</Typography> | ||
</StyledQueueUpdates> | ||
); | ||
}; | ||
|
||
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,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