|
|
|
@ -1,20 +1,34 @@
|
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import { Input, Button, Tabs, List, Space, Popover, Flex } from 'antd';
|
|
|
|
|
// import { Input } from 'react-chat-elements';
|
|
|
|
|
import { useConversationState } from '@/stores/ConversationContext';
|
|
|
|
|
import { useConversationState, useConversationDispatch } from '@/stores/ConversationContext';
|
|
|
|
|
import { sentNewMessage } from '@/actions/ConversationActions';
|
|
|
|
|
import { useAuthContext } from '@/stores/AuthContext';
|
|
|
|
|
import { LikeOutlined, MessageOutlined, StarOutlined, SendOutlined, PlusOutlined, PlusCircleOutlined } from '@ant-design/icons';
|
|
|
|
|
import { cloneDeep, getNestedValue, isEmpty } from '@/utils/utils';
|
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
import { whatsappTemplatesParamMapped } from '@/lib/msgUtils';
|
|
|
|
|
import { whatsappTemplatesParamMapped, sentMsgTypeMapped } from '@/lib/msgUtils';
|
|
|
|
|
|
|
|
|
|
const InputBox = ({ onSend }) => {
|
|
|
|
|
const { currentConversation, templates } = useConversationState();
|
|
|
|
|
const InputBox = () => {
|
|
|
|
|
const { loginUser } = useAuthContext();
|
|
|
|
|
const { userId } = loginUser;
|
|
|
|
|
const { websocket, currentConversation, templates } = useConversationState();
|
|
|
|
|
const dispatch = useConversationDispatch();
|
|
|
|
|
const [textContent, setTextContent] = useState('');
|
|
|
|
|
|
|
|
|
|
const talkabled = !isEmpty(currentConversation.sn);
|
|
|
|
|
|
|
|
|
|
const invokeSendMessage = (msgObj) => {
|
|
|
|
|
console.log('sendMessage------------------', msgObj);
|
|
|
|
|
const contentToSend = sentMsgTypeMapped[msgObj.type].contentToSend(msgObj);
|
|
|
|
|
websocket.sendMessage({ ...contentToSend, opi_sn: userId });
|
|
|
|
|
const contentToRender = sentMsgTypeMapped[msgObj.type].contentToRender(msgObj);
|
|
|
|
|
console.log(contentToRender, 'contentToRender sendMessage------------------');
|
|
|
|
|
dispatch(sentNewMessage(contentToRender));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSendText = () => {
|
|
|
|
|
if (typeof onSend === 'function' && textContent.trim() !== '') {
|
|
|
|
|
if (textContent.trim() !== '') {
|
|
|
|
|
const msgObj = {
|
|
|
|
|
type: 'text',
|
|
|
|
|
text: textContent,
|
|
|
|
@ -24,14 +38,13 @@ const InputBox = ({ onSend }) => {
|
|
|
|
|
date: new Date(),
|
|
|
|
|
status: 'waiting',
|
|
|
|
|
};
|
|
|
|
|
onSend(msgObj);
|
|
|
|
|
invokeSendMessage(msgObj);
|
|
|
|
|
setTextContent('');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSendTemplate = (fromTemplate) => {
|
|
|
|
|
console.log(fromTemplate, 'fromTemplate');
|
|
|
|
|
if (typeof onSend === 'function') {
|
|
|
|
|
const _conversation = { ...cloneDeep(currentConversation) };
|
|
|
|
|
const msgObj = {
|
|
|
|
|
type: 'whatsappTemplate',
|
|
|
|
@ -67,9 +80,8 @@ const InputBox = ({ onSend }) => {
|
|
|
|
|
},
|
|
|
|
|
template_origin: fromTemplate,
|
|
|
|
|
};
|
|
|
|
|
onSend(msgObj);
|
|
|
|
|
invokeSendMessage(msgObj);
|
|
|
|
|
setOpenTemplates(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const [openTemplates, setOpenTemplates] = useState(false);
|
|
|
|
|