feat: 主动收邮件: 结果提示

2.0/email-builder
Lei OT 11 months ago
parent f9364d21df
commit 118acc6671

@ -305,6 +305,22 @@ const emailMsgMapped = {
sender: 'me',
dateString: msgcontent.status==='failed' ? `发送失败 ❌` : '',
}),
},
'email.action.received': {
getMsg: (result) => {
return isEmpty(result?.emailMessage) ? null : { ...result.emailMessage, };
},
contentToRender: (contentObj) => null,
contentToUpdate: (msgcontent) => null,
contentToNotify: (contentObj) => {
return {
...contentObj,
status: contentObj?.status || 'failed',
content: `${contentObj?.error?.message || ''}`,
title: (contentObj.status === 'failed') ? `接收${contentObj.email}邮件失败` : '',
type: (contentObj.status === 'failed') ? 'warning' : 'info',
};
},
}
}
export const msgStatusRenderMapped = {

@ -52,6 +52,14 @@ const initialConversationState = {
};
const globalNotifySlice = (set) => ({
globalNotify: [],
setGlobalNotify: (notify) => set(() => ({ globalNotify: notify })),
addGlobalNotify: (notify) => set((state) => ({ globalNotify: [...state.globalNotify, notify] })),
removeGlobalNotify: (id) => set((state) => ({ globalNotify: state.globalNotify.filter(item => item.id !== id) })),
clearGlobalNotify: () => set(() => ({ globalNotify: [] })),
})
// 顾问的自定义标签
const tagsSlice = (set) => ({
tags: [],
@ -143,7 +151,7 @@ const websocketSlice = (set, get) => ({
handleMessage: (data) => {
olog('handleMessage------------------');
// console.log(data);
const { updateMessageItem, sentOrReceivedNewMessage } = get();
const { updateMessageItem, sentOrReceivedNewMessage, addGlobalNotify } = get();
const { errcode, errmsg, result } = data;
if (!result) {
@ -172,6 +180,12 @@ const websocketSlice = (set, get) => ({
...(msgRender.type === 'photo' ? { image: msgRender.data.uri } : {}),
});
}
if ([
'email.action.received',
].includes(resultType)) {
const msgNotify = receivedMsgTypeMapped[resultType].contentToNotify(msgObj);
addGlobalNotify(msgNotify);
}
console.log('handleMessage*******************');
},
});
@ -405,6 +419,7 @@ export const useConversationStore = create(
...complexMsgSlice(set, get),
...tagsSlice(set, get),
...filterSlice(set, get),
...globalNotifySlice(set, get),
// state actions
addError: (error) => set((state) => ({ errors: [...state.errors, error] })),

@ -3,11 +3,39 @@ import { App, Tooltip, Button } from 'antd'
import { PlusOutlined, LoadingOutlined, HistoryOutlined, FireOutlined, AudioTwoTone } from '@ant-design/icons'
import { getEmailFetchAction, getAllEmailFetchAction } from '@/actions/EmailActions'
import useAuthStore from '@/stores/AuthStore'
import useConversationStore from '@/stores/ConversationStore'
import { MailDownloadIcon } from '@/components/Icons'
import { isEmpty } from '@/utils/commons'
const EmailFetch = ({ ...props }) => {
const { message } = App.useApp()
const { notification, message } = App.useApp()
const { userId, emailList } = useAuthStore((state) => state.loginUser)
const [globalNotify, clearGlobalNotify] = useConversationStore((state) => [state.globalNotify, state.clearGlobalNotify]);
useEffect(() => {
if (isEmpty(globalNotify)) {
return () => {}
}
// message.info(globalNotify[0].content, 3)
notification.open({
key: globalNotify[0].id,
message: globalNotify[0].title,
description: globalNotify[0].content,
duration: 3,
placement: 'top',
type: globalNotify[0].type,
onClick: () => {
clearGlobalNotify()
},
})
setTimeout(() => {
clearGlobalNotify()
}, 3030)
return () => {}
}, [globalNotify])
const [getEmailLoading, setEmailLoading] = useState(false)
const [fetchingText, setFetchingText] = useState('收邮件')
const handleGetEmail = async () => {

Loading…
Cancel
Save