refactor: simplify component loading

This commit is contained in:
Shivam Mishra
2025-06-10 17:49:23 +05:30
parent 851f622fe1
commit 2dca1eee89
3 changed files with 12 additions and 93 deletions
@@ -1,4 +1,3 @@
import { useState, useCallback } from 'react';
import { useChatwoot } from './ChatwootProvider';
import { ChatwootMessageListWrapper } from './ChatwootMessageListWrapper';
@@ -6,36 +5,11 @@ export const ChatwootConversation = ({
conversationId,
className = '',
style = {},
onError = null,
onLoad = null,
...otherProps
}) => {
// Ensure we're inside a ChatwootProvider
useChatwoot(); // This will throw if not in Provider context
const [, setIsLoaded] = useState(false);
const [, setError] = useState(null);
// Validate required props
if (!conversationId) {
throw new Error('ChatwootConversation: conversationId is required');
}
const handleLoad = useCallback(() => {
setIsLoaded(true);
setError(null);
onLoad?.();
}, [onLoad]);
const handleError = useCallback(
err => {
setError(err.message);
setIsLoaded(false);
onError?.(err);
},
[onError]
);
return (
<div
className={`chatwoot-conversation ${className}`}
@@ -46,13 +20,7 @@ export const ChatwootConversation = ({
...style,
}}
>
<ChatwootMessageListWrapper
conversationId={conversationId}
onLoad={handleLoad}
onError={handleError}
className="h-full w-full"
{...otherProps}
/>
<ChatwootMessageListWrapper className="h-full w-full" {...otherProps} />
</div>
);
};