@@ -110,6 +110,21 @@ export const MainContent: React.FC<MainContentProps> = (props) => {
110110 }
111111 } , [ activeConversationId , siteUtility ] ) ;
112112
113+ const createConversationWithAssistant = React . useCallback (
114+ async (
115+ assistantInfo : { assistantId : string } | { name : string ; assistantServiceId : string ; templateId : string } ,
116+ ) => {
117+ setSubmitted ( true ) ;
118+ try {
119+ const { conversation } = await createConversation ( assistantInfo ) ;
120+ navigateToConversation ( conversation . id ) ;
121+ } finally {
122+ setSubmitted ( false ) ;
123+ }
124+ } ,
125+ [ createConversation , navigateToConversation ] ,
126+ ) ;
127+
113128 const handleCreate = React . useCallback ( async ( ) => {
114129 if ( submitted || ! isValid || ! assistantId ) {
115130 return ;
@@ -129,25 +144,9 @@ export const MainContent: React.FC<MainContentProps> = (props) => {
129144 if ( ! assistantInfo ) {
130145 return ;
131146 }
132- setSubmitted ( true ) ;
133147
134- try {
135- const { conversation } = await createConversation ( assistantInfo ) ;
136- navigateToConversation ( conversation . id ) ;
137- } finally {
138- // In case of error, allow user to retry
139- setSubmitted ( false ) ;
140- }
141- } , [
142- assistantId ,
143- assistantServiceId ,
144- createConversation ,
145- isValid ,
146- name ,
147- navigateToConversation ,
148- submitted ,
149- templateId ,
150- ] ) ;
148+ await createConversationWithAssistant ( assistantInfo ) ;
149+ } , [ assistantId , assistantServiceId , createConversationWithAssistant , isValid , name , submitted , templateId ] ) ;
151150
152151 const handleImport = React . useCallback (
153152 ( conversationIds : string [ ] ) => {
@@ -159,17 +158,14 @@ export const MainContent: React.FC<MainContentProps> = (props) => {
159158 ) ;
160159
161160 const handleQuickCreate = React . useCallback (
162- ( assistant : Assistant | undefined ) => {
163- if ( ! assistant ) {
164- return ( ) => { } ;
165- }
166- return ( ) => {
167- setIsValid ( true ) ;
168- setAssistantId ( assistant . id ) ;
169- handleCreate ( ) ;
161+ ( assistant : Assistant ) => {
162+ return async ( ) => {
163+ await createConversationWithAssistant ( {
164+ assistantId : assistant . id ,
165+ } ) ;
170166 } ;
171167 } ,
172- [ handleCreate ] ,
168+ [ createConversationWithAssistant ] ,
173169 ) ;
174170
175171 const quickAssistantCreateButton = React . useCallback (
0 commit comments