@@ -8,12 +8,11 @@ const Import: React.FC<ModalFormProps> = ({ initialData, type, adaptorKey, treeD
88 const isBrowser = useIsBrowser ( ) ;
99 if ( ! isBrowser ) { return null ; }
1010 const formRef = useRef < HTMLFormElement > ( null ) ;
11- const [ isSubmitting , handleSubmit ] = useSubmit ( ) ;
12- const [ importState , setImportState ] = useState < boolean | string | null > ( null ) ;
11+ const [ isSubmitting , handleSubmit , message ] = useSubmit ( ) ;
1312 const submitFunction = async ( ) => {
1413 const formData = new FormData ( formRef . current ) ;
15- const formValues = Object . fromEntries ( formData . entries ( ) ) as { endpoint : string , text : any , format : string } ;
16- formValues . endpoint = initialData . id ;
14+ const formValues = Object . fromEntries ( formData . entries ( ) ) as { endpointId : string , text : any , format : string } ;
15+ formValues . endpointId = initialData . id ;
1716 formValues . format = "openAPI" ;
1817 type === 'Edit' ?
1918 // await axios.post('/api/endpoints/' + adaptorKey + '/create', formValues).then(req => {
@@ -27,13 +26,12 @@ const Import: React.FC<ModalFormProps> = ({ initialData, type, adaptorKey, treeD
2726 // onSubmit(data)
2827 // }).catch(error => {
2928 // const { data } = error.response;
30- // setImportState( data.message);
29+ // throw new Error(JSON.stringify( data.message) );
3130 // });
3231 null
3332 :
3433 await axios . post ( '/api/bff/callgent-functions/import' , formValues ) . then ( ( req ) => {
3534 const { data } = req . data ;
36- setImportState ( true ) ;
3735 setTimeout ( onClose , 350 ) ;
3836 data
3937 . filter ( ( item : TreeNodeType ) =>
@@ -45,19 +43,18 @@ const Import: React.FC<ModalFormProps> = ({ initialData, type, adaptorKey, treeD
4543 } ) ;
4644 } ) . catch ( error => {
4745 const { data } = error . response ;
48- setImportState ( data . message ) ;
46+ throw new Error ( JSON . stringify ( data . message ) ) ;
4947 } ) ;
5048 } ;
51-
5249 return (
5350 < form ref = { formRef } >
5451 < div className = "form-group" >
5552 < label htmlFor = "text" > Import SEP Functions</ label >
5653 < textarea className = "customTextarea" name = 'text' id = 'text' style = { { maxHeight : '180px' , } } > </ textarea >
5754 </ div >
5855 < div >
59- { importState === true && < span className = "margin--md text--success" > Successfully { type } !</ span > }
60- { importState !== true && importState !== null && < span className = "margin--md text--danger" > { importState } </ span > }
56+ { message === true && < span className = "margin--md text--success" > Successfully { type } !</ span > }
57+ { message !== true && message !== null && < span className = "margin--md text--danger" > { message } </ span > }
6158 </ div >
6259 < div className = "modal-footer" >
6360 < button type = "button" className = "cancel-button" onClick = { onClose } >
0 commit comments