perf: 订单没有WhatsApp号码, 请求订单会话, 需要用邮箱创建

2.0/email-builder
Lei OT 10 months ago
parent 82cc84dcac
commit f4f9da4a23

@ -57,9 +57,9 @@ export const fetchConversationsList = async (params) => {
/**
*
* @param {object} params { opisn, whatsappid, colisn }
* @param {object} params { opisn, whatsappid, colisn, email }
* * opisn, colisn : 用于查询
* * whatsappid: 用于创建会话
* * whatsappid, email: 用于创建会话
*/
export const fetchOrderConversationsList = async (params) => {
const { errcode, result: data } = await fetchJSON(`${API_HOST}/getorderconversation`, params);

@ -485,8 +485,11 @@ export const useConversationStore = create(
setInitial: (v) => set({ initialState: v }),
// side effects
fetchInitialData: async ({userId, userIds, whatsAppBusiness, ...loginUser}) => {
const { setTemplates, setInitial, setTags } = get();
fetchInitialData: async ({userId, whatsAppBusiness, ...loginUser}) => {
const { addToConversationList, setTemplates, setInitial, setTags } = get();
const conversationsList = await fetchConversationsList({ opisn: userId });
addToConversationList(conversationsList);
const templates = await fetchTemplates({ waba: whatsAppBusiness });
setTemplates(templates);

@ -1,9 +1,8 @@
import React, { useState, useEffect } from 'react';
import { Button, Tag, Radio, Popover, Form, Divider } from 'antd';
import { FilterOutlined, FilterTwoTone } from '@ant-design/icons';
import { debounce, isEmpty, isNotEmpty, objectMapper, stringToColour } from '@/utils/commons';
import { Button, Tag, Radio, Popover, Form } from 'antd';
import { isEmpty, objectMapper, stringToColour } from '@/utils/commons';
import useConversationStore from '@/stores/ConversationStore';
import { OrderLabelDefaultOptions, OrderStatusDefaultOptions } from '@/stores/OrderStore';
import { OrderLabelDefaultOptions } from '@/stores/OrderStore';
import { FilterIcon } from '@/components/Icons';
const otypes = [

@ -64,7 +64,7 @@ const NewTagForm = ({onSubmit,...props}) => {
);
};
const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitchConversation,tabSelectedConversation, setNewChatModalVisible,setEditingChat,...props}) => {
const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitchConversation, setNewChatModalVisible,setEditingChat,...props}) => {
const [mobile] = useStyleStore((state) => [state.mobile]);
const routerReplace = mobile === false ? true : false; // : true;
@ -243,8 +243,6 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
// item.top_state === 1 ? 'bg-stone-100' : '',
String(item.sn) === String(currentConversation.sn)
? '__active text-primary bg-whatsapp-bg'
: String(item.sn) === String(tabSelectedConversation?.sn)
? ' bg-neutral-200'
: item.top_state === 1
? 'bg-stone-100'
: '',

@ -1,12 +1,13 @@
import React, { useEffect, useState, useRef, useCallback } from 'react';
import { useParams, useNavigate, useLocation } from 'react-router-dom';
import { Input, Button, Empty, Tooltip, List } from 'antd';
import { App, Input, Button, Empty, Tooltip, List } from 'antd';
import { PlusOutlined, LoadingOutlined, HistoryOutlined, FireOutlined,AudioTwoTone } from '@ant-design/icons';
import { fetchConversationsList, fetchOrderConversationsList, CONVERSATION_PAGE_SIZE } from '@/actions/ConversationActions';
import ConversationsNewItem from './ConversationsNewItem';
import { debounce, flush, isEmpty, isNotEmpty, pick } from '@/utils/commons';
import useConversationStore from '@/stores/ConversationStore';
import useAuthStore from '@/stores/AuthStore';
import { useOrderStore, OrderLabelDefaultOptions, OrderStatusDefaultOptions } from "@/stores/OrderStore";
import { useVisibilityState } from '@/hooks/useVisibilityState';
import ChatListItem from './Components/ChatListItem';
import ChatListFilter from './Components/ChatListFilter';
@ -14,10 +15,12 @@ import useStyleStore from '@/stores/StyleStore';
import dayjs from 'dayjs';
import { DATETIME_FORMAT } from '@/config';
/**
* []
*/
const Conversations = () => {
const { message } = App.useApp();
const [mobile] = useStyleStore((state) => [state.mobile]);
const routerReplace = mobile === false ? true : false; // : true;
const routePrefix = mobile === false ? `/order/chat` : `/m/chat`;
@ -26,8 +29,12 @@ const Conversations = () => {
const { order_sn } = useParams();
const navigate = useNavigate();
const userId = useAuthStore((state) => state.loginUser.userId);
const initialState = useConversationStore((state) => state.initialState);
const [currentConversation, setCurrentConversation] = useConversationStore((state) => [state.currentConversation, state.setCurrentConversation]);
const [customerDetail] = useOrderStore((s) => [s.customerDetail])
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 [conversationsListLoading, setConversationsListLoading] = useConversationStore((state) => [state.conversationsListLoading, state.setConversationsListLoading]);
const addToConversationList = useConversationStore((state) => state.addToConversationList);
@ -35,16 +42,20 @@ const Conversations = () => {
const isVisible = useVisibilityState();
const [tabSelectedConversation, setTabSelectedConversation] = useState({});
const [tabCnt, setTabCnt] = useState(-1);
const [{ search: searchContent, loadNextPage, ...filterState }, setSearchContent, setFilter] = useConversationStore((state) => [state.filter, state.setFilterSearch, state.setFilter])
const [activeList, setActiveList] = useState(true);
const [currentLoading, setCurrentLoading] = useState(false);
/**
*
*/
let refreshing = false;
async function refreshConversationList(current='', append=false) {
// console.log('invoke -- refreshConversationList', current, conversationsListLoading, refreshing);
if (refreshing !== false) {
return false;
}
refreshing = true;
// setConversationsListLoading(mobile !== undefined ? true : false);
setConversationsListLoading(true);
setCurrentLoading(current==='');
@ -67,6 +78,7 @@ const Conversations = () => {
}
const _list = await fetchConversationsList({ ...searchParams, opisn: userId });
// const _list = DebounceFetchList({ ...searchParams, opisn: userId });
// ,
if (current) {
@ -86,18 +98,27 @@ const Conversations = () => {
// } : {}),
});
refreshing = false;
setConversationsListLoading(false);
setCurrentLoading(false);
}
useEffect(() => {
if (mobile !== undefined) {
setCurrentConversation({});
setCurrentConversation({ });
}
return () => {};
}, []);
const [activeList, setActiveList] = useState(true);
useEffect(() => {
if (order_sn && isEmpty(currentConversation.sn)) {
setCurrentConversation({ coli_sn: order_sn })
}
return () => {}
}, [order_sn])
useEffect(() => {
if (isVisible && initialState) {
@ -117,6 +138,10 @@ const Conversations = () => {
const [dataSource, setDataSource] = useState(conversationsList);
const [listUpdateFlag, setListUpdateFlag] = useState();
const [switchToC, setSwitchToC] = useState({});
const [shouldFetchCList, setShouldFetchCList] = useState(true);
useEffect(() => {
setDataSource([...topList, ...pageList]);
// setDataSource(activeList ? conversationsList: closedConversationsList);
@ -129,45 +154,50 @@ const Conversations = () => {
}
return () => {}
}, [conversationsList, initialState])
}, [order_sn, initialState, customerDetail.email])
const [switchToC, setSwitchToC] = useState({});
const [shouldFetchCList, setShouldFetchCList] = useState(true);
// useEffect(() => {
// console.log('shouldFetchCList', order_sn , shouldFetchCList , initialState);
const getOrderConversationList = async (colisn) => {
// if (order_sn && shouldFetchCList && initialState) {
// getOrderConversationList(order_sn);
// }
const { whatsapp_phone_number } = switchToC;
const whatsappID = coli_guest_WhatsApp || whatsapp_phone_number || '';
// if (isEmpty(conversationsList)) {
// return false;
// }
// return () => {};
// }, [order_sn, shouldFetchCList, initialState]);
let findCurrentOrderChats;
let findCurrentIndex;
let findCurrent;
const getOrderConversationList = async (colisn, WHATSAPP_ID = null) => {
const { whatsapp_phone_number } = switchToC;
const whatsappID = WHATSAPP_ID || coli_guest_WhatsApp || whatsapp_phone_number || '';
// let findCurrentOrderChats = conversationsList.filter((item) => `${item.coli_sn}` === `${colisn}`);
// 使opisn + whatsappID , whatsappID,
if (isEmpty(conversationsList)) {
return false;
}
let findCurrentOrderChats = conversationsList.filter((item) => `${item.whatsapp_phone_number}` === `${whatsappID}` && `${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);
if (!isEmpty(whatsappID) || !isEmpty(customerDetail.email)) {
findCurrentOrderChats = conversationsList.filter(
(item) => `${item.coli_sn}` === `${colisn}` && (`${item.whatsapp_phone_number}` === `${whatsappID}` || `${item.channels?.email}` === `${customerDetail.email}`)
)
findCurrentIndex = isEmpty(findCurrentOrderChats) ? -1 : 0; // findCurrentOrderChats.length-1;
findCurrent = findCurrentOrderChats[findCurrentIndex];
if (findCurrentIndex !== -1) {
addToConversationList(findCurrentOrderChats);
} else // if (!isEmpty(whatsappID))
{
try {
const data = await fetchOrderConversationsList({ opisn: userId, colisn: colisn, whatsappid: whatsappID, email: customerDetail.email });
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);
}
} catch (error) {
// message.warning('')
}
}
} else if (isEmpty(whatsappID)) {
}
else if (isEmpty(whatsappID)) {
//
findCurrentIndex = conversationsList.findIndex((item) => `${item.coli_sn}` === `${colisn}`);
findCurrent = conversationsList[findCurrentIndex];
@ -306,7 +336,6 @@ const Conversations = () => {
refreshConversationList,
setListUpdateFlag,
onSwitchConversation,
tabSelectedConversation,
setNewChatModalVisible,
setEditingChat,
}}

@ -55,7 +55,7 @@ const CustomerProfile = () => {
fetchOtherEmail(currentOrder)
.then(result => {
console.info(result)
// console.info(result)
})
.finally(() => setLoading(false))
.catch(reason => {

Loading…
Cancel
Save