fix: 从订单页面进入会话页面.

dev/emitter
Lei OT 10 months ago
parent 70259d222e
commit 615f7b332f

@ -1,6 +1,6 @@
import { create } from 'zustand'; import { create } from 'zustand';
import { RealTimeAPI } from '@/channel/realTimeAPI'; import { RealTimeAPI } from '@/channel/realTimeAPI';
import { olog, isEmpty, groupBy } from '@/utils/commons'; import { olog, isEmpty, groupBy, sortArrayByOrder } from '@/utils/commons';
import { receivedMsgTypeMapped, handleNotification } from '@/channel/bubbleMsgUtils'; import { receivedMsgTypeMapped, handleNotification } from '@/channel/bubbleMsgUtils';
import { fetchConversationsList, fetchTemplates, fetchConversationsSearch, UNREAD_MARK, fetchTags } from '@/actions/ConversationActions'; import { fetchConversationsList, fetchTemplates, fetchConversationsSearch, UNREAD_MARK, fetchTags } from '@/actions/ConversationActions';
import { devtools } from 'zustand/middleware'; import { devtools } from 'zustand/middleware';
@ -299,9 +299,9 @@ const conversationSlice = (set, get) => ({
totalNotify: state.totalNotify - (conversation.unread_msg_count || 0), totalNotify: state.totalNotify - (conversation.unread_msg_count || 0),
currentConversation: Object.assign({}, conversation, targetItemFromList), currentConversation: Object.assign({}, conversation, targetItemFromList),
referenceMsg: {}, referenceMsg: {},
topList: mergedListMapped['1'] || [], // topList: mergedListMapped['1'] || [],
pageList: mergedListMapped['0'] || [], // pageList: mergedListMapped['0'] || [],
conversationsList: [...conversationsList], // conversationsList: [...conversationsList],
})); }));
}, },
updateCurrentConversation: (conversation) => set((state) => ({ currentConversation: { ...state.currentConversation, ...conversation } })), updateCurrentConversation: (conversation) => set((state) => ({ currentConversation: { ...state.currentConversation, ...conversation } })),

@ -55,13 +55,13 @@ export const useOrderStore = create(devtools((set, get) => ({
if (json.errcode === 0 && json.result.length > 0) { if (json.errcode === 0 && json.result.length > 0) {
const orderResult = json.result[0] const orderResult = json.result[0]
set(() => ({ set(() => ({
orderDetail: orderResult, orderDetail: {...orderResult, coli_sn: colisn },
customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {}, customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {},
lastQuotation: orderResult.quotes.length > 0 ? orderResult.quotes[0] : {}, lastQuotation: orderResult.quotes.length > 0 ? orderResult.quotes[0] : {},
quotationList: orderResult.quotes, quotationList: orderResult.quotes,
})) }))
return { return {
orderDetail: orderResult, orderDetail: {...orderResult, coli_sn: colisn },
customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {}, customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {},
lastQuotation: orderResult.quotes.length > 0 ? orderResult.quotes[0] : {}, lastQuotation: orderResult.quotes.length > 0 ? orderResult.quotes[0] : {},
quotationList: orderResult.quotes, quotationList: orderResult.quotes,

@ -106,26 +106,32 @@ const Conversations = () => {
} }
useEffect(() => { useEffect(() => {
// console.log('effect []');
if (mobile !== false) { if (mobile !== false) {
setCurrentConversation({}); setCurrentConversation({});
} else
if (order_sn ) {
setCurrentConversation({ coli_sn: Number(order_sn), sn: null })
// updateCurrentConversation({ coli_sn: Number(order_sn) });
} }
return () => {}; return () => {};
}, []); }, []);
useEffect(() => { // useEffect(() => {
if (order_sn && shouldFetchCList) { // if (order_sn && shouldFetchCList) {
setCurrentConversation({ coli_sn: Number(order_sn) }) // setCurrentConversation({ coli_sn: Number(order_sn) })
// updateCurrentConversation({ coli_sn: Number(order_sn) }); // // updateCurrentConversation({ coli_sn: Number(order_sn) });
} else { // } else {
// setCurrentConversation({ coli_sn: order_sn }) // // setCurrentConversation({ coli_sn: order_sn })
} // }
return () => {} // return () => {}
}, [order_sn]) // }, [order_sn])
useEffect(() => { useEffect(() => {
// console.log('effect isVisible', isVisible);
if (isVisible && initialState) { if (isVisible && initialState) {
refreshConversationList(new Date()); // , loading, refreshConversationList(new Date()); // , loading,
} }
@ -134,6 +140,7 @@ const Conversations = () => {
}, [isVisible]); }, [isVisible]);
useEffect(() => { useEffect(() => {
// console.log('effect activeList');
if (isVisible && initialState) { if (isVisible && initialState) {
refreshConversationList(); // loading refreshConversationList(); // loading
} }
@ -150,15 +157,17 @@ const Conversations = () => {
setDataSource([...topList, ...pageList]); setDataSource([...topList, ...pageList]);
// setDataSource(activeList ? conversationsList: closedConversationsList); // setDataSource(activeList ? conversationsList: closedConversationsList);
return () => {}; return () => {};
}, [conversationsList, listUpdateFlag, currentConversation.unread_msg_count]); }, [conversationsList, topList, pageList, listUpdateFlag, currentConversation.unread_msg_count]);
useEffect(() => { useEffect(() => {
// console.log('effect get order c');
if (isEmpty(currentConversation.sn) && order_sn && shouldFetchCList && initialState) { if (isEmpty(currentConversation.sn) && order_sn && shouldFetchCList && initialState) {
getOrderConversationList(order_sn) getOrderConversationList(order_sn)
} }
return () => {} return () => {}
}, [order_sn, initialState, customerDetail.email]) }, [initialState, customerDetail.email])
const getOrderConversationList = async (colisn) => { const getOrderConversationList = async (colisn) => {
@ -184,7 +193,7 @@ const Conversations = () => {
findCurrent = findCurrentOrderChats[findCurrentIndex]; findCurrent = findCurrentOrderChats[findCurrentIndex];
if (findCurrentIndex !== -1) { if (findCurrentIndex !== -1) {
addToConversationList(findCurrentOrderChats); addToConversationList(findCurrentOrderChats, 'top');
} else // if (!isEmpty(whatsappID)) } else // if (!isEmpty(whatsappID))
{ {
try { try {
@ -201,8 +210,8 @@ const Conversations = () => {
} }
} }
} }
// else else {
if (isEmpty(whatsappID)) { // if (isEmpty(whatsappID) && findCurrentIndex === undefined) {
// //
findCurrentIndex = conversationsList.findIndex((item) => `${item.coli_sn}` === `${colisn}`); findCurrentIndex = conversationsList.findIndex((item) => `${item.coli_sn}` === `${colisn}`);
findCurrent = conversationsList[findCurrentIndex]; findCurrent = conversationsList[findCurrentIndex];
@ -219,6 +228,8 @@ const Conversations = () => {
const onSwitchConversation = async (item) => { const onSwitchConversation = async (item) => {
setCurrentConversation(item); setCurrentConversation(item);
setShouldFetchCList(false);
if (isEmpty(item.coli_sn)) { if (isEmpty(item.coli_sn)) {
navigate(routePrefix, { replace: true }); navigate(routePrefix, { replace: true });
} else { } else {
@ -308,7 +319,7 @@ const Conversations = () => {
/> />
)} )}
</div> </div>
<ChatListFilter <ChatListFilter key='chat-list-filter'
onFilterChange={(d) => { onFilterChange={(d) => {
refreshConversationList() refreshConversationList()
}} }}

Loading…
Cancel
Save