diff --git a/src/stores/OrderStore.js b/src/stores/OrderStore.js index a9651fc..b7227c9 100644 --- a/src/stores/OrderStore.js +++ b/src/stores/OrderStore.js @@ -4,16 +4,22 @@ import { fetchJSON, postForm } from '@/utils/request' import { API_HOST, EMAIL_HOST } from '@/config' import { isNotEmpty, prepareUrl } from '@/utils/commons' -export const useOrderStore = create(devtools((set, get) => ({ - +const initialState = { orderList: [], orderDetail: {}, customerDetail: {}, lastQuotation: {}, quotationList: [], otherEmailList: [], +}; + +export const useOrderStore = create(devtools((set, get) => ({ + + ...initialState, drawerOpen: false, + resetOrderStore: () => set(initialState), + openDrawer: () => { set(() => ({ drawerOpen: true diff --git a/src/views/Conversations/Online/ConversationsList.jsx b/src/views/Conversations/Online/ConversationsList.jsx index 056ee15..9dce49c 100644 --- a/src/views/Conversations/Online/ConversationsList.jsx +++ b/src/views/Conversations/Online/ConversationsList.jsx @@ -159,6 +159,7 @@ const Conversations = () => { return () => {}; }, [conversationsList, topList, pageList, listUpdateFlag, currentConversation.unread_msg_count]); + let orderChatRefreshing = false; useEffect(() => { // console.log('effect get order c'); @@ -171,6 +172,10 @@ const Conversations = () => { const getOrderConversationList = async (colisn) => { + if (orderChatRefreshing !== false) { + return false; + } + orderChatRefreshing = true; const { whatsapp_phone_number } = switchToC; const whatsappID = coli_guest_WhatsApp || whatsapp_phone_number || ''; @@ -216,6 +221,7 @@ const Conversations = () => { findCurrentIndex = conversationsList.findIndex((item) => `${item.coli_sn}` === `${colisn}`); findCurrent = conversationsList[findCurrentIndex]; } + orderChatRefreshing = false; if (findCurrentIndex >= 0) { setCurrentConversation(findCurrent); return findCurrent; diff --git a/src/views/Conversations/Online/order/CustomerProfile.jsx b/src/views/Conversations/Online/order/CustomerProfile.jsx index 171c96e..a21520d 100644 --- a/src/views/Conversations/Online/order/CustomerProfile.jsx +++ b/src/views/Conversations/Online/order/CustomerProfile.jsx @@ -34,6 +34,7 @@ const CustomerProfile = () => { ] = useOrderStore(s => [ s.orderDetail, s.customerDetail, s.lastQuotation, s.quotationList, s.fetchOrderDetail, s.setOrderPropValue, s.appendOrderComment, s.fetchOtherEmail, s.otherEmailList, s.fetchHistoryOrder ]); + const [resetOrderStore] = useOrderStore(state => [state.resetOrderStore]) const [chatOrder, setChatOrder] = useState(currentOrder); @@ -91,8 +92,10 @@ const CustomerProfile = () => { duration: 60, }); }); - } - }, [currentOrder]); + } else { + resetOrderStore(); + } + }, [currentOrder, currentConversationID]); let regularText = ""; if (orderDetail.buytime > 0) regularText = "(R" + orderDetail.buytime + ")";