From ca2aa434493716164bec3a1fb31cf52ab7b4bffa Mon Sep 17 00:00:00 2001 From: Lei OT Date: Mon, 8 Apr 2024 15:04:42 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=96=B0=E5=BB=BA=E4=BC=9A=E8=AF=9D=20?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Online/ConversationsList.jsx | 29 ++++++++-- .../Online/ConversationsNewItem.jsx | 58 +++++++++++++++++++ 2 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/views/Conversations/Online/ConversationsNewItem.jsx diff --git a/src/views/Conversations/Online/ConversationsList.jsx b/src/views/Conversations/Online/ConversationsList.jsx index 8f3eb2f..aa928c0 100644 --- a/src/views/Conversations/Online/ConversationsList.jsx +++ b/src/views/Conversations/Online/ConversationsList.jsx @@ -4,6 +4,7 @@ import { Dropdown, Input, Button, } from 'antd'; import { PlusOutlined, WhatsAppOutlined, LoadingOutlined } from '@ant-design/icons'; import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, postNewConversationItem } from '@/actions/ConversationActions'; import { ChatItem } from 'react-chat-elements'; +import ConversationsNewItem from './ConversationsNewItem'; import { isEmpty, olog } from '@/utils/commons'; import useConversationStore from '@/stores/ConversationStore'; import useAuthStore from '@/stores/AuthStore'; @@ -71,9 +72,9 @@ const Conversations = ({ mobile }) => { return () => {}; }, [order_sn, shouldFetchCList, initialState]); - const getOrderConversationList = async (colisn) => { + const getOrderConversationList = async (colisn, WHATSAPP_ID = null) => { const { whatsapp_phone_number } = switchToC; - const whatsappID = coli_guest_WhatsApp || whatsapp_phone_number || ''; + const whatsappID = WHATSAPP_ID || coli_guest_WhatsApp || whatsapp_phone_number || ''; // let findCurrentOrderChats = conversationsList.filter((item) => `${item.coli_sn}` === `${colisn}`); // 使用opisn + whatsappID 判断, 解决订单修改whatsappID号码之后获取新会话, 登录账号此处省略 let findCurrentOrderChats = conversationsList.filter((item) => `${item.whatsapp_phone_number}` === `${whatsappID}`); @@ -97,6 +98,7 @@ const Conversations = ({ mobile }) => { } if (findCurrentIndex >= 0) { setCurrentConversation(findCurrent); + return findCurrent; } else { // reset chat window setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn }); @@ -146,9 +148,27 @@ const Conversations = ({ mobile }) => { setDataSource(conversationsList); }; + const [newChatModalVisible, setNewChatModalVisible] = useState(false); + const [newChatFormValues, setNewChatFormValues] = useState(); + const handleNewChat = async (values) => { + // console.log(values); + const hasNewCurrent = await getOrderConversationList(values.coli_sn, values.phone_number); + if (hasNewCurrent !== false) { + // + } + setNewChatModalVisible(false); + // const newItem = await postNewConversationItem({...values, opi_sn: userId }); + // if ( ! isEmpty(newItem)) { + // addToConversationList(newItem); + // setCurrentConversation(newItem); + // } + // setNewChatFormValues(values); + } + return (
-
+
+ {([404, 383].includes(userId)) &&
@@ -225,6 +245,7 @@ const Conversations = ({ mobile }) => { ))}
+ setNewChatModalVisible(false)} />
); }; diff --git a/src/views/Conversations/Online/ConversationsNewItem.jsx b/src/views/Conversations/Online/ConversationsNewItem.jsx new file mode 100644 index 0000000..70c4e7f --- /dev/null +++ b/src/views/Conversations/Online/ConversationsNewItem.jsx @@ -0,0 +1,58 @@ +import { useState, useEffect } from 'react'; +import { Form, Input, Modal } from 'antd'; +import { isEmpty } from '@/utils/commons'; + +export const ConversationItemForm = ({ initialValues, onFormInstanceReady }) => { + const [form] = Form.useForm(); + useEffect(() => { + onFormInstanceReady(form); + }, []); + return ( +
+ + + + {/* + + */} + + + + {/* + + */} +
+ ); +}; +export const ConversationItemFormModal = ({ open, onCreate, onCancel, initialValues }) => { + const [formInstance, setFormInstance] = useState(); + return ( + { onCancel(); formInstance?.resetFields();}} + destroyOnClose + onOk={async () => { + try { + const values = await formInstance?.validateFields(); + // formInstance?.resetFields(); + onCreate(values); + } catch (error) { + console.log('Failed:', error); + } + }}> + { + setFormInstance(instance); + }} + /> + + ); +}; +export default ConversationItemFormModal;