Skip to content

Commit 54c6637

Browse files
authored
Merge pull request #76 from Dialogue-Bot/DIAL-42-implement-test-your-bot
feat: update
2 parents efe4875 + 2084585 commit 54c6637

31 files changed

+1237
-157
lines changed

client/package-lock.json

Lines changed: 328 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"crypto-js": "^4.2.0",
6767
"date-fns": "^3.3.1",
6868
"dayjs": "^1.11.10",
69-
"dialogue-chatbox": "^1.0.10",
69+
"dialogue-chatbox": "^1.0.12",
7070
"embla-carousel-react": "^8.0.0-rc23",
7171
"fast-glob": "^3.3.2",
7272
"firebase": "^10.8.0",

client/src/apis/live-chat.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
import { ENDPOINTS } from '@/constants'
22
import http_client from '@/lib/http-client'
3+
import { TConversation, TConversationLiveChatQuery } from '@/types/live-chat'
4+
import { TBaseResponse, TResPagination } from '@/types/share'
35

46
class LiveChatApi {
5-
async getConversations() {
6-
return http_client.get(ENDPOINTS.CONVERSATION_LIVE_CHAT.INDEX)
7+
async getConversations(
8+
q?: TConversationLiveChatQuery,
9+
): Promise<TResPagination<TConversation>> {
10+
return http_client.get(ENDPOINTS.CONVERSATION_LIVE_CHAT.INDEX, {
11+
params: q,
12+
})
13+
}
14+
15+
async getConversation(
16+
channelId: string,
17+
userId: string,
18+
): Promise<TBaseResponse<TConversation>> {
19+
return http_client.get(
20+
`${ENDPOINTS.CONVERSATION_LIVE_CHAT.INDEX}/${userId}/${channelId}`,
21+
)
722
}
823
}
24+
25+
export const liveChatApi = new LiveChatApi()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { Layout as AppLayout } from './app'
22
export { Layout as AuthLayout } from './auth'
3-
export { Layout as SettingLayout } from './setting'
3+
export { Layout as LiveChatLayout } from './live-chat'
44
export { Layout as PublishLayout } from './publish'
5+
export { Layout as SettingLayout } from './setting'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './layout'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Outlet } from 'react-router-dom'
2+
import Sidebar from './sidebar'
3+
4+
export const Layout = () => {
5+
return (
6+
<div className='flex h-screen-header'>
7+
<Sidebar />
8+
<div className='flex-1'>
9+
<Outlet />
10+
</div>
11+
</div>
12+
)
13+
}
14+
15+
export default Layout
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ConversationItem } from '@/components/pages/live-chat'
2+
import { queryConversationsOptions } from '@/lib/query-options/live-chat'
3+
import { TConversationLiveChatQuery } from '@/types/live-chat'
4+
import { urlSearchParamsToObject } from '@/utils'
5+
import { useSuspenseQuery } from '@tanstack/react-query'
6+
import { useTranslation } from 'react-i18next'
7+
import { useSearchParams } from 'react-router-dom'
8+
9+
const Sidebar = () => {
10+
const { t } = useTranslation('conversations')
11+
const [search] = useSearchParams()
12+
const { data } = useSuspenseQuery(
13+
queryConversationsOptions(
14+
urlSearchParamsToObject(search) as TConversationLiveChatQuery,
15+
),
16+
)
17+
return (
18+
<aside className='max-w-80 w-full border-r border-input'>
19+
{data.items.length > 0 ? (
20+
<ul>
21+
{data.items.map((item) => {
22+
return (
23+
<li key={`${item.userId}-${item.channelId}`}>
24+
<ConversationItem conversation={item} />
25+
</li>
26+
)
27+
})}
28+
</ul>
29+
) : (
30+
<div className='p-4 flex items-center justify-center'>
31+
<p className='text-muted-foreground'>{t('empty_conversation')}</p>
32+
</div>
33+
)}
34+
</aside>
35+
)
36+
}
37+
38+
export default Sidebar

client/src/components/pages/flow-detail/test-your-bot.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ const TestYourBot = () => {
1717
showTestBot && (
1818
<div
1919
className={cn(
20-
'fixed right-4 z-10 rounded-md shadow w-80 transition-transform duration-300 bottom-4 flex flex-col gap-4 bg-white h-[500px]',
20+
'fixed right-4 z-10 rounded-md shadow w-80 transition-transform duration-300 bottom-4 flex flex-col gap-4 bg-white h-[500px] overflow-hidden',
2121
)}
2222
>
23-
<ChatBox channelId={channel.contactId} className='h-full w-full'
23+
<ChatBox
24+
channelId={channel.contactId}
25+
className='h-full w-full'
2426
isTest
27+
isShowClose={false}
2528
/>
2629
</div>
2730
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ROUTES } from '@/constants'
2+
import { TConversation } from '@/types/live-chat'
3+
import { useNavigate } from 'react-router-dom'
4+
5+
type Props = {
6+
conversation: TConversation
7+
}
8+
9+
export const ConversationItem = ({ conversation }: Props) => {
10+
const navigate = useNavigate()
11+
return (
12+
<div
13+
className='p-4 border-b border-input'
14+
onClick={() => {
15+
navigate(
16+
`${ROUTES.PRIVATE.CONVERSATION.INDEX}/${conversation.userId}/${conversation.channelId}`,
17+
)
18+
}}
19+
>
20+
<div>
21+
<span>
22+
{conversation.userId} - {conversation.channel.contactName}
23+
</span>
24+
</div>
25+
</div>
26+
)
27+
}
28+
29+
export default ConversationItem
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './conversation-item'

0 commit comments

Comments
 (0)