diff --git a/src/views/Conversations/Online/Input/InputComposer.jsx b/src/views/Conversations/Online/Input/InputComposer.jsx index 1bf75ba..f276de8 100644 --- a/src/views/Conversations/Online/Input/InputComposer.jsx +++ b/src/views/Conversations/Online/Input/InputComposer.jsx @@ -13,6 +13,7 @@ import { postUploadFileItem } from '@/actions/CommonActions'; import dayjs from 'dayjs'; import useStyleStore from '@/stores/StyleStore'; import ComposerTools from './ComposerTools'; +import { useOrderStore, OrderLabelDefaultOptions, OrderStatusDefaultOptions } from "@/stores/OrderStore"; const ButtonStyleClsMapped = { @@ -22,9 +23,11 @@ const ButtonStyleClsMapped = }; const InputComposer = ({ channel, currentActive }) => { + const { message: appMessage, notification: appNotification } = App.useApp(); const [mobile] = useStyleStore((state) => [state.mobile]); const {userId, whatsAppBusiness} = useAuthStore((state) => state.loginUser); + const [customerDetail] = useOrderStore((s) => [s.customerDetail]) const websocket = useConversationStore((state) => state.websocket); const websocketOpened = useConversationStore((state) => state.websocketOpened); @@ -55,6 +58,7 @@ const InputComposer = ({ channel, currentActive }) => { ? 'Enter 发送, Shift+Enter 换行' : 'Enter 换行'; + const [toIM, setToIM] = useState(''); const [fromIM, setFromIM] = useState(DEFAULT_WABA); useEffect(() => { switch (channel) { @@ -73,15 +77,25 @@ const InputComposer = ({ channel, currentActive }) => { return () => {} }, [channel, whatsAppBusiness]) + useEffect(() => { + const _to = currentConversation.whatsapp_phone_number || currentConversation.channel?.whatsapp_phone_number || currentConversation.channel?.phone_number // || customerDetail.whatsapp_phone_number + setToIM(_to); + + return () => {} + }, [currentConversation, customerDetail]) const textInputRef = useRef(null); const [textContent, setTextContent] = useState(''); const invokeSendMessage = (msgObj) => { + if (isEmpty(toIM)) { + appNotification.warning({ message: '缺少WhatsApp号码, 请先在会话列表右键菜单编辑联系人', placement: 'top' }); + return false + } const msgObjMerge = { sender: 'me', senderName: 'me', - to: currentConversation.whatsapp_phone_number, + to: toIM, from: fromIM, date: new Date(), status: 'waiting', @@ -110,7 +124,7 @@ const InputComposer = ({ channel, currentActive }) => { const msgObjMerge = { sender: 'me', senderName: 'me', - to: currentConversation.whatsapp_phone_number, + to: toIM, date: new Date(), status: 'waiting', ...(referenceMsg.id ? { context: { message_id: referenceMsg.id }, message_origin: referenceMsg } : {}), @@ -125,10 +139,14 @@ const InputComposer = ({ channel, currentActive }) => { }; const invokeSendUploadMessage = (msgObj) => { + if (isEmpty(toIM)) { + appNotification.warning({ message: '缺少WhatsApp号码, 请先在会话列表右键菜单编辑联系人', placement: 'top' }); + return false + } const msgObjMerge = { sender: 'me', senderName: 'me', - to: currentConversation.whatsapp_phone_number, + to: toIM, from: fromIM, date: new Date(), status: 'waiting', @@ -142,7 +160,6 @@ const InputComposer = ({ channel, currentActive }) => { websocket.sendMessage({ ...contentToSend, opi_sn: userId, coli_sn: currentConversation.coli_sn, conversationid: currentConversation.sn, }); }; - const { message: appMessage } = App.useApp(); const [pastedUploading, setPastedUploading] = useState(false); const readPasted = async (file) => { const fileTypeSupport = Object.keys(whatsappSupportFileTypes).find((msgType) => whatsappSupportFileTypes[msgType].types.includes(file.type)); @@ -260,6 +277,7 @@ const InputComposer = ({ channel, currentActive }) => { return (