feat: 会话设置标签

2.0/email-builder
Lei OT 11 months ago
parent 3a56ed87c7
commit da74174ebf

@ -225,15 +225,15 @@ export const postConversationTags = async (body) => {
Object.keys(body).forEach(function (key) {
formData.append(key, body[key]);
});
const { errcode, result } = await fetchJSON(`${API_HOST}/set_conversation_tags_add`, formData);
return errcode !== 0 ? {} : result;
const { errcode, result } = await postForm(`${API_HOST}/v2/set_conversation_tags_add`, formData);
return errcode !== 0 ? {} : result[0];
}
/**
* 会话删除标签
* @param {object} params { opisn, conversationid, tag_id }
*/
export const deleteConversationTags = async (params) => {
const { errcode, result } = await fetchJSON(`${API_HOST}/delete_conversation_tags`, params);
const { errcode, result } = await fetchJSON(`${API_HOST}/v2/set_conversation_tags_del`, params);
return errcode !== 0 ? {} : result;
}
/**

@ -1,15 +1,15 @@
import React, { useEffect, useState } from 'react';
import { useParams, useNavigate, useLocation } from 'react-router-dom';
import { useParams, useNavigate } from 'react-router-dom';
import { Dropdown, Input, Button, Tag, Popover, Form } from 'antd';
import { CloseCircleOutlined } from '@ant-design/icons';
import { fetchConversationItemClose, fetchConversationsSearch, fetchConversationItemUnread, fetchConversationItemTop, postConversationTags, deleteConversationTags } from '@/actions/ConversationActions';
import { ChatItem } from 'react-chat-elements';
// import ConversationsNewItem from './ConversationsNewItem';
import { flush, isEmpty, stringToColour } from '@/utils/commons';
import { flush, isEmpty, isNotEmpty, stringToColour } from '@/utils/commons';
import useConversationStore from '@/stores/ConversationStore';
import useAuthStore from '@/stores/AuthStore';
import ChannelLogo from './ChannelLogo';
import { DeliverIcon, ReadIcon, SentIcon } from '@/components/Icons';
import { ReadIcon } from '@/components/Icons';
import useStyleStore from '@/stores/StyleStore';
const TagColorStyle = (tag) => {
@ -25,19 +25,14 @@ const TagColorStyle_2 = (tag, outerStyle = false) => {
const NewTagForm = ({onSubmit,...props}) => {
const [form] = Form.useForm();
const [subLoding, setSubLoding] = useState(false);
const [tags, addTag] = useConversationStore(state => [state.tags, state.addTag]);
const onFinish = async (values) => {
console.log('Received values of form[new_tag]: ', values);
// console.log('Received values of form[new_tag]: ', values);
setSubLoding(true);
if (typeof onSubmit === 'function') {
onSubmit();
await onSubmit(values.tag_label);
}
// debug:
setTimeout(() => {
setSubLoding(false);
addTag({ label: values.tag_label, key: values.tag_label, value: values.tag_label })
}, 2000);
form.resetFields();
setSubLoding(false);
}
return (
<Form
@ -68,9 +63,10 @@ const EditChatMemoForm = ({onSubmit,...props}) => {
setSubLoding(false);
}, 2000);
if (typeof onSubmit === 'function') {
onSubmit();
await onSubmit();
}
form.resetFields();
setSubLoding(false);
}
return (
<Form
@ -97,19 +93,12 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
const routerReplace = mobile === false ? true : false; // : true;
const routePrefix = mobile === false ? `/order/chat` : `/m/chat`;
const { state: orderRow } = useLocation();
const { coli_guest_WhatsApp } = orderRow || {};
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 conversationsList = useConversationStore((state) => state.conversationsList);
const [conversationsListLoading, setConversationsListLoading] = useConversationStore((state) => [state.conversationsListLoading, state.setConversationsListLoading]);
const addToConversationList = useConversationStore((state) => state.addToConversationList);
const delConversationitem = useConversationStore((state) => state.delConversationitem);
const closedConversationsList = useConversationStore((state) => state.closedConversationsList);
const setClosedConversationList = useConversationStore((state) => state.setClosedConversationList);
const itemTagsKeys = (item.tags || []).map(t => t.key);
@ -136,12 +125,20 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
setListUpdateFlag(Math.random());
}
const handleConversationItemTags = async (item, tagKey) => {
const _tags = item.tags || [];
if (_tags.includes(tagKey)) {
const handleConversationItemTags = async (item, tagKey, tagLabel) => {
const _tags = (item.tags || []).map(t => t.key);
if (isNotEmpty(tagKey) && _tags.includes(Number(tagKey))) {
await deleteConversationTags({ conversationid: item.sn, tag_id: tagKey, opisn: userId })
} else {
await postConversationTags({ conversationid: item.sn, tag_id: tagKey, opisn: userId });
const rtag = await postConversationTags({
conversationid: item.sn,
tag_id: tagKey || '',
tag_label: tagLabel || '',
opi_sn: userId,
})
if (isEmpty(tagKey)) {
addTag({ label: rtag.tag_label, key: rtag.tag_key, value: rtag.tag_key })
}
}
await refreshConversationList();
setListUpdateFlag(Math.random());
@ -174,7 +171,7 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
onOpenChange={handleContextMenuOpenChange}
menu={{
items: [
item.top_state === 1 ? { label: '取消置顶', key: 'no_top' } : { label: '置顶会话', key: 'top' },
item.top_state === 1 ? { label: '取消置顶', key: 'top' } : { label: '置顶会话', key: 'top' },
{ label: '标记为未读', key: 'unread' },
{
label: '设置标签',
@ -184,13 +181,17 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
...t,
key: `tag_${t.key}`,
style: { color: stringToColour(t.label) },
icon: itemTagsKeys.includes(t.key) ? <CloseCircleOutlined /> : false,
// icon: itemTagsKeys.includes(t.key) ? <CloseCircleOutlined className='text-red-500' /> : false,
extra: itemTagsKeys.includes(t.key) ? <CloseCircleOutlined className='text-red-500' /> : false,
})),
{
label: (
<>
<Popover content={<NewTagForm onSubmit={() => setContextMenuOpen(false)} />} placement='bottom' trigger={['click']}>
{/* todo: refresh list */}
<Popover content={<NewTagForm onSubmit={(tagLabel) => {
handleConversationItemTags(item, '', tagLabel);
setContextMenuOpen(false);
}}
/>} placement='bottom' trigger={['click']}>
<Button type='dashed' size='small' className='m-1'>
+新标签
</Button>
@ -201,23 +202,10 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
},
],
onTitleClick: ({ key, domEvent }) => {
console.log(']]]', key);
// console.log(']]]', key);
},
},
{ label: '编辑联系人', key: 'edit0' },
// {
// label: (
// <>
// {/* todo: refresh list */}
// <Popover overlayClassNam1e='w-80' content={<EditChatMemoForm onSubmit={() => setContextMenuOpen(false)} />} placement='bottom' trigger={['click']}>
// {/* <Button type='text' size='small' className='m-1'> */}
//
// {/* </Button> */}
// </Popover>
// </>
// ),
// key: 'remark',
// },
{ type: 'divider' },
{ label: '隐藏会话', key: 'close', danger: true },
],
@ -241,9 +229,6 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
case 'unread':
setContextMenuOpen(false);
return handleConversationItemUnread(item);
// case 'remark':
// setOpenTags([]);
// return;
case 'close':
setContextMenuOpen(false);
return handleConversationItemClose(item);
@ -251,7 +236,8 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
setOpenTags([]);
setEditingChat({...item, is_new: false});
return setNewChatModalVisible(true);
case 'new_tags':
return;
default:
// setContextMenuOpen(false);
console.log('unknown key', key);
@ -287,10 +273,7 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
<span><ReadIcon />最后一条消息</span>
{/* <span>最后一条消息</span> */}
<div className='text-sm'>
{[
{ label: '已付款', key: 'p1' },
{ label: '地接', key: 'p2' },
]?.map((tag) => (
{(item?.tags || [])?.map((tag) => (
<Tag key={tag.label} style={{ ...TagColorStyle(tag.label) }} className='text-xs px-0.5 me-0.5'>
{tag.label}
</Tag>

Loading…
Cancel
Save