77 Card ,
88 Text ,
99 Title2 ,
10+ Toast ,
11+ ToastBody ,
12+ ToastTitle ,
1013} from "@fluentui/react-components" ;
1114import {
1215 Send20Regular ,
@@ -27,6 +30,9 @@ const HomeInput: React.FC<HomeInputProps> = ({
2730 onQuickTaskSelect,
2831} ) => {
2932 const [ input , setInput ] = useState ( "" ) ;
33+ const [ submitting , setSubmitting ] = useState ( false ) ;
34+ const [ showToast , setShowToast ] = useState ( false ) ;
35+ const [ error , setError ] = useState < string | null > ( null ) ;
3036 const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
3137 const navigate = useNavigate ( ) ;
3238
@@ -49,22 +55,35 @@ const HomeInput: React.FC<HomeInputProps> = ({
4955
5056 const handleSubmit = async ( ) => {
5157 if ( input . trim ( ) ) {
58+ setSubmitting ( true ) ;
59+ setShowToast ( true ) ;
60+ setError ( null ) ;
5261 try {
5362 // Submit the input task using TaskService
5463 const response = await TaskService . submitInputTask ( input . trim ( ) ) ;
5564
5665 // Clear the input field
57- setInput ( "" ) ;
66+ // setInput("");
5867 if ( textareaRef . current ) {
5968 textareaRef . current . style . height = "auto" ;
6069 }
6170
62- // Navigate to the plan page using the plan_id from the response
63- navigate ( `/plan/${ response . plan_id } ` ) ;
71+ console . log ( 'Task response' , response ) ;
72+ if ( response . plan_id != null ) {
73+ // plan_id is valid (not null or undefined)
74+ navigate ( `/plan/${ response . plan_id } ` ) ;
75+ } else {
76+ // plan_id is not valid, handle accordingly
77+ console . log ( 'Invalid plan:' , response . status ) ;
78+ setShowToast ( false ) ;
79+ setError ( "Failed to create task. Please try again." ) ;
80+ }
6481
65- } catch ( error ) {
66- console . error ( 'Failed to create task:' , error ) ;
67- // You can add error handling here if needed
82+ } catch ( error : any ) {
83+ console . log ( 'Failed to create task:' , error ) ;
84+ setError ( error . message || "Failed to create task." ) ;
85+ } finally {
86+ setSubmitting ( false ) ;
6887 }
6988 }
7089 } ;
@@ -101,12 +120,13 @@ const HomeInput: React.FC<HomeInputProps> = ({
101120 < ChatInput
102121 value = { input }
103122 placeholder = "Describe what you'd like to do or use / to reference files, people, and more" onChange = { setInput }
123+ disabledChat = { submitting }
104124 >
105125 < Button
106126 appearance = "subtle"
107127 className = "home-input-send-button"
108128 onClick = { handleSubmit }
109- disabled = { ! input . trim ( ) }
129+ disabled = { submitting }
110130 icon = { < Send20Regular /> }
111131 />
112132 </ ChatInput >
@@ -137,6 +157,23 @@ const HomeInput: React.FC<HomeInputProps> = ({
137157 ) ) }
138158 </ div >
139159 </ div >
160+ { /* Toast appears after quick tasks */ }
161+ { showToast && (
162+ < div style = { { marginTop : 16 } } >
163+ < Toast >
164+ < ToastTitle > Task submitted!</ ToastTitle >
165+ < ToastBody > Your task is processing.</ ToastBody >
166+ </ Toast >
167+ </ div >
168+ ) }
169+ { error && (
170+ < div style = { { marginTop : 16 } } >
171+ < Toast >
172+ < ToastTitle > Task failed!</ ToastTitle >
173+ < ToastBody > { error } </ ToastBody >
174+ </ Toast >
175+ </ div >
176+ ) }
140177 </ div >
141178 </ div >
142179 </ div >
0 commit comments