Skip to content

Commit 1b0abdf

Browse files
committed
feat(humanInput): improve form handling with site info integration and error management
1 parent 441104a commit 1b0abdf

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

web/app/(humanInputLayout)/form/[token]/form.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22
import type { ButtonProps } from '@/app/components/base/button'
33
import type { FormInputItem, UserAction } from '@/app/components/workflow/nodes/human-input/types'
4+
import type { SiteInfo } from '@/models/share'
45
import type { HumanInputFormError } from '@/service/use-share'
56
import {
67
RiCheckboxCircleFill,
@@ -24,7 +25,7 @@ import { useGetHumanInputForm, useSubmitHumanInputForm } from '@/service/use-sha
2425
import { cn } from '@/utils/classnames'
2526

2627
export type FormData = {
27-
site: any
28+
site: { site: SiteInfo }
2829
form_content: string
2930
inputs: FormInputItem[]
3031
resolved_default_values: Record<string, string>
@@ -40,16 +41,14 @@ const FormContent = () => {
4041

4142
const [inputs, setInputs] = useState<Record<string, string>>({})
4243
const [success, setSuccess] = useState(false)
44+
const [expired, setExpired] = useState(false)
4345

4446
const { mutate: submitForm, isPending: isSubmitting } = useSubmitHumanInputForm()
4547

4648
const { data: formData, isLoading, error } = useGetHumanInputForm(token)
4749

48-
const expired = (error as HumanInputFormError | null)?.code === 'human_input_form_expired'
4950
const submitted = (error as HumanInputFormError | null)?.code === 'human_input_form_submitted'
5051

51-
const site = formData?.site.site
52-
5352
const splitByOutputVar = (content: string): string[] => {
5453
const outputVarRegex = /(\{\{#\$output\.[^#]+#\}\})/g
5554
const parts = content.split(outputVarRegex)
@@ -87,6 +86,14 @@ const FormContent = () => {
8786
onSuccess: () => {
8887
setSuccess(true)
8988
},
89+
onError: async (error) => {
90+
if (error instanceof Response && error.status && error.json) {
91+
const errorData = await error.json() as { code: string, message: string }
92+
if (errorData.code === 'human_input_form_expired') {
93+
setExpired(true)
94+
}
95+
}
96+
},
9097
},
9198
)
9299
}
@@ -207,12 +214,14 @@ const FormContent = () => {
207214
)
208215
}
209216

217+
const site = formData.site.site
218+
210219
return (
211220
<div className={cn('mx-auto flex h-full w-full max-w-[720px] flex-col items-center')}>
212221
<div className="mt-4 flex w-full shrink-0 items-center gap-3 py-3">
213222
<AppIcon
214223
size="large"
215-
iconType={site.icon_type as any}
224+
iconType={site.icon_type}
216225
icon={site.icon}
217226
background={site.icon_background}
218227
imageUrl={site.icon_url}

web/app/components/base/chat/chat/answer/human-input-content/expiration-time.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ExpirationTime = ({
2121
<div
2222
className={cn(
2323
'system-xs-regular mt-1 flex items-center gap-x-1 text-text-tertiary',
24-
isSameOrAfter && 'text-text-warning',
24+
!isSameOrAfter && 'text-text-warning',
2525
)}
2626
>
2727
{

web/eslint-suppressions.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@
102102
"app/(humanInputLayout)/form/[token]/form.tsx": {
103103
"react-hooks-extra/no-direct-set-state-in-use-effect": {
104104
"count": 1
105-
},
106-
"ts/no-explicit-any": {
107-
"count": 2
108105
}
109106
},
110107
"app/(shareLayout)/components/splash.tsx": {

0 commit comments

Comments
 (0)