feat: 添加/编辑会话

2.0/email-builder
Lei OT 1 year ago
parent 8cfd8ccc1a
commit 3a56ed87c7

@ -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;
};

@ -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 };

@ -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={
<div>

@ -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);

@ -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);
}

Loading…
Cancel
Save