fix: 重复请求订单的会话

2.0/wai-server
Lei OT 10 months ago
parent 2c38a86d3c
commit 86a7d76409

@ -7,7 +7,7 @@ import ConversationsNewItem from './ConversationsNewItem';
import { debounce, flush, isEmpty, isNotEmpty, pick } from '@/utils/commons'; import { debounce, flush, isEmpty, isNotEmpty, pick } from '@/utils/commons';
import useConversationStore from '@/stores/ConversationStore'; import useConversationStore from '@/stores/ConversationStore';
import useAuthStore from '@/stores/AuthStore'; import useAuthStore from '@/stores/AuthStore';
import { useOrderStore, OrderLabelDefaultOptions, OrderStatusDefaultOptions } from "@/stores/OrderStore"; // import { useOrderStore, OrderLabelDefaultOptions, OrderStatusDefaultOptions } from "@/stores/OrderStore";
import { useVisibilityState } from '@/hooks/useVisibilityState'; import { useVisibilityState } from '@/hooks/useVisibilityState';
import ChatListItem from './Components/ChatListItem'; import ChatListItem from './Components/ChatListItem';
import ChatListFilter from './Components/ChatListFilter'; import ChatListFilter from './Components/ChatListFilter';
@ -25,14 +25,14 @@ const Conversations = () => {
const routerReplace = mobile === false ? true : false; // : true; const routerReplace = mobile === false ? true : false; // : true;
const routePrefix = mobile === false ? `/order/chat` : `/m/chat`; const routePrefix = mobile === false ? `/order/chat` : `/m/chat`;
const { state: orderRow } = useLocation(); const { state: orderRow } = useLocation();
const { coli_guest_WhatsApp } = orderRow || {}; const { coli_guest_WhatsApp, guest_email } = orderRow || {};
const { order_sn } = useParams(); const { order_sn } = useParams();
const navigate = useNavigate(); const navigate = useNavigate();
const userId = useAuthStore((state) => state.loginUser.userId); const userId = useAuthStore((state) => state.loginUser.userId);
const initialState = useConversationStore((state) => state.initialState); const initialState = useConversationStore((state) => state.initialState);
const [customerDetail] = useOrderStore((s) => [s.customerDetail]) // const [customerDetail] = useOrderStore((s) => [s.customerDetail])
const [currentConversation, setCurrentConversation, updateCurrentConversation] = useConversationStore((state) => [state.currentConversation, state.setCurrentConversation, state.updateCurrentConversation]); const [currentConversation, setCurrentConversation, updateCurrentConversation] = useConversationStore((state) => [state.currentConversation, state.setCurrentConversation, state.updateCurrentConversation]);
const [topList, pageList, conversationsList] = useConversationStore((state) => [state.topList, state.pageList, state.conversationsList]); const [topList, pageList, conversationsList] = useConversationStore((state) => [state.topList, state.pageList, state.conversationsList]);
@ -162,12 +162,14 @@ const Conversations = () => {
let orderChatRefreshing = false; let orderChatRefreshing = false;
useEffect(() => { useEffect(() => {
if (isEmpty(currentConversation.sn) && order_sn && shouldFetchCList && initialState) { // console.log('first', isEmpty(currentConversation.sn) , order_sn , shouldFetchCList , initialState)
// isEmpty(currentConversation.sn) &&
if (order_sn && shouldFetchCList && initialState) {
getOrderConversationList(order_sn) getOrderConversationList(order_sn)
} }
return () => {} return () => {}
}, [initialState, customerDetail]) }, [order_sn, shouldFetchCList, initialState])
const getOrderConversationList = async (colisn) => { const getOrderConversationList = async (colisn) => {
@ -178,6 +180,7 @@ const Conversations = () => {
const { whatsapp_phone_number } = switchToC; const { whatsapp_phone_number } = switchToC;
const whatsappID = coli_guest_WhatsApp || whatsapp_phone_number || ''; const whatsappID = coli_guest_WhatsApp || whatsapp_phone_number || '';
const _email = guest_email || '';
// if (isEmpty(conversationsList)) { // if (isEmpty(conversationsList)) {
// return false; // return false;
// } // }
@ -188,10 +191,10 @@ const Conversations = () => {
// let findCurrentOrderChats = conversationsList.filter((item) => `${item.coli_sn}` === `${colisn}`); // let findCurrentOrderChats = conversationsList.filter((item) => `${item.coli_sn}` === `${colisn}`);
// 使opisn + whatsappID , whatsappID, // 使opisn + whatsappID , whatsappID,
if (!isEmpty(whatsappID) || !isEmpty(customerDetail.email)) { if (!isEmpty(whatsappID) || !isEmpty(_email)) {
findCurrentOrderChats = conversationsList.filter( findCurrentOrderChats = conversationsList.filter(
(item) => `${item.coli_sn}` === `${colisn}` && (`${item.whatsapp_phone_number}` === `${whatsappID}` || `${item.channels?.email}` === `${customerDetail.email}`) (item) => `${item.coli_sn}` === `${colisn}` && (`${item.whatsapp_phone_number}` === `${whatsappID}` || `${item.channels?.email}` === `${_email}`)
) )
findCurrentIndex = isEmpty(findCurrentOrderChats) ? -1 : 0; // findCurrentOrderChats.length-1; findCurrentIndex = isEmpty(findCurrentOrderChats) ? -1 : 0; // findCurrentOrderChats.length-1;
findCurrent = findCurrentOrderChats[findCurrentIndex]; findCurrent = findCurrentOrderChats[findCurrentIndex];
@ -201,7 +204,8 @@ const Conversations = () => {
} else // if (!isEmpty(whatsappID)) } else // if (!isEmpty(whatsappID))
{ {
try { try {
const data = await fetchOrderConversationsList({ opisn: userId, colisn: colisn, whatsappid: whatsappID, email: customerDetail.email }); setShouldFetchCList(false);
const data = await fetchOrderConversationsList({ opisn: userId, colisn: colisn, whatsappid: whatsappID, email: _email });
if (!isEmpty(data)) { if (!isEmpty(data)) {
addToConversationList(data); addToConversationList(data);
findCurrentIndex = 0; // data.length-1; // data.lastIndexOf((item) => item.coli_sn === Number(colisn)); findCurrentIndex = 0; // data.length-1; // data.lastIndexOf((item) => item.coli_sn === Number(colisn));

Loading…
Cancel
Save