import { useState, useEffect } from 'react' import { isEmpty } from '@/utils/commons' import { getEmailDetailAction, postResendEmailAction, } from '@/actions/EmailActions' import { App } from 'antd' import useConversationStore from '@/stores/ConversationStore'; import { msgStatusRenderMapped } from '@/channel/bubbleMsgUtils'; /** * @param mai_sn 邮件编号ID * @param data 直接传递, 不重复获取 * * 在详情点击`回复`呼出编辑时 */ export const useEmailDetail = (mai_sn, data) => { const {notification} = App.useApp() const [loading, setLoading] = useState(false) const [mailData, setMailData] = useState({ loading, info: {}, content: '', attachments: [] }) const [updateMessageItem] = useConversationStore(state => [state.updateMessageItem]); useEffect(() => { const getEmailDetail = async () => { if (isEmpty(mai_sn)) { return false } try { setLoading(true) const data = await getEmailDetailAction({ mai_sn }) setMailData(data) setLoading(false) } catch (err) { setLoading(false) notification.error({ message: "请求失败", description: err.message || '网络异常', placement: "top", duration: 3, }); } } if (isEmpty(data)) getEmailDetail() else setMailData(data) }, [mai_sn]) const postEmailResend = async ({ mai_sn, conversationid: externalid, actionId: actionid, ...body }) => { if (isEmpty(mai_sn)) { return false } await postResendEmailAction({ mai_sn, externalid, actionid, token: 0 }) // 重发没有状态返回值, 此处前端处理为'待发送', todo: 刷新页面后消息仍为上一个状态'失败' updateMessageItem({ conversationid: externalid, actionid, id: actionid, status: msgStatusRenderMapped['accepted'] }) } return { loading, mailData, postEmailResend } } export const EmailBuilder = ({subject, content}) => { return `${subject}${content}`; }