feat: better errors feedback

This commit is contained in:
swve 2024-01-16 23:23:13 +01:00
parent af7d5edd80
commit 854c7dd415
5 changed files with 118 additions and 35 deletions

View file

@ -5,12 +5,18 @@ export const AIChatBotContext = createContext(null) as any;
export const AIChatBotDispatchContext = createContext(null) as any;
export type AIChatBotStateTypes = {
messages: AIMessage[],
isModalOpen: boolean,
aichat_uuid: string,
isWaitingForResponse: boolean,
chatInputValue: string
error: AIError
}
type AIError = {
isError: boolean
status: number
error_message: string
}
function AIChatBotProvider({ children }: { children: React.ReactNode }) {
@ -20,7 +26,8 @@ function AIChatBotProvider({ children }: { children: React.ReactNode }) {
isModalOpen: false,
aichat_uuid: null,
isWaitingForResponse: false,
chatInputValue: ''
chatInputValue: '',
error: { isError: false, status: 0, error_message: ' ' } as AIError
}
);
return (
@ -60,6 +67,8 @@ function aiChatBotReducer(state: any, action: any) {
return { ...state, isWaitingForResponse: false };
case 'setChatInputValue':
return { ...state, chatInputValue: action.payload };
case 'setError':
return { ...state, error: action.payload };
default:
throw new Error(`Unhandled action type: ${action.type}`)

View file

@ -14,6 +14,13 @@ export type AIEditorStateTypes = {
chatInputValue: string,
selectedTool: 'Writer' | 'ContinueWriting' | 'MakeLonger' | 'GenerateQuiz' | 'Translate'
isUserInputEnabled: boolean
error: AIError
}
type AIError = {
isError: boolean
status: number
error_message: string
}
function AIEditorProvider({ children }: { children: React.ReactNode }) {
@ -26,7 +33,8 @@ function AIEditorProvider({ children }: { children: React.ReactNode }) {
isWaitingForResponse: false,
chatInputValue: '',
selectedTool: 'Writer',
isUserInputEnabled: true
isUserInputEnabled: true,
error: { isError: false, status: 0, error_message: ' ' } as AIError
}
);
return (
@ -74,7 +82,9 @@ function aIEditorReducer(state: any, action: any) {
return { ...state, isFeedbackModalOpen: false };
case 'setIsUserInputEnabled':
return { ...state, isUserInputEnabled: action.payload };
case 'setError':
return { ...state, error: action.payload };
default:
throw new Error(`Unhandled action type: ${action.type}`)