feat: 订单信息: 号码点击打开新建会话;

hotfix/new-conversation
Lei OT 1 year ago
parent 015c31f3da
commit 88cedb3a8c

@ -0,0 +1,35 @@
import useConversationStore from '@/stores/ConversationStore';
import { fetchOrderConversationsList } from '@/actions/ConversationActions';
import { isEmpty } from '@/utils/commons';
export function useConversationNewItem() {
const [currentConversation, setCurrentConversation] = useConversationStore((state) => [
state.currentConversation,
state.setCurrentConversation,
]);
const conversationsList = useConversationStore((state) => state.conversationsList);
const addToConversationList = useConversationStore((state) => state.addToConversationList);
const openOrderContactConversation = async (whatsappID) => {
const { coli_sn, opi_sn } = currentConversation;
let findCurrentOrderChats = conversationsList.filter(
(item) => `${item.coli_sn}` === `${coli_sn}` && `${item.opi_sn}` === `${opi_sn}` && `${item.whatsapp_phone_number}` === `${whatsappID}`
);
let findCurrentIndex = isEmpty(findCurrentOrderChats) ? -1 : 0; // findCurrentOrderChats.length-1;
let findCurrent = findCurrentOrderChats[findCurrentIndex];
if (findCurrentIndex !== -1) {
addToConversationList(findCurrentOrderChats);
} else if (!isEmpty(whatsappID)) {
const data = await fetchOrderConversationsList({ opisn: opi_sn, colisn: coli_sn, whatsappid: whatsappID });
if (!isEmpty(data)) {
addToConversationList(data);
findCurrentIndex = data.findIndex((item) => `${item.coli_sn}` === `${coli_sn}` && `${item.opi_sn}` === `${opi_sn}` && `${item.whatsapp_phone_number}` === `${whatsappID}`);
findCurrentIndex = findCurrentIndex >= 0 ? findCurrentIndex : 0;
findCurrent = data[findCurrentIndex];
}
}
if (findCurrentIndex >= 0) {
setCurrentConversation(findCurrent);
}
return false;
};
return { openOrderContactConversation };
}

@ -50,7 +50,7 @@ export const ConversationItemForm = ({ initialValues, onFormInstanceReady }) =>
rules={[{ required: true, message: '关联的订单' }]}
validateStatus='warning'
help='请务必确认关联的订单是否正确'>
<Input placeholder='关联订单' disabled={initialValues.is_current_order} />
<Input placeholder='请先关联订单' disabled={initialValues.is_current_order} />
</Form.Item>
<Form.Item name={'coli_sn'} label='订单SN' hidden={initialValues.is_current_order} rules={[{ required: true, message: '订单SN' }]}>
<Input placeholder='订单SN' />

@ -4,10 +4,9 @@ import { useShallow } from 'zustand/react/shallow';
import { Image, Modal, Button } from 'antd';
import MessagesList from './MessagesList';
import { fetchCleanUnreadMsgCount, fetchMessages, MESSAGE_PAGE_SIZE } from '@/actions/ConversationActions';
import { fetchOrderConversationsList, } from '@/actions/ConversationActions';
import { isEmpty } from '@/utils/commons';
import useAuthStore from '@/stores/AuthStore';
import { useVisibilityState } from '@/hooks/useVisibilityState';
import { useConversationNewItem } from '@/hooks/useConversation';
const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
const userId = useAuthStore((state) => state.loginUser.userId);
@ -98,32 +97,12 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
}
};
const openContactConversation = async (whatsappID) => {
const {coli_sn, opi_sn} = currentConversation;
let findCurrentOrderChats = conversationsList.filter((item) => `${item.coli_sn}` === `${coli_sn}` && `${item.opi_sn}` === `${opi_sn}` && `${item.whatsapp_phone_number}` === `${whatsappID}`);
let findCurrentIndex = isEmpty(findCurrentOrderChats) ? -1 : 0; // findCurrentOrderChats.length-1;
let findCurrent = findCurrentOrderChats[findCurrentIndex];
if (findCurrentIndex !== -1) {
addToConversationList(findCurrentOrderChats);
} else if (!isEmpty(whatsappID)) {
const data = await fetchOrderConversationsList({ opisn: opi_sn, colisn: coli_sn, whatsappid: whatsappID });
if (!isEmpty(data)) {
addToConversationList(data);
findCurrentIndex = data.findIndex((item) => `${item.coli_sn}` === `${coli_sn}` && `${item.opi_sn}` === `${opi_sn}` && `${item.whatsapp_phone_number}` === `${whatsappID}`);
findCurrentIndex = findCurrentIndex >= 0 ? findCurrentIndex : 0;
findCurrent = data[findCurrentIndex];
}
}
if (findCurrentIndex >= 0) {
setCurrentConversation(findCurrent);
}
setContactsModalVisible(false);
return false;
};
const { openOrderContactConversation } = useConversationNewItem();
const [contactsModalVisible, setContactsModalVisible] = useState(false);
const [contactListData, setContactListData] = useState([]);
const handleContactItemClick = (contact) => {
openContactConversation(contact.wa_id);
openOrderContactConversation(contact.wa_id);
setContactsModalVisible(false);
}
const handleContactListClick = (data) => {
setContactListData(data);

@ -9,6 +9,8 @@ import { useOrderStore, OrderLabelDefaultOptions, OrderStatusDefaultOptions } fr
import useAuthStore from '@/stores/AuthStore'
import QuotesHistory from './QuotesHistory'
import ConversationBind from './../ConversationBind';
import ConversationsNewItem from './../ConversationsNewItem';
import { useConversationNewItem } from '@/hooks/useConversation';
const CustomerProfile = (() => {
const { notification, message } = App.useApp()
@ -47,6 +49,15 @@ const CustomerProfile = (() => {
let regularText = ''
if (orderDetail.buytime > 0) regularText = '(R' + orderDetail.buytime + ')'
const { openOrderContactConversation } = useConversationNewItem();
const [newChatModalVisible, setNewChatModalVisible] = useState(false);
const [newChatFormValues, setNewChatFormValues] = useState({});
const handleNewChat = async (values) => {
const newContact = { wa_id: values.wa_id };
openOrderContactConversation(newContact.wa_id);
setNewChatModalVisible(false);
}
if (currentOrder) {
return (
<div className='divide-x-0 divide-y divide-dashed divide-gray-300'>
@ -55,7 +66,7 @@ const CustomerProfile = (() => {
bordered={false}
title={orderDetail.order_no}
actions={[
<Select
<Select key={'orderlabel'} size='small'
style={{
width: '100%'
}}
@ -77,7 +88,7 @@ const CustomerProfile = (() => {
value={orderDetail.tags}
options={orderLabelOptions}
/>,
<Select
<Select key={'orderstatus'} size='small'
style={{
width: '100%'
}}
@ -106,7 +117,13 @@ const CustomerProfile = (() => {
<Typography.Text ><UserOutlined className=' pr-1' />{customerDetail.name + regularText}</Typography.Text>
<Typography.Text ><PhoneOutlined className=' pr-1' />{customerDetail.phone}</Typography.Text>
<Typography.Text ><MailOutlined className=' pr-1' />{customerDetail.email}</Typography.Text>
<Typography.Text ><WhatsAppOutlined className='pr-1' />{customerDetail.whatsapp_phone_number}</Typography.Text>
<Typography.Text >
<WhatsAppOutlined className='pr-1' />
<Button type='link' size={'small'} onClick={() => {
setNewChatModalVisible(true);
setNewChatFormValues(prev => ({...prev, phone_number: customerDetail.whatsapp_phone_number, is_current_order: true, }))
}} >{customerDetail.whatsapp_phone_number}</Button>
</Typography.Text>
</Flex>
</Flex>
</Card>
@ -156,6 +173,7 @@ const CustomerProfile = (() => {
setIsModalOpen(true)
}}>添加备注</Button>
</Spin>
<ConversationsNewItem initialValues={newChatFormValues} open={newChatModalVisible} onCreate={handleNewChat} onCancel={() => setNewChatModalVisible(false)} />
</div>
)
} else {

Loading…
Cancel
Save