|
|
|
@ -5,9 +5,8 @@ import { DownOutlined, LoadingOutlined } from '@ant-design/icons';
|
|
|
|
|
import { useShallow } from 'zustand/react/shallow';
|
|
|
|
|
import useConversationStore from '@/stores/ConversationStore';
|
|
|
|
|
import { groupBy, isEmpty, } from '@/utils/commons';
|
|
|
|
|
import ConversationsNewItem from './ConversationsNewItem';
|
|
|
|
|
|
|
|
|
|
const MessagesList = ({ messages, handlePreview, reference, longListLoading, getMoreMessages, shouldScrollBottom, loadNextPage, handleContactClick, ...props }) => {
|
|
|
|
|
const MessagesList = ({ messages, handlePreview, reference, longListLoading, getMoreMessages, shouldScrollBottom, loadNextPage, handleContactClick, setNewChatModalVisible, setNewChatFormValues, ...props }) => {
|
|
|
|
|
|
|
|
|
|
const { message: appMessage } = App.useApp()
|
|
|
|
|
|
|
|
|
@ -41,6 +40,11 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get
|
|
|
|
|
|
|
|
|
|
useEffect(scrollToBottom, [messages]);
|
|
|
|
|
|
|
|
|
|
const openNewChatModal = ({wa_id, wa_name}) => {
|
|
|
|
|
setNewChatModalVisible(true);
|
|
|
|
|
setNewChatFormValues(prev => ({...prev, phone_number: wa_id, name: wa_name }));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const RenderText = memo(function renderText({ str, className, template }) {
|
|
|
|
|
|
|
|
|
|
let headerObj, footerObj, buttonsArr;
|
|
|
|
@ -90,8 +94,7 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get
|
|
|
|
|
);
|
|
|
|
|
} else if (part.type === 'number') {
|
|
|
|
|
return (
|
|
|
|
|
<a key={`${part.key}${index}`} className='text-sm' onClick={() => {setNewChatModalVisible(true);
|
|
|
|
|
setNewChatFormValues(prev => ({...prev, phone_number: part.key, is_current_order: true, }))}}>
|
|
|
|
|
<a key={`${part.key}${index}`} className='text-sm' onClick={() => openNewChatModal({ wa_id: part.key, wa_name: part.key })}>
|
|
|
|
|
{part.key}
|
|
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
@ -134,15 +137,6 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get
|
|
|
|
|
</div>
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
const [newChatModalVisible, setNewChatModalVisible] = useState(false);
|
|
|
|
|
const [newChatFormValues, setNewChatFormValues] = useState({});
|
|
|
|
|
const handleNewChat = async (values) => {
|
|
|
|
|
const newContact = { wa_id: values.wa_id };
|
|
|
|
|
await handleContactClick([newContact]);
|
|
|
|
|
setNewChatModalVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='relative h-full overflow-y-auto overflow-x-hidden flex flex-1'>
|
|
|
|
|
<div ref={reference} className='relative overflow-y-auto overflow-x-hidden block flex-1'>
|
|
|
|
@ -208,7 +202,6 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
<Button onClick={() => scrollToBottom(true)} ghost type={'dashed'} shape={'circle'} className=' absolute bottom-1 right-4' icon={<DownOutlined />} />
|
|
|
|
|
<ConversationsNewItem initialValues={newChatFormValues} open={newChatModalVisible} onCreate={handleNewChat} onCancel={() => setNewChatModalVisible(false)} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|