From 1b0abdf642d85d93a072203f37dbe5069f051f93 Mon Sep 17 00:00:00 2001 From: twwu Date: Tue, 27 Jan 2026 18:14:24 +0800 Subject: [PATCH] feat(humanInput): improve form handling with site info integration and error management --- .../(humanInputLayout)/form/[token]/form.tsx | 19 ++++++++++++++----- .../human-input-content/expiration-time.tsx | 2 +- web/eslint-suppressions.json | 3 --- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/web/app/(humanInputLayout)/form/[token]/form.tsx b/web/app/(humanInputLayout)/form/[token]/form.tsx index f17c7879f4..784084fdeb 100644 --- a/web/app/(humanInputLayout)/form/[token]/form.tsx +++ b/web/app/(humanInputLayout)/form/[token]/form.tsx @@ -1,6 +1,7 @@ 'use client' import type { ButtonProps } from '@/app/components/base/button' import type { FormInputItem, UserAction } from '@/app/components/workflow/nodes/human-input/types' +import type { SiteInfo } from '@/models/share' import type { HumanInputFormError } from '@/service/use-share' import { RiCheckboxCircleFill, @@ -24,7 +25,7 @@ import { useGetHumanInputForm, useSubmitHumanInputForm } from '@/service/use-sha import { cn } from '@/utils/classnames' export type FormData = { - site: any + site: { site: SiteInfo } form_content: string inputs: FormInputItem[] resolved_default_values: Record @@ -40,16 +41,14 @@ const FormContent = () => { const [inputs, setInputs] = useState>({}) const [success, setSuccess] = useState(false) + const [expired, setExpired] = useState(false) const { mutate: submitForm, isPending: isSubmitting } = useSubmitHumanInputForm() const { data: formData, isLoading, error } = useGetHumanInputForm(token) - const expired = (error as HumanInputFormError | null)?.code === 'human_input_form_expired' const submitted = (error as HumanInputFormError | null)?.code === 'human_input_form_submitted' - const site = formData?.site.site - const splitByOutputVar = (content: string): string[] => { const outputVarRegex = /(\{\{#\$output\.[^#]+#\}\})/g const parts = content.split(outputVarRegex) @@ -87,6 +86,14 @@ const FormContent = () => { onSuccess: () => { setSuccess(true) }, + onError: async (error) => { + if (error instanceof Response && error.status && error.json) { + const errorData = await error.json() as { code: string, message: string } + if (errorData.code === 'human_input_form_expired') { + setExpired(true) + } + } + }, }, ) } @@ -207,12 +214,14 @@ const FormContent = () => { ) } + const site = formData.site.site + return (
{ diff --git a/web/eslint-suppressions.json b/web/eslint-suppressions.json index 17fb365272..a78a3003b2 100644 --- a/web/eslint-suppressions.json +++ b/web/eslint-suppressions.json @@ -102,9 +102,6 @@ "app/(humanInputLayout)/form/[token]/form.tsx": { "react-hooks-extra/no-direct-set-state-in-use-effect": { "count": 1 - }, - "ts/no-explicit-any": { - "count": 2 } }, "app/(shareLayout)/components/splash.tsx": {