From 3a56ed87c77d30180b8a61759a575db55579c37c Mon Sep 17 00:00:00 2001 From: Lei OT Date: Wed, 23 Oct 2024 14:14:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0/=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/ConversationActions.js | 11 ++++++-- src/hooks/useConversation.js | 28 +++++++++++++------ .../Online/Components/ChatListItem.jsx | 5 ++-- .../Online/ConversationsList.jsx | 4 +-- .../Online/ConversationsNewItem.jsx | 6 +++- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/actions/ConversationActions.js b/src/actions/ConversationActions.js index 4dafffa..eb9443b 100644 --- a/src/actions/ConversationActions.js +++ b/src/actions/ConversationActions.js @@ -69,12 +69,12 @@ export const fetchConversationItemClose = async (body) => { /** * @param {object} body { phone_number, name } */ -export const postNewConversationItem = async (body) => { +export const postNewOrEditConversationItem = async (body) => { const formData = new FormData(); Object.keys(body).forEach(function (key) { formData.append(key, body[key]); }); - const { errcode, result } = await postForm(`${API_HOST}/new_conversation`, formData); + const { errcode, result } = await postForm(`${API_HOST}/v2/new_conversation`, formData); if (errcode !== 0) { return {}; } @@ -83,6 +83,11 @@ export const postNewConversationItem = async (body) => { ...resultItem, customer_name: `${resultItem.whatsapp_name || ''}`.trim(), whatsapp_name: `${resultItem.whatsapp_name || ''}`.trim(), + channels: {}, + tags: [], + last_message: {}, + top_state: 0, + conversation_memo: resultItem.session_memo, }; }; @@ -108,7 +113,7 @@ export const fetchConversationItemUnread = async (body) => { * @param {object} body { conversationid, top_state } */ export const fetchConversationItemTop = async (body) => { - const { errcode, result } = await fetchJSON(`${API_HOST}/set_state_top`, body); + const { errcode, result } = await fetchJSON(`${API_HOST}/v2/set_top_conversation`, body); return errcode !== 0 ? {} : result; }; diff --git a/src/hooks/useConversation.js b/src/hooks/useConversation.js index 7f2c693..fd14b9f 100644 --- a/src/hooks/useConversation.js +++ b/src/hooks/useConversation.js @@ -1,5 +1,5 @@ import useConversationStore from '@/stores/ConversationStore'; -import { fetchOrderConversationsList, postNewConversationItem } from '@/actions/ConversationActions'; +import { fetchConversationsList, fetchOrderConversationsList, postNewOrEditConversationItem } from '@/actions/ConversationActions'; import { isEmpty } from '@/utils/commons'; export function useConversationNewItem() { const [currentConversation, setCurrentConversation] = useConversationStore((state) => [ @@ -36,15 +36,25 @@ export function useConversationNewItem() { }; /** - * 创建新会话 - * whatsappID, whatsappName + * 创建新会话/编辑会话 */ - const newConversation = async (whatsappID, whatsappName = '') => { - const { opi_sn } = currentConversation; - const newChat = { phone_number: whatsappID, remark_name: whatsappName }; - const createdNew = await postNewConversationItem({ ...newChat, opi_sn: opi_sn }); - addToConversationList([createdNew]); - setCurrentConversation(createdNew); + const newConversation = async (body) => { + const { wa_id, remark, opi_sn, conversationid } = body; + const newChat = { + whatsapp_phone_number: wa_id, + remark: remark || '', + guest_email: body.email || '', + guest_phone: body.phone_number || '', + guest_name: body.name || '', + } + const createdNew = await postNewOrEditConversationItem({ ...newChat, opi_sn, conversationid }); + // addToConversationList([{...createdNew, sn: createdNew.conversationid}]); + const _list = await fetchConversationsList({ opisn: opi_sn }); + addToConversationList(_list); + if (!body.conversationid) { + const newChat = _list.find(item => item.sn === createdNew.conversationid); + setCurrentConversation(newChat); + } }; return { openOrderContactConversation, newConversation }; diff --git a/src/views/Conversations/Online/Components/ChatListItem.jsx b/src/views/Conversations/Online/Components/ChatListItem.jsx index ec39039..fbac281 100644 --- a/src/views/Conversations/Online/Components/ChatListItem.jsx +++ b/src/views/Conversations/Online/Components/ChatListItem.jsx @@ -174,8 +174,7 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch onOpenChange={handleContextMenuOpenChange} menu={{ items: [ - { label: '置顶会话', key: 'top' }, - // { label: '取消置顶', key: 'no_top' }, + item.top_state === 1 ? { label: '取消置顶', key: 'no_top' } : { label: '置顶会话', key: 'top' }, { label: '标记为未读', key: 'unread' }, { label: '设置标签', @@ -276,7 +275,7 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch id={item.sn} letterItem={{ id: item.whatsapp_name || item.whatsapp_phone_number, letter: (item.whatsapp_name || item.whatsapp_phone_number).slice(0, 5) }} alt={item.whatsapp_name} - title={'备注 / 名称' || item.whatsapp_name || item.whatsapp_phone_number} + title={(item.top_state === 1 ? '🔝' : '') + (item.conversation_memo || item.whatsapp_name || item.whatsapp_phone_number)} // subtitle={item.coli_id} subtitle={
diff --git a/src/views/Conversations/Online/ConversationsList.jsx b/src/views/Conversations/Online/ConversationsList.jsx index 9069751..3935bcd 100644 --- a/src/views/Conversations/Online/ConversationsList.jsx +++ b/src/views/Conversations/Online/ConversationsList.jsx @@ -2,7 +2,7 @@ import React, { useEffect, useState, useRef } from 'react'; import { useParams, useNavigate, useLocation } from 'react-router-dom'; import { Dropdown, Input, Button, Empty, Tooltip, Tag, Select, Divider, Radio, Popover, theme } from 'antd'; import { PlusOutlined, WhatsAppOutlined, LoadingOutlined, HistoryOutlined, FireOutlined,AudioTwoTone, FilterOutlined, TagsOutlined, TagsTwoTone, FilterTwoTone } from '@ant-design/icons'; -import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, fetchConversationsSearch, postNewConversationItem, fetchConversationItemUnread, UNREAD_MARK } from '@/actions/ConversationActions'; +import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, fetchConversationsSearch, fetchConversationItemUnread, UNREAD_MARK } from '@/actions/ConversationActions'; import { ChatItem } from 'react-chat-elements'; import ConversationsNewItem from './ConversationsNewItem'; import { isEmpty, olog, stringToColour } from '@/utils/commons'; @@ -83,7 +83,7 @@ const Conversations = () => { // setDataSource(conversationsList); setDataSource(activeList ? conversationsList: closedConversationsList); return () => {}; - }, [conversationsList.length, listUpdateFlag, currentConversation.unread_msg_count]); + }, [conversationsList, listUpdateFlag, currentConversation.unread_msg_count]); const [switchToC, setSwitchToC] = useState({}); const [shouldFetchCList, setShouldFetchCList] = useState(true); diff --git a/src/views/Conversations/Online/ConversationsNewItem.jsx b/src/views/Conversations/Online/ConversationsNewItem.jsx index 1d2c033..337065d 100644 --- a/src/views/Conversations/Online/ConversationsNewItem.jsx +++ b/src/views/Conversations/Online/ConversationsNewItem.jsx @@ -4,6 +4,7 @@ import { isEmpty, isNotEmpty, pick } from '@/utils/commons'; import useConversationStore from '@/stores/ConversationStore'; import { phoneNumberToWAID } from '@/channel/whatsappUtils'; import { useConversationNewItem } from '@/hooks/useConversation'; +import useAuthStore from '@/stores/AuthStore'; export const ConversationItemForm = ({ initialValues, onFormInstanceReady }) => { const [currentConversation] = useConversationStore((state) => [state.currentConversation]); @@ -84,6 +85,7 @@ export const ConversationItemForm = ({ initialValues, onFormInstanceReady }) => export const ConversationItemFormModal = ({ open, onCreate, onCancel, initialValues: _initialValues, }) => { const [formInstance, setFormInstance] = useState(); const [newItemLoading, setNewItemLoading] = useState(false); + const userId = useAuthStore((state) => state.loginUser.userId); const { newConversation } = useConversationNewItem(); @@ -94,6 +96,7 @@ export const ConversationItemFormModal = ({ open, onCreate, onCancel, initialVal phone_number: _initialValues?.whatsapp_phone_number || _initialValues?.phone_number || '', wa_id: _initialValues?.whatsapp_phone_number || _initialValues?.wa_id || '', name: _initialValues?.whatsapp_name || _initialValues?.name || '', + remark: _initialValues?.conversation_memo || '', is_new: _initialValues?.is_new ?? true, }); @@ -120,8 +123,9 @@ export const ConversationItemFormModal = ({ open, onCreate, onCancel, initialVal try { const values = await formInstance?.validateFields(); // formInstance?.resetFields(); + setNewItemLoading(true); - if (initialValues.is_current_order !== true) newConversation(values.wa_id, values.name); + if (initialValues.is_current_order !== true) newConversation({...values, conversationid: _initialValues?.sn || '', opi_sn: userId}); if (typeof onCreate === 'function') { onCreate(values); }