|
|
|
@ -3,7 +3,7 @@ import { useParams, useNavigate } from "react-router-dom";
|
|
|
|
|
import { List, Avatar, Flex } from 'antd';
|
|
|
|
|
import { useAuthContext } from '@/stores/AuthContext';
|
|
|
|
|
import { useConversationState, useConversationDispatch } from '@/stores/ConversationContext';
|
|
|
|
|
import { fetchCustomerProfile, receivedCustomerProfile, setCurrentConversation, addConversationList, setActiveConversations, postConversationItemClose } from '@/actions/ConversationActions'
|
|
|
|
|
import { fetchCustomerProfile, receivedCustomerProfile, setCurrentConversation, addConversationList, postConversationItemClose } from '@/actions/ConversationActions'
|
|
|
|
|
import { ChatList } from 'react-chat-elements';
|
|
|
|
|
import { isEmpty, pick } from '@/utils/utils';
|
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
@ -56,11 +56,9 @@ const Conversations = (() => {
|
|
|
|
|
if (isEmpty(data)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!isEmpty(data.conversation)) {
|
|
|
|
|
if (!isEmpty(data.conversations)) {
|
|
|
|
|
dispatch(addConversationList(data.conversations));
|
|
|
|
|
dispatch(setCurrentConversation(data.conversation[0]));
|
|
|
|
|
const thisCMapped = data.conversation.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {});
|
|
|
|
|
dispatch(setActiveConversations(thisCMapped));
|
|
|
|
|
dispatch(setCurrentConversation(data.conversations[0]));
|
|
|
|
|
} else {
|
|
|
|
|
// reset chat window
|
|
|
|
|
if (isEmpty(data.contact?.[0]?.whatsapp_phone_number)) {
|
|
|
|
@ -80,7 +78,6 @@ const Conversations = (() => {
|
|
|
|
|
'customer_name': data.contact[0].name,
|
|
|
|
|
};
|
|
|
|
|
dispatch(addConversationList([newChat]));
|
|
|
|
|
dispatch(setActiveConversations({ [`${newChat.sn}`]: []}));
|
|
|
|
|
const newCurrent = pick(newChat, ['sn', 'coli_sn', 'whatsapp_phone_number', 'whatsapp_name', 'customer_name']);
|
|
|
|
|
dispatch(setCurrentConversation(newCurrent));
|
|
|
|
|
}
|
|
|
|
@ -93,10 +90,10 @@ const Conversations = (() => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onSwitchConversation = (item) => {
|
|
|
|
|
switchConversation(item);
|
|
|
|
|
if (item.coli_sn) {
|
|
|
|
|
navigate(`/order/chat/${item.coli_sn}`, { replace: true });
|
|
|
|
|
}
|
|
|
|
|
switchConversation(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleConversationItemClose = async (item) => {
|
|
|
|
|