From eecd58eb7ede810e71bc7554f038dc132cd5d182 Mon Sep 17 00:00:00 2001 From: Jessica Boezwinkle Date: Fri, 13 Jan 2023 17:31:55 +0000 Subject: [PATCH 1/2] feat: adds CC field to email --- src/collections/FormSubmissions/hooks/sendEmail.ts | 9 +++++++-- src/collections/Forms/index.ts | 10 +++++++++- src/types.ts | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/collections/FormSubmissions/hooks/sendEmail.ts b/src/collections/FormSubmissions/hooks/sendEmail.ts index 826e586..e3d525e 100644 --- a/src/collections/FormSubmissions/hooks/sendEmail.ts +++ b/src/collections/FormSubmissions/hooks/sendEmail.ts @@ -45,6 +45,8 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => { message, subject, emailTo, + cc, + bcc, emailFrom, emailFromName, replyTo: emailReplyTo, @@ -52,13 +54,17 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => { } = email; const to = replaceDoubleCurlys(emailTo, submissionData); + const ccFormatted = replaceDoubleCurlys(cc ? cc : '', submissionData); + const bccFormatted = replaceDoubleCurlys(bcc ? bcc : '', submissionData); const from = replaceDoubleCurlys(emailFromName ? `"${emailFromName}" ` + emailFrom : emailFrom, submissionData); - const replyTo = replaceDoubleCurlys(replyToName ? `"${replyToName}" ` + emailReplyTo : emailReplyTo || emailFrom, submissionData); + const replyTo = replaceDoubleCurlys(replyToName ? `"${replyToName}" ` + emailReplyTo : emailReplyTo || emailFrom, submissionData); if (to && from) { return ({ to, from, + cc: ccFormatted, + bcc: bccFormatted, replyTo, subject: replaceDoubleCurlys(subject, submissionData), html: `
${serialize(message, submissionData)}
` @@ -72,7 +78,6 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => { if (typeof beforeEmail === 'function') { emailsToSend = await beforeEmail(formattedEmails); } - const log = emailsToSend.map(({ html, ...rest }) => ({ ...rest })) await Promise.all( diff --git a/src/collections/Forms/index.ts b/src/collections/Forms/index.ts index c0bc39f..471520e 100644 --- a/src/collections/Forms/index.ts +++ b/src/collections/Forms/index.ts @@ -155,10 +155,18 @@ export const generateFormCollection = (formConfig: PluginConfig): CollectionConf label: 'Email To', required: true, admin: { - width: '50%', + width: '100%', placeholder: 'Email Sender ' }, }, + { + type: 'text', + name: 'cc', + label: 'CC', + admin: { + width: '50%', + }, + }, { type: 'text', name: 'bcc', diff --git a/src/types.ts b/src/types.ts index 8d091ac..2755e38 100644 --- a/src/types.ts +++ b/src/types.ts @@ -157,6 +157,7 @@ export type Email = { emailTo: string emailFrom: string emailFromName?: string + cc?: string bcc?: string replyTo?: string replyToName?: string @@ -166,6 +167,8 @@ export type Email = { export type FormattedEmail = { to: string + cc?: string + bcc?: string from: string subject: string html: string From e1750b4e6a4054eef58374787a5971e66af5f432 Mon Sep 17 00:00:00 2001 From: Jessica Boezwinkle Date: Fri, 13 Jan 2023 17:36:08 +0000 Subject: [PATCH 2/2] chore: remove unnecessary code --- src/collections/FormSubmissions/hooks/sendEmail.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/collections/FormSubmissions/hooks/sendEmail.ts b/src/collections/FormSubmissions/hooks/sendEmail.ts index e3d525e..97edb1d 100644 --- a/src/collections/FormSubmissions/hooks/sendEmail.ts +++ b/src/collections/FormSubmissions/hooks/sendEmail.ts @@ -45,8 +45,8 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => { message, subject, emailTo, - cc, - bcc, + cc: emailCC, + bcc: emailBCC, emailFrom, emailFromName, replyTo: emailReplyTo, @@ -54,8 +54,8 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => { } = email; const to = replaceDoubleCurlys(emailTo, submissionData); - const ccFormatted = replaceDoubleCurlys(cc ? cc : '', submissionData); - const bccFormatted = replaceDoubleCurlys(bcc ? bcc : '', submissionData); + const cc = emailCC ? replaceDoubleCurlys(emailCC, submissionData) : ''; + const bcc = emailBCC ? replaceDoubleCurlys(emailBCC, submissionData) : ''; const from = replaceDoubleCurlys(emailFromName ? `"${emailFromName}" ` + emailFrom : emailFrom, submissionData); const replyTo = replaceDoubleCurlys(replyToName ? `"${replyToName}" ` + emailReplyTo : emailReplyTo || emailFrom, submissionData); @@ -63,8 +63,8 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => { return ({ to, from, - cc: ccFormatted, - bcc: bccFormatted, + cc, + bcc, replyTo, subject: replaceDoubleCurlys(subject, submissionData), html: `
${serialize(message, submissionData)}
`