|
|
|
@ -46,16 +46,23 @@ const Conversations = () => {
|
|
|
|
|
const getOrderConversationList = async (colisn) => {
|
|
|
|
|
const { whatsapp_phone_number } = switchToC;
|
|
|
|
|
const whatsappID = coli_guest_WhatsApp || whatsapp_phone_number || '';
|
|
|
|
|
let findCurrent = conversationsList.findIndex((item) => item.coli_sn === Number(colisn));
|
|
|
|
|
if (!isEmpty(whatsappID)) {
|
|
|
|
|
let findCurrentOrderChats = conversationsList.filter((item) => `${item.coli_sn}` === `${colisn}`);
|
|
|
|
|
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: userId, colisn: colisn, whatsappid: whatsappID });
|
|
|
|
|
if (!isEmpty(data)) {
|
|
|
|
|
addToConversationList(data);
|
|
|
|
|
findCurrentIndex = 0; // data.length-1; // data.lastIndexOf((item) => item.coli_sn === Number(colisn));
|
|
|
|
|
findCurrent = data[findCurrentIndex];
|
|
|
|
|
} else {
|
|
|
|
|
// findCurrentIndex = conversationsList.findIndex((item) => item.coli_sn === Number(colisn)); // data.findIndex((item) => item.sn === currentConversation.sn);
|
|
|
|
|
}
|
|
|
|
|
findCurrent = conversationsList.findIndex((item) => item.coli_sn === Number(colisn)); // data.findIndex((item) => item.sn === currentConversation.sn);
|
|
|
|
|
}
|
|
|
|
|
if (findCurrent !== -1) {
|
|
|
|
|
switchConversation(conversationsList[findCurrent]);
|
|
|
|
|
if (findCurrentIndex >= 0) {
|
|
|
|
|
switchConversation(findCurrent);
|
|
|
|
|
} else {
|
|
|
|
|
// reset chat window
|
|
|
|
|
setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn });
|
|
|
|
|