diff --git a/src/views/NewEmail.jsx b/src/views/NewEmail.jsx index 4bd74a5..8e7e43d 100644 --- a/src/views/NewEmail.jsx +++ b/src/views/NewEmail.jsx @@ -46,14 +46,15 @@ const parseHTMLText = (html) => { const parser = new DOMParser() const dom = parser.parseFromString(html, 'text/html') // Replace
and

with line breaks - Array.from(dom.body.querySelectorAll('br, p')).forEach((el) => { - el.textContent = '\n' + el.textContent - }) + // Array.from(dom.body.querySelectorAll('br, p')).forEach((el) => { + // el.textContent = '
' + el.textContent + // }) // Replace


with a line of dashes - Array.from(dom.body.querySelectorAll('hr')).forEach((el) => { - el.textContent = '\n------------------------------------------------------------------\n' - }) - return dom.body.textContent || '' + // Array.from(dom.body.querySelectorAll('hr')).forEach((el) => { + // el.innerHTML = '


------------------------------------------------------------------

' + // }) + const line = '

------------------------------------------------------------------

' + return line+(dom.body.innerHTML || '') } const generateQuoteContent = (mailData, isRichText = true) => { @@ -199,6 +200,8 @@ const NewEmail = () => { mat_sn: emailAccount?.mat_sn || info?.MAI_MAT_SN || defaultMAT, opi_sn: emailAccount?.opi_sn || info?.MAI_OPI_SN || orderDetail.opi_sn || '', } + const originalContentType = info?.mailType === 'text/html'; + setIsRichText(originalContentType) let readyToInitialContent = ''; let _formValues = {}; @@ -225,6 +228,7 @@ const NewEmail = () => { subject: `Re: ${info.MAI_Subject || ''}`, ..._form2 } + readyToInitialContent += generateQuoteContent(mailData, originalContentType) break case 'replyall': _formValues = { @@ -235,6 +239,7 @@ const NewEmail = () => { subject: `Re: ${info.MAI_Subject || ''}`, ..._form2 } + readyToInitialContent += generateQuoteContent(mailData, originalContentType) break case 'forward': _formValues = { @@ -243,6 +248,7 @@ const NewEmail = () => { // coli_sn: pageParam.oid, ..._form2 } + readyToInitialContent += generateQuoteContent(mailData, originalContentType) break case 'edit': _formValues = { @@ -341,12 +347,14 @@ const NewEmail = () => { } const handleEditorChange = ({ editorStateJSON, htmlContent, textContent }) => { - // console.log('textContent', textContent); + const _text = textContent.replace(/\r\n/g, '\n').replace(/\n{2,}/g, '\n') + // console.log('textContent---\n', textContent, 'textContent'); // console.log('html', html); setHtmlContent(htmlContent) - setTextContent(textContent) + setTextContent(_text) form.setFieldValue('content', htmlContent) - const { bodyText: abstract } = parseHTMLString(htmlContent, true); + const abstract = _text; + // const { bodyText: abstract } = parseHTMLString(htmlContent, true); // form.setFieldValue('abstract', getAbstract(textContent)) const formValues = omitEmpty(form.getFieldsValue()); if (!isEmpty(formValues)) { @@ -496,8 +504,8 @@ const NewEmail = () => { body.attaList = fileList; // console.log('body', body, '\n', fileList); const values = await form.validateFields() - const preQuoteBody = !['edit', 'new'].includes(pageParam.action) && pageParam.quoteid ? (quoteContent ? quoteContent : generateQuoteContent(mailData, isRichText)) : '' - body.mailcontent = isRichText ? EmailBuilder({ subject: values.subject, content: htmlContent + preQuoteBody }) : textContent + preQuoteBody + // const preQuoteBody = !['edit', 'new'].includes(pageParam.action) && pageParam.quoteid ? (quoteContent ? quoteContent : generateQuoteContent(mailData, isRichText)) : '' + body.mailcontent = isRichText ? EmailBuilder({ subject: values.subject, content: htmlContent }) : textContent body.cc = values.cc || '' body.bcc = values.bcc || '' body.bcc = values.mailtype || '' @@ -517,6 +525,8 @@ const NewEmail = () => { try { // console.log('postSendEmail', body, '\n'); + // console.log('🎈postSendEmail mailContent', body.mailcontent, '\n'); + // throw new Error('test') // return; const mailSavedId = await postEmailSaveOrSend(body, isDraft) form.setFieldsValue({ @@ -703,20 +713,17 @@ const NewEmail = () => { - {!isEmpty(Number(pageParam.quoteid)) && pageParam.action!=='edit' && !showQuoteContent && ( + {/* {!isEmpty(Number(pageParam.quoteid)) && pageParam.action!=='edit' && !showQuoteContent && (
- {/* */}
)} - {/* {showQuoteContent && ( + {showQuoteContent && (