Skip to content

Commit 57d7776

Browse files
committed
feat: refine handoff information banner
1 parent 3de0827 commit 57d7776

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

packages/botonic-react/src/webchat/chat-area/index.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useContext, useEffect, useState } from 'react'
22

33
import { BotonicContainerId } from '../constants'
44
import { WebchatContext } from '../context'
5-
import { HandoffInformationBanner } from '../handoff'
65
import { useWebchatDimensions } from '../hooks'
76
import { WebchatMessageList } from '../message-list'
87
import { WebchatReplies } from '../replies'
@@ -25,9 +24,6 @@ export const ChatArea = () => {
2524
height={chatAreaHeight}
2625
>
2726
<WebchatMessageList />
28-
{webchatState.isWebchatOpen && webchatState.handoffState.isHandoff && (
29-
<HandoffInformationBanner />
30-
)}
3127
{webchatState.replies && webchatState.replies.length > 0 && (
3228
<WebchatReplies />
3329
)}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
1+
import { CASE_STATUS } from '@botonic/core'
12
import React, { useContext } from 'react'
23

34
import { WebchatContext } from '../context'
5+
import { BannerContainer, BannerText, BannerTextStrong } from './styles'
46

5-
interface PositionInQueueProps {}
7+
interface HandoffInformationBannerProps {}
68

7-
export function HandoffInformationBanner({}: PositionInQueueProps) {
9+
export function HandoffInformationBanner({}: HandoffInformationBannerProps) {
810
const { webchatState } = useContext(WebchatContext)
911

1012
const handoffState = webchatState.handoffState
1113

12-
return <div>PositionInQueue: {handoffState.currentQueuePosition}</div>
14+
console.log('handoffState', handoffState)
15+
16+
if (
17+
handoffState.previousStatus === CASE_STATUS.WAITING &&
18+
handoffState.nextStatus === CASE_STATUS.ATTENDING
19+
) {
20+
return (
21+
<BannerContainer>
22+
<BannerText>An agent has joined the conversation</BannerText>
23+
</BannerContainer>
24+
)
25+
}
26+
27+
if (handoffState.previousStatus === CASE_STATUS.ATTENDING) {
28+
return (
29+
<BannerContainer>
30+
<BannerText>Chat with agent has ended</BannerText>
31+
</BannerContainer>
32+
)
33+
}
34+
35+
return (
36+
<BannerContainer>
37+
<BannerText>
38+
Position in queue{' '}
39+
<BannerTextStrong>{handoffState.currentQueuePosition}</BannerTextStrong>
40+
</BannerText>
41+
</BannerContainer>
42+
)
1343
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import styled from 'styled-components'
2+
3+
import { COLORS } from '../../constants'
4+
5+
export const BannerContainer = styled.div`
6+
color: ${COLORS.GRAY};
7+
background-color: white;
8+
padding: 10px;
9+
border-radius: 5px;
10+
text-align: center;
11+
`
12+
13+
export const BannerText = styled.p`
14+
margin: 0;
15+
`
16+
17+
export const BannerTextStrong = styled.strong`
18+
color: ${COLORS.GRAY};
19+
font-weight: 600;
20+
`

packages/botonic-react/src/webchat/message-list/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { useContext, useEffect, useRef, useState } from 'react'
33
import { ROLES } from '../../constants'
44
import { WebchatContext } from '../../webchat/context'
55
import { BotonicContainerId } from '../constants'
6+
import { HandoffInformationBanner } from '../handoff'
67
import TypingIndicator from '../typing-indicator'
78
import { IntroMessage } from './intro-message'
89
import { ScrollButton } from './scroll-button'
@@ -149,11 +150,14 @@ export const WebchatMessageList = () => {
149150
style={{
150151
content: '',
151152
}}
152-
></div>
153+
/>
153154
)}
154155
</React.Fragment>
155156
)
156157
})}
158+
{webchatState.isWebchatOpen && webchatState.handoffState.isHandoff && (
159+
<HandoffInformationBanner />
160+
)}
157161
{webchatState.typing && <TypingIndicator ref={typingRef} />}
158162
</ScrollableMessageList>
159163
{showScrollButton && <ScrollButton handleClick={handleScrollToBottom} />}

packages/botonic-react/src/webchat/webchat.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ import { TriggerButton } from './trigger-button'
7171
import { useStorageState } from './use-storage-state-hook'
7272
import { getParsedAction } from './utils'
7373
import { WebviewContainer } from './webview/index'
74-
import { HandoffInformationBanner } from './handoff'
7574

7675
// eslint-disable-next-line complexity, react/display-name
7776
const Webchat = forwardRef<WebchatRef | null, WebchatProps>((props, ref) => {

0 commit comments

Comments
 (0)