From c77cc50ac3e6eb5a50a887efc775b010a8428df4 Mon Sep 17 00:00:00 2001 From: swve Date: Tue, 16 Jan 2024 23:29:32 +0100 Subject: [PATCH] fix: include error feedback on AICanvaToolkit --- .../DynamicCanva/AI/AICanvaToolkit.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/web/components/Objects/Activities/DynamicCanva/AI/AICanvaToolkit.tsx b/apps/web/components/Objects/Activities/DynamicCanva/AI/AICanvaToolkit.tsx index 3bb2a041..d71cc41c 100644 --- a/apps/web/components/Objects/Activities/DynamicCanva/AI/AICanvaToolkit.tsx +++ b/apps/web/components/Objects/Activities/DynamicCanva/AI/AICanvaToolkit.tsx @@ -58,7 +58,6 @@ function AIActionButton(props: { editor: Editor, label: string, activity: any }) const prompt = getPrompt(label, selection); dispatchAIChatBot({ type: 'setIsModalOpen' }); await sendMessage(prompt); - } const getTipTapEditorSelectedText = () => { @@ -86,18 +85,30 @@ function AIActionButton(props: { editor: Editor, label: string, activity: any }) await dispatchAIChatBot({ type: 'addMessage', payload: { sender: 'user', message: message, type: 'user' } }); await dispatchAIChatBot({ type: 'setIsWaitingForResponse' }); const response = await sendActivityAIChatMessage(message, aiChatBotState.aichat_uuid, props.activity.activity_uuid) + if (response.success == false) { + await dispatchAIChatBot({ type: 'setIsNoLongerWaitingForResponse' }); + await dispatchAIChatBot({ type: 'setChatInputValue', payload: '' }); + await dispatchAIChatBot({ type: 'setError', payload: { isError: true, status: response.status, error_message: response.data.detail } }); + return; + } await dispatchAIChatBot({ type: 'setIsNoLongerWaitingForResponse' }); await dispatchAIChatBot({ type: 'setChatInputValue', payload: '' }); - await dispatchAIChatBot({ type: 'addMessage', payload: { sender: 'ai', message: response.message, type: 'ai' } }); + await dispatchAIChatBot({ type: 'addMessage', payload: { sender: 'ai', message: response.data.message, type: 'ai' } }); } else { await dispatchAIChatBot({ type: 'addMessage', payload: { sender: 'user', message: message, type: 'user' } }); await dispatchAIChatBot({ type: 'setIsWaitingForResponse' }); const response = await startActivityAIChatSession(message, props.activity.activity_uuid) - await dispatchAIChatBot({ type: 'setAichat_uuid', payload: response.aichat_uuid }); + if (response.success == false) { + await dispatchAIChatBot({ type: 'setIsNoLongerWaitingForResponse' }); + await dispatchAIChatBot({ type: 'setChatInputValue', payload: '' }); + await dispatchAIChatBot({ type: 'setError', payload: { isError: true, status: response.status, error_message: response.data.detail } }); + return; + } + await dispatchAIChatBot({ type: 'setAichat_uuid', payload: response.data.aichat_uuid }); await dispatchAIChatBot({ type: 'setIsNoLongerWaitingForResponse' }); await dispatchAIChatBot({ type: 'setChatInputValue', payload: '' }); - await dispatchAIChatBot({ type: 'addMessage', payload: { sender: 'ai', message: response.message, type: 'ai' } }); + await dispatchAIChatBot({ type: 'addMessage', payload: { sender: 'ai', message: response.data.message, type: 'ai' } }); } }