mirror of
https://github.com/langgenius/dify.git
synced 2026-06-21 01:41:08 +08:00
Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: GPT 5.4 <codex@openai.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { HumanInputFieldValue } from '@/app/components/base/chat/chat/answer/human-input-content/field-renderer'
|
|
import type { FormInputItem } from '@/app/components/workflow/nodes/human-input/types'
|
|
import { useCallback, useState } from 'react'
|
|
import { getProcessedHumanInputFormInputs } from '@/app/components/base/chat/chat/answer/human-input-content/utils'
|
|
import { useSubmitHumanInputForm } from '@/service/use-share'
|
|
|
|
export const useFormSubmit = (token: string) => {
|
|
const [success, setSuccess] = useState(false)
|
|
const { mutate: submitForm, isPending: isSubmitting } = useSubmitHumanInputForm()
|
|
|
|
const submit = useCallback((inputs: Record<string, HumanInputFieldValue>, actionID: string, formInputs: FormInputItem[]) => {
|
|
submitForm(
|
|
{
|
|
token,
|
|
data: {
|
|
inputs: getProcessedHumanInputFormInputs(formInputs, inputs) || {},
|
|
action: actionID,
|
|
},
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
setSuccess(true)
|
|
},
|
|
},
|
|
)
|
|
}, [submitForm, token])
|
|
|
|
return {
|
|
isSubmitting,
|
|
submit,
|
|
success,
|
|
}
|
|
}
|