|
|
|
@ -46,7 +46,7 @@ const Conversations = () => {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const { loginUser } = useAuthContext();
|
|
|
|
|
const { userId } = loginUser;
|
|
|
|
|
const { activeConversations, currentConversation, conversationsList, addToConversationList, setCurrentConversation, receivedMessageList, setMsgLoading } = useConversationStore();
|
|
|
|
|
const { initialState, activeConversations, currentConversation, conversationsList, addToConversationList, setCurrentConversation, receivedMessageList, setMsgLoading } = useConversationStore();
|
|
|
|
|
const [chatlist, setChatlist] = useState([]);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setChatlist(
|
|
|
|
@ -76,12 +76,12 @@ const Conversations = () => {
|
|
|
|
|
|
|
|
|
|
const [shouldFetchCList, setShouldFetchCList] = useState(true);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (order_sn && shouldFetchCList) {
|
|
|
|
|
if (order_sn && shouldFetchCList && initialState) {
|
|
|
|
|
getOrderConversationList(order_sn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [order_sn, shouldFetchCList]);
|
|
|
|
|
}, [order_sn, shouldFetchCList, initialState]);
|
|
|
|
|
|
|
|
|
|
const getOrderConversationList = async (colisn) => {
|
|
|
|
|
const { whatsapp_phone_number } = switchToC;
|
|
|
|
@ -89,8 +89,11 @@ const Conversations = () => {
|
|
|
|
|
const data = await fetchOrderConversationsList({ opisn: userId, colisn: colisn, whatsappid: whatsappID });
|
|
|
|
|
if (!isEmpty(data)) {
|
|
|
|
|
addToConversationList(data);
|
|
|
|
|
const ifCurrent = data.findIndex((item) => item.sn === currentConversation.sn);
|
|
|
|
|
switchConversation(data[ifCurrent === -1 ? 0 : ifCurrent]);
|
|
|
|
|
}
|
|
|
|
|
// const ifCurrent = data.findIndex((item) => item.sn === currentConversation.sn);
|
|
|
|
|
const ifCurrent = conversationsList.findIndex((item) => item.coli_sn === Number(colisn));
|
|
|
|
|
if (ifCurrent !== -1) {
|
|
|
|
|
switchConversation(conversationsList[ifCurrent === -1 ? 0 : ifCurrent]);
|
|
|
|
|
} else {
|
|
|
|
|
// reset chat window
|
|
|
|
|
setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn });
|
|
|
|
|