|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
import { createContext, useEffect, useState } from 'react';
|
|
|
|
|
import { ConfigProvider, Button, Form, Input, Flex, Checkbox, Switch, Mentions, Popover, Popconfirm, Select, Space, Upload, Divider } from 'antd';
|
|
|
|
|
import { DashOutlined, EllipsisOutlined, MenuOutlined, MoreOutlined, UploadOutlined } from '@ant-design/icons';
|
|
|
|
|
import Modal from '@dckj/react-better-modal';
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { App, ConfigProvider, Button, Form, Input, Flex, Checkbox, Popconfirm, Select, Space, Upload, Divider } from 'antd';
|
|
|
|
|
import { UploadOutlined } from '@ant-design/icons';
|
|
|
|
|
import '@dckj/react-better-modal/dist/index.css';
|
|
|
|
|
import DnDModal from '@/components/DndModal';
|
|
|
|
|
import useStyleStore from '@/stores/StyleStore';
|
|
|
|
@ -14,7 +13,8 @@ import { v4 as uuid } from 'uuid';
|
|
|
|
|
import { isEmpty } from '@/utils/commons';
|
|
|
|
|
import './EmailEditor.css';
|
|
|
|
|
import { postSendEmail } from '@/actions/EmailActions';
|
|
|
|
|
import { sentMsgTypeMapped, whatsappSupportFileTypes, uploadProgressSimulate } from '@/channel/bubbleMsgUtils';
|
|
|
|
|
import { sentMsgTypeMapped, } from '@/channel/bubbleMsgUtils';
|
|
|
|
|
import { useEmailDetail } from '@/hooks/useEmail';
|
|
|
|
|
|
|
|
|
|
const getAbstract = (longtext) => {
|
|
|
|
|
const lines = longtext.split('\n');
|
|
|
|
@ -23,11 +23,48 @@ const getAbstract = (longtext) => {
|
|
|
|
|
return abstract;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, reference, quote = {}, initial = {}, action = 'reply', ...props }) => {
|
|
|
|
|
const generateQuoteContent = (mailData) => `<br><br>
|
|
|
|
|
<hr>
|
|
|
|
|
<p>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >From: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${mailData.info?.MAI_From || ''} </span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >Sent: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${mailData.info?.MAI_SendDate || ''}</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >To: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${mailData.info?.MAI_To || ''}</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >Subject: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${mailData.info.subject || ''}</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
${mailData.content}
|
|
|
|
|
</p>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, conversationid, quoteid, initial = {}, mailData: _mailData, action = 'reply', ...props }) => {
|
|
|
|
|
const [mobile] = useStyleStore((state) => [state.mobile]);
|
|
|
|
|
const [userId, username, emailList] = useAuthStore((state) => [state.loginUser.userId, state.loginUser.username, state.loginUser.emailList]);
|
|
|
|
|
const emailListOption = emailList?.map(ele => ({ ...ele, label: ele.email, key: ele.email, value: ele.email })) || [];
|
|
|
|
|
|
|
|
|
|
const mai_sn = quoteid;
|
|
|
|
|
const mailData = useEmailDetail(mai_sn, _mailData);
|
|
|
|
|
|
|
|
|
|
const emailUser = mailData.info?.MAI_OPI_SN || fromUser // quote.order_opi
|
|
|
|
|
|
|
|
|
|
const { notification, message } = App.useApp();
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
|
|
const [isRichText, setIsRichText] = useState(mobile === false);
|
|
|
|
@ -56,51 +93,31 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, reference, quote
|
|
|
|
|
const [newFromEmail, setNewFromEmail] = useState('');
|
|
|
|
|
const [initialForm, setInitialForm] = useState({});
|
|
|
|
|
const [initialContent, setInitialContent] = useState('');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载邮件数据
|
|
|
|
|
*/
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isEmpty(quote)) {
|
|
|
|
|
// console.log('quoteid', quoteid, isEmpty(quoteid), isEmpty(mailData.info));
|
|
|
|
|
|
|
|
|
|
if (isEmpty(quoteid)) {
|
|
|
|
|
return () => {};
|
|
|
|
|
}
|
|
|
|
|
setShowCc(!isEmpty(quote.cc));
|
|
|
|
|
const { from, email: { subject, content, mai_sn } } = quote;
|
|
|
|
|
const preQuoteBody = `<br><br>
|
|
|
|
|
<hr>
|
|
|
|
|
<p>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >From: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${quote.from} </span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >Sent: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${quote.sendTime || ''}</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >To: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${quote.to}</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >Subject: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${subject}</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
${content}
|
|
|
|
|
</p>
|
|
|
|
|
`;
|
|
|
|
|
const { info, } = mailData
|
|
|
|
|
setShowCc(!isEmpty(mailData.info?.MAI_CS));
|
|
|
|
|
|
|
|
|
|
const preQuoteBody = generateQuoteContent(mailData);
|
|
|
|
|
|
|
|
|
|
if ( !isEmpty(mailData.info))
|
|
|
|
|
setInitialContent(preQuoteBody);
|
|
|
|
|
|
|
|
|
|
setInitialContent(preQuoteBody);
|
|
|
|
|
const _formValues = {
|
|
|
|
|
to: from || fromEmail,
|
|
|
|
|
cc: quote.cc || '',
|
|
|
|
|
bcc: quote.bcc || '',
|
|
|
|
|
subject: `Re: ${subject}`,
|
|
|
|
|
to: info?.MAI_From || fromEmail,
|
|
|
|
|
cc: info?.MAI_CS || '',
|
|
|
|
|
// bcc: quote.bcc || '',
|
|
|
|
|
subject: `Re: ${info.subject || ''}`,
|
|
|
|
|
};
|
|
|
|
|
const forwardValues = { subject: `Fw: ${subject}` };
|
|
|
|
|
const forwardValues = { subject: `Fw: ${info.subject || ''}` };
|
|
|
|
|
if (action === 'reply') {
|
|
|
|
|
form.setFieldsValue(_formValues);
|
|
|
|
|
setInitialForm(_formValues);
|
|
|
|
@ -110,7 +127,7 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, reference, quote
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [quote, open]);
|
|
|
|
|
}, [open, mailData.info]);
|
|
|
|
|
|
|
|
|
|
const [openPlainTextConfirm, setOpenPlainTextConfirm] = useState(false);
|
|
|
|
|
const handlePlainTextOpenChange = ({ target }) => {
|
|
|
|
@ -181,7 +198,7 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, reference, quote
|
|
|
|
|
status: 'waiting',
|
|
|
|
|
...msgObj,
|
|
|
|
|
// id: `${currentConversation.sn}.${msgObj.id}`,
|
|
|
|
|
id: `1148.${msgObj.id}`,
|
|
|
|
|
id: `${conversationid}.${msgObj.id}`,
|
|
|
|
|
};
|
|
|
|
|
// olog('invoke upload', msgObjMerge)
|
|
|
|
|
const contentToRender = sentMsgTypeMapped[msgObjMerge.type].contentToRender(msgObjMerge);
|
|
|
|
@ -197,9 +214,10 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, reference, quote
|
|
|
|
|
const body = structuredClone(form.getFieldsValue());
|
|
|
|
|
body.mailcontent = isRichText ? htmlContent : textContent;
|
|
|
|
|
body.from = newFromEmail || fromEmail;
|
|
|
|
|
body.to = 'lyt@hainatravel.com'; // debug: 0
|
|
|
|
|
body.attaList = fileList;
|
|
|
|
|
body.opi_sn = fromUser;
|
|
|
|
|
body.mat_sn = 278;
|
|
|
|
|
body.opi_sn = emailUser || fromUser;
|
|
|
|
|
body.mat_sn = 278; // todo: 从配置中获取
|
|
|
|
|
console.log('body', body);
|
|
|
|
|
const values = await form.validateFields();
|
|
|
|
|
const msgObj = {
|
|
|
|
@ -214,12 +232,25 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, reference, quote
|
|
|
|
|
content: body.mailcontent,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
invokeEmailMessage(msgObj);
|
|
|
|
|
setSendLoading(true);
|
|
|
|
|
const result = await postSendEmail(body);
|
|
|
|
|
body.externalID = conversationid;
|
|
|
|
|
body.actionID = `${conversationid}.${msgObj.id}`;
|
|
|
|
|
try {
|
|
|
|
|
const result = await postSendEmail(body);
|
|
|
|
|
setSendLoading(false);
|
|
|
|
|
|
|
|
|
|
invokeEmailMessage(msgObj);
|
|
|
|
|
setOpen(false);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
notification.error({
|
|
|
|
|
message: "邮件保存失败",
|
|
|
|
|
// description: error,
|
|
|
|
|
placement: "top",
|
|
|
|
|
// duration: 60,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
setSendLoading(false);
|
|
|
|
|
setOpen(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
@ -229,11 +260,11 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, reference, quote
|
|
|
|
|
rootClassName='email-editor-wrapper !border-indigo-300 '
|
|
|
|
|
open={open}
|
|
|
|
|
setOpen={setOpen}
|
|
|
|
|
initial={{ top: isEmpty(reference) ? 20 : 74 }}
|
|
|
|
|
initial={{ top: isEmpty(quoteid) ? 20 : 74 }}
|
|
|
|
|
onCancel={() => {
|
|
|
|
|
form.resetFields();
|
|
|
|
|
}}
|
|
|
|
|
title={initialForm.subject || `${isEmpty(quote) ? '回复: ' : '写邮件: '} ${fromEmail || ''}`}
|
|
|
|
|
title={initialForm.subject || `${isEmpty(quoteid) ? '回复: ' : '写邮件: '} ${fromEmail || ''}`}
|
|
|
|
|
footer={
|
|
|
|
|
<div className='w-full flex gap-6 justify-start items-center text-indigo-600'>
|
|
|
|
|
<Button type='primary' onClick={onHandleSend} loading={sendLoading}>
|
|
|
|
|