Skip to content

Commit 53b89a6

Browse files
committed
feat: http-request dialog
1 parent 2e3ad77 commit 53b89a6

25 files changed

+966
-50
lines changed

client/src/app.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Outlet, createBrowserRouter, redirect } from 'react-router-dom'
2-
import i18n from './i18n'
31
import {
42
Channels,
53
ChatBotDetail,
@@ -11,17 +9,18 @@ import {
119
Register,
1210
SetPassword,
1311
} from '@/pages'
12+
import { Outlet, createBrowserRouter, redirect } from 'react-router-dom'
1413

1514
import {
1615
AppLayout,
1716
AuthLayout,
1817
PublishLayout,
1918
SettingLayout,
2019
} from '@/components/layouts'
21-
import { ROUTES } from './constants'
22-
import Help from './pages/help'
20+
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
2321
import { Suspense } from 'react'
2422
import PageLoading from './components/page-loading'
23+
import { ROUTES } from './constants'
2524
import {
2625
appLoader,
2726
articleLoader,
@@ -32,8 +31,8 @@ import {
3231
flowsLoader,
3332
settingLoader,
3433
} from './lib/loader'
34+
import Help from './pages/help'
3535
import HelpDetail from './pages/help-detail'
36-
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
3736

3837
const App = () => {
3938
return (

client/src/components/forms/card.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ type Props = {
2828
defaultValue?: TCardInput
2929
}
3030

31-
export const CardForm = ({ defaultValue, id, onSubmit }: Props) => {
31+
export const CardForm = ({
32+
defaultValue,
33+
id = 'card-form',
34+
onSubmit,
35+
}: Props) => {
3236
const schema = useCardInputSchema()
3337
const { t } = useTranslation(['forms', 'flowDetail'])
3438
const form = useForm<TCardInput>({
@@ -71,7 +75,7 @@ export const CardForm = ({ defaultValue, id, onSubmit }: Props) => {
7175
<Form {...form}>
7276
<form
7377
className='space-y-3'
74-
id='card-form'
78+
id={id}
7579
onSubmit={form.handleSubmit(handleSubmit)}
7680
>
7781
<FormField

client/src/components/forms/variables-setting.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ const parseVariableValue = (value: string, type: string) => {
5454
return value
5555
}
5656

57+
const stringifyVariableValue = (value: any, type: string) => {
58+
if (type === 'array')
59+
return JSON.stringify(value)
60+
.replace('[', '')
61+
.replace(']', '')
62+
.replace(/"/g, '')
63+
64+
if (type === 'object') return JSON.stringify(value, null, 2)
65+
return JSON.stringify(value)
66+
}
67+
5768
export const VariablesSettingForm = ({
5869
id = 'variables-setting-form',
5970
onSubmit,
@@ -68,7 +79,7 @@ export const VariablesSettingForm = ({
6879
...defaultValues,
6980
variables: defaultValues?.variables?.map((variable) => ({
7081
...variable,
71-
value: JSON.stringify(variable.value).replace(/"/g, ''),
82+
value: stringifyVariableValue(variable.value, variable.type as string),
7283
})),
7384
},
7485
})

client/src/components/pages/flow-detail/condition-dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type Props = {}
22

3-
const ConditionDialog = (props: Props) => {
3+
const ConditionDialog = (_props: Props) => {
44
return <div>ConditionDialog</div>
55
}
66

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import i18n from '@/i18n'
2-
import { EActionTypes, EMessageTypes } from '@/types/flow'
2+
import { EActionTypes, EGrammarTypes, EMessageTypes } from '@/types/flow'
33
import {
44
Bolt,
55
GitPullRequest,
@@ -11,7 +11,13 @@ import {
1111
Workflow,
1212
} from 'lucide-react'
1313
import { useTranslation } from 'react-i18next'
14-
import { CheckVariablesContent, MessageDialogContent } from './node-dialog'
14+
import {
15+
CheckVariablesContent,
16+
HttpRequestDialogContent,
17+
MessageDialogContent,
18+
PromptAndCollectDialogContent,
19+
SubFlowContent,
20+
} from './node-dialog'
1521

1622
export const MAP_ACTION_TO_LABEL: Record<EActionTypes, string> = {
1723
[EActionTypes.MESSAGE]: i18n.t('flowDetail:actions.items.message') as string,
@@ -70,7 +76,7 @@ export const MAP_ACTION: Record<
7076
[EActionTypes.PROMPT_AND_COLLECT]: {
7177
icon: () => <HelpCircle className='w-4 h-4' />,
7278
label: 'Prompt and collect',
73-
dialogContent: () => <MessageDialogContent />,
79+
dialogContent: () => <PromptAndCollectDialogContent />,
7480
},
7581
[EActionTypes.CHECK_VARIABLES]: {
7682
icon: () => <Variable className='w-4 h-4' />,
@@ -80,7 +86,7 @@ export const MAP_ACTION: Record<
8086
[EActionTypes.HTTP_REQUEST]: {
8187
icon: () => <GitPullRequest className='w-4 h-4' />,
8288
label: 'Http request',
83-
dialogContent: () => <div>Http request</div>,
89+
dialogContent: () => <HttpRequestDialogContent />,
8490
},
8591
[EActionTypes.SEND_MAIL]: {
8692
icon: () => <Mail className='w-4 h-4' />,
@@ -100,7 +106,7 @@ export const MAP_ACTION: Record<
100106
[EActionTypes.SUB_FLOW]: {
101107
icon: () => <Workflow className='w-4 h-4' />,
102108
label: 'Sub flow',
103-
dialogContent: () => <div>Sub flow</div>,
109+
dialogContent: () => <SubFlowContent />,
104110
},
105111
}
106112

@@ -136,3 +142,12 @@ export const CONDITIONAL_OPERATOR = [
136142
'in',
137143
'not_in',
138144
]
145+
146+
export const MAP_GRAMMAR_TYPE: Record<EGrammarTypes, string> = {
147+
[EGrammarTypes.INTENT]: i18n.t('flowDetail:grammars_type.intent'),
148+
[EGrammarTypes.NUMBER]: i18n.t('flowDetail:grammars_type.number'),
149+
[EGrammarTypes.EMAIL]: i18n.t('flowDetail:grammars_type.email'),
150+
[EGrammarTypes.PHONE_NUMBER]: i18n.t('flowDetail:grammars_type.phone_number'),
151+
[EGrammarTypes.TEXT]: i18n.t('flowDetail:grammars_type.text'),
152+
[EGrammarTypes.YES_NO]: i18n.t('flowDetail:grammars_type.yes_no'),
153+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Button } from '@/components/ui'
22
import { X } from 'lucide-react'
3-
import { BaseEdge, EdgeProps, getBezierPath, useReactFlow } from 'reactflow'
3+
import { BaseEdge, EdgeProps, getSmoothStepPath, useReactFlow } from 'reactflow'
44

55
const foreignObjectSize = 16
66

@@ -22,7 +22,7 @@ export const Edge = ({
2222
deletable?: boolean
2323
}>) => {
2424
const { setEdges } = useReactFlow()
25-
const [edgePath, labelX, labelY] = getBezierPath({
25+
const [edgePath, labelX, labelY] = getSmoothStepPath({
2626
sourceX,
2727
sourceY,
2828
sourcePosition,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useDidUpdate } from '@/hooks/use-did-update'
2-
import { usePrevious } from '@/hooks/use-prev'
32
import { TFlowInput } from '@/lib/schema/flow-input'
43
import { EActionTypes, EMessageTypes, TNode } from '@/types/flow'
54
import { createId } from '@paralleldrive/cuid2'
@@ -99,12 +98,11 @@ export const FlowProvider = ({ children, flow }: Props) => {
9998
},
10099
])
101100
const [selectedNode, setSelectedNode] = useState<Node<any> | null>(null)
102-
const [selectedEdge, setSelectedEdge] = useState<Edge<any> | null>(null)
101+
const [_selectedEdge, setSelectedEdge] = useState<Edge<any> | null>(null)
103102
const [currentLang, setCurrentLang] = useState(
104103
flow.settings?.find((setting) => setting.type === 'language')?.value ||
105104
'en',
106105
)
107-
const prevLang = usePrevious<string>(currentLang)
108106

109107
const [reactFlowInstance, setReactFlowInstance] = useState<ReactFlowInstance<
110108
any,

client/src/components/pages/flow-detail/input-buttons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const InputButtons = ({ onChange, defaultValue }: Props) => {
7070
e.preventDefault()
7171
}}
7272
className={cn(
73-
'space-y-3 max-h-[180px] overflow-y-auto hidden-scroll',
73+
'space-y-3 max-h-[148px] overflow-y-auto hidden-scroll',
7474
{
7575
'py-2 px-[2px]': fields.length > 0,
7676
},

0 commit comments

Comments
 (0)