11'use client'
22import type { ButtonProps } from '@/app/components/base/button'
33import type { FormInputItem , UserAction } from '@/app/components/workflow/nodes/human-input/types'
4+ import type { SiteInfo } from '@/models/share'
45import type { HumanInputFormError } from '@/service/use-share'
56import {
67 RiCheckboxCircleFill ,
@@ -24,7 +25,7 @@ import { useGetHumanInputForm, useSubmitHumanInputForm } from '@/service/use-sha
2425import { cn } from '@/utils/classnames'
2526
2627export 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 = / ( \{ \{ # \$ o u t p u t \. [ ^ # ] + # \} \} ) / 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 }
0 commit comments