|
|
|
@ -5,6 +5,7 @@ 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 }) => {
|
|
|
|
|
|
|
|
|
@ -50,13 +51,16 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get
|
|
|
|
|
buttonsArr = componentsObj?.buttons?.reduce((r, c) => r.concat(c.buttons), []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const parts = str.split(/(https?:\/\/[^\s]+|\p{Emoji_Presentation})/gmu).filter((s) => s !== '');
|
|
|
|
|
const parts = str.split(/(https?:\/\/[^\s]+|\p{Emoji_Presentation}|\d{4,})/gmu).filter((s) => s !== '');
|
|
|
|
|
const links = str.match(/https?:\/\/[\S]+/gi) || [];
|
|
|
|
|
const numbers = str.match(/\d{4,}/g) || [];
|
|
|
|
|
const emojis = str.match(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g) || [];
|
|
|
|
|
const extraClass = isEmpty(emojis) ? '' : '';
|
|
|
|
|
const objArr = parts.reduce((prev, curr, index) => {
|
|
|
|
|
if (links.includes(curr)) {
|
|
|
|
|
prev.push({ type: 'link', key: curr });
|
|
|
|
|
} else if (numbers.includes(curr)) {
|
|
|
|
|
prev.push({ type: 'number', key: curr });
|
|
|
|
|
} else if (emojis.includes(curr)) {
|
|
|
|
|
prev.push({ type: 'emoji', key: curr });
|
|
|
|
|
} else {
|
|
|
|
@ -84,6 +88,13 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get
|
|
|
|
|
{part.key}
|
|
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
} 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, }))}}>
|
|
|
|
|
{part.key}
|
|
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// if (part.type === 'emoji')
|
|
|
|
|
return part.key;
|
|
|
|
@ -123,6 +134,15 @@ 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'>
|
|
|
|
@ -188,6 +208,7 @@ 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>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|