Skip to content

Commit 0bf17a4

Browse files
authored
Merge pull request #58 from Dialogue-Bot/DIAL-42-implement-test-your-bot
Dial 42 implement test your bot
2 parents 9610cff + f979439 commit 0bf17a4

File tree

20 files changed

+131
-10
lines changed

20 files changed

+131
-10
lines changed

client/package-lock.json

Lines changed: 4 additions & 4 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
@@ -65,7 +65,7 @@
6565
"crypto-js": "^4.2.0",
6666
"date-fns": "^3.3.1",
6767
"dayjs": "^1.11.10",
68-
"dialogue-chatbox": "^1.0.4",
68+
"dialogue-chatbox": "^1.0.8",
6969
"embla-carousel-react": "^8.0.0-rc23",
7070
"fast-glob": "^3.3.2",
7171
"firebase": "^10.8.0",

client/src/apis/channel.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ class ChannelApi {
5353
params: { flowId },
5454
})
5555
}
56+
57+
getChannelForTest(): Promise<TBaseResponse<TChannelWithChannelType>> {
58+
return http_client.get(ENDPOINTS.CHANNEL.FOR_TEST)
59+
}
60+
61+
updateChannelForTest(
62+
flowId: string,
63+
): Promise<TBaseResponse<TChannelWithChannelType>> {
64+
return http_client.put(ENDPOINTS.CHANNEL.FOR_TEST, { flowId })
65+
}
5666
}
5767

5868
export const channelApi = new ChannelApi()

client/src/components/pages/flow-detail/flow-inside.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { edgeTypes } from './edge-types'
1919
import { useFlowCtx } from './flow-provider'
2020
import { NodeDialog } from './node-dialog'
2121
import { nodeTypes } from './node-types'
22+
import TestYourBot from './test-your-bot'
2223
import { Toolbar } from './toolbar'
2324

2425
export const FlowInside = () => {
@@ -103,6 +104,7 @@ export const FlowInside = () => {
103104
<Actions />
104105
<NodeDialog />
105106
<ConditionDialog />
107+
<TestYourBot />
106108
</div>
107109
)
108110
}

client/src/components/pages/flow-detail/flow-provider.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { EActionTypes, EMessageTypes, TFLow, TNode } from '@/types/flow'
44
import { createId } from '@paralleldrive/cuid2'
55
import _ from 'lodash'
66
import {
7+
Dispatch,
78
DragEvent,
9+
SetStateAction,
810
createContext,
911
useCallback,
1012
useContext,
@@ -63,6 +65,8 @@ type FlowCtx = {
6365
handleDeleteEdgeById: (id: string) => void
6466
handleNodesDelete: OnNodesDelete
6567
handleDeleteNodeById: (id: string) => void
68+
showTestBot: boolean
69+
setShowTestBot: Dispatch<SetStateAction<boolean>>
6670
}
6771

6872
const FlowContext = createContext<FlowCtx | undefined>(undefined)
@@ -134,6 +138,8 @@ export const FlowProvider = ({ children, flow }: Props) => {
134138
flow.settings?.find((setting) => setting.type === 'language')?.value ||
135139
'en',
136140
)
141+
const [showTestBot, setShowTestBot] = useState(false)
142+
137143
const updateFlowMutation = useUpdateFlow({
138144
isShowToastSuccess: false,
139145
})
@@ -852,6 +858,8 @@ export const FlowProvider = ({ children, flow }: Props) => {
852858
handleDeleteEdgeById,
853859
handleNodesDelete,
854860
handleDeleteNodeById,
861+
showTestBot,
862+
setShowTestBot,
855863
}}
856864
>
857865
{children}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { queryChannelForTestOption } from '@/lib/query-options'
2+
import { cn } from '@/lib/utils'
3+
import { useSuspenseQuery } from '@tanstack/react-query'
4+
import { ChatBox } from 'dialogue-chatbox'
5+
import { useParams } from 'react-router-dom'
6+
import { useFlowCtx } from '.'
7+
8+
const TestYourBot = () => {
9+
const { id } = useParams()
10+
const { data: channel } = useSuspenseQuery(
11+
queryChannelForTestOption(id as string),
12+
)
13+
14+
const { showTestBot } = useFlowCtx()
15+
16+
return (
17+
showTestBot && (
18+
<div
19+
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]',
21+
)}
22+
>
23+
<ChatBox channelId={channel.contactId} className='h-full w-full' />
24+
</div>
25+
)
26+
)
27+
}
28+
29+
export default TestYourBot

client/src/components/pages/flow-detail/toolbar.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { useFlowCtx } from '.'
1515
import Setting from './setting'
1616

1717
export const Toolbar = () => {
18-
const { toggleActions } = useFlowCtx()
18+
const { toggleActions, openActions, setShowTestBot, showTestBot } =
19+
useFlowCtx()
1920
const { t } = useTranslation('flowDetail')
2021
const { flow, edges, nodes, getCompleteFlows } = useFlowCtx()
2122
const { id } = useParams()
@@ -45,7 +46,10 @@ export const Toolbar = () => {
4546
<Button
4647
size='icon'
4748
variant='ghost'
48-
onClick={toggleActions}
49+
onClick={() => {
50+
toggleActions()
51+
setShowTestBot(false)
52+
}}
4953
className='flex-shrink-0'
5054
>
5155
<Zap className='w-4 h-4' />
@@ -75,7 +79,18 @@ export const Toolbar = () => {
7579
orientation='vertical'
7680
className='self-stretch h-[unset]'
7781
/>
78-
<Button variant='ghost'>{t('toolbar.test_your_bot')}</Button>
82+
<Button
83+
variant='ghost'
84+
onClick={() => {
85+
setShowTestBot((prev) => !prev)
86+
87+
if (openActions) {
88+
toggleActions()
89+
}
90+
}}
91+
>
92+
{t(!showTestBot ? 'toolbar.test_your_bot' : 'toolbar.close_test')}
93+
</Button>
7994
<Button
8095
variant='secondary'
8196
onClick={handleSave}

client/src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const ENDPOINTS = {
3131
DELETE: '/channel/delete',
3232
DELETES: '/channel/deletes',
3333
TYPES: '/channel/types',
34+
FOR_TEST: '/channel/for-test',
3435
},
3536
FLOW: {
3637
INDEX: '/flow',

client/src/hooks/auth/use-logout.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ export const useLogout = () => {
1818
window.location.href = '/login'
1919
setUser(null)
2020
queryClient.clear()
21+
localStorage.removeItem('user-bot-id')
2122
},
2223
onError() {
2324
window.location.href = '/login'
2425
setUser(null)
2526
queryClient.clear()
27+
localStorage.removeItem('user-bot-id')
2628
},
2729
})
2830
}

client/src/hooks/channel/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './use-create-channel'
2-
export * from './use-update-channel'
32
export * from './use-delete-channel'
43
export * from './use-delete-many-channel'
4+
export * from './use-update-channel'
5+
export * from './use-update-channel-for-test'

0 commit comments

Comments
 (0)