fix(web): form submmit in human input form page

This commit is contained in:
JzoNg 2026-05-08 10:32:53 +08:00
parent 04ed797ac9
commit 3f35f3594b
4 changed files with 25 additions and 8 deletions

View File

@ -186,7 +186,12 @@ describe('Human input share form', () => {
action: 'approve',
inputs: {
summary: 'updated summary',
attachments: [mockContentItemState.uploadedFile],
attachments: [{
type: 'document',
transfer_method: TransferMethod.local_file,
url: '',
upload_file_id: 'upload-file-1',
}],
},
},
}, expect.objectContaining({
@ -208,7 +213,12 @@ describe('Human input share form', () => {
action: 'approve',
inputs: {
summary: 'initial summary',
attachments: [mockContentItemState.uploadedFile],
attachments: [{
type: 'document',
transfer_method: TransferMethod.local_file,
url: '',
upload_file_id: 'upload-file-1',
}],
},
},
}, expect.objectContaining({

View File

@ -16,7 +16,7 @@ import DifyLogo from '@/app/components/base/logo/dify-logo'
type LoadedFormContentProps = {
formData: FormData
isSubmitting: boolean
onSubmit: (inputs: Record<string, HumanInputFieldValue>, actionID: string) => void
onSubmit: (inputs: Record<string, HumanInputFieldValue>, actionID: string, formInputs: FormData['inputs']) => void
}
const LoadedFormContent = ({
@ -40,7 +40,7 @@ const LoadedFormContent = ({
}
const submit = (actionID: string) => {
onSubmit(inputs, actionID)
onSubmit(inputs, actionID, formData.inputs)
}
const isActionDisabled = isSubmitting || hasInvalidRequiredHumanInput(formData.inputs, inputs)

View File

@ -1,14 +1,22 @@
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) => {
const submit = useCallback((inputs: Record<string, HumanInputFieldValue>, actionID: string, formInputs: FormInputItem[]) => {
submitForm(
{ token, data: { inputs, action: actionID } },
{
token,
data: {
inputs: getProcessedHumanInputFormInputs(formInputs, inputs) || {},
action: actionID,
},
},
{
onSuccess: () => {
setSuccess(true)

View File

@ -1,5 +1,4 @@
import type { FormData as HumanInputFormData } from '@/app/(humanInputLayout)/form/[token]/form'
import type { HumanInputFieldValue } from '@/app/components/base/chat/chat/answer/human-input-content/field-renderer'
import type { AppConversationData, ConversationItem } from '@/models/share'
import { useMutation, useQuery } from '@tanstack/react-query'
import {
@ -198,7 +197,7 @@ export const useGetHumanInputForm = (token: string, options: ShareQueryOptions =
type SubmitHumanInputFormParams = {
token: string
data: {
inputs: Record<string, HumanInputFieldValue>
inputs: Record<string, unknown>
action: string
}
}