Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(email): prevent duplicate Sent with Macro watermarks on failed validation (#2336)

Evan Hutnik4efc14b750ad
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsx
index 26dafa7cab..e25a7e5506 100644
--- a/js/app/packages/block-email/component/BaseInput.tsx
+++ b/js/app/packages/block-email/component/BaseInput.tsx
@@ -919,9 +919,13 @@ export function BaseInput(props: {
}
}
- // We handle cleaning up the signature after we've sent the request because
- // otherwise the `bodyMacro` signal would update after the clean up call and
- // not contain the signature in the request data
+ // Failsafe: don't send if a scheduled send time is set
+ if (form().sendTime()) {
+ return;
+ }
+
+ // Append watermark after all validation passes so failed sends don't
+ // leave orphaned watermark nodes in the editor tree.
const cleanupWatermark = $appendWatermarkNodeToLast(
currentEditor,
!hasPaidAccess() ? MACRO_EMAIL_SIGNATURE : undefined
@@ -939,6 +943,7 @@ export function BaseInput(props: {
: undefined
);
if (!prepared) {
+ cleanupWatermark();
return;
}
@@ -949,12 +954,6 @@ export function BaseInput(props: {
const currentDraftID = savedDraftId();
- // Failsafe: don't send if a scheduled send time is set
- if (form().sendTime()) {
- cleanupWatermark();
- return;
- }
-
sendMutation.mutate({
message: {
db_id: currentDraftID,
diff --git a/js/app/packages/block-email/component/compose/Compose.tsx b/js/app/packages/block-email/component/compose/Compose.tsx
index 9f7e67c072..f6b7051262 100644
--- a/js/app/packages/block-email/component/compose/Compose.tsx
+++ b/js/app/packages/block-email/component/compose/Compose.tsx
@@ -356,22 +356,6 @@ export function EmailCompose(props: EmailComposeProps) {
}
}
- const cleanupWatermark = $appendWatermarkNodeToLast(
- currentEditor,
- !hasPaidAccess() ? MACRO_EMAIL_SIGNATURE : undefined
- );
-
- const prepared = prepareEmailBody(currentEditor, undefined);
- if (!prepared) return;
-
- const bodyMacro = content();
-
- const data = {
- text: prepared.bodyText,
- html: prepared.bodyHtml,
- raw: bodyMacro,
- };
-
const currentLink = link();
const recipients = form.recipients();
@@ -383,7 +367,7 @@ export function EmailCompose(props: EmailComposeProps) {
return;
}
- if (!data.raw.trim()) {
+ if (!content().trim()) {
setValidationError({
type: 'no_message',
message: 'Please enter a message',
@@ -412,6 +396,21 @@ export function EmailCompose(props: EmailComposeProps) {
return;
}
+ // Append watermark after all validation passes so failed sends don't
+ // leave orphaned watermark nodes in the editor tree.
+ const cleanupWatermark = $appendWatermarkNodeToLast(
+ currentEditor,
+ !hasPaidAccess() ? MACRO_EMAIL_SIGNATURE : undefined
+ );
+
+ const prepared = prepareEmailBody(currentEditor, undefined);
+ if (!prepared) {
+ cleanupWatermark();
+ return;
+ }
+
+ const bodyMacro = content();
+
sendMutation.mutate({
message: {
to: convertToContactInfoArray(recipients.to),
@@ -424,9 +423,9 @@ export function EmailCompose(props: EmailComposeProps) {
? convertToContactInfoArray(recipients.bcc)
: [],
subject: form.subject(),
- body_text: data.text,
- body_html: data.html,
- body_macro: data.raw,
+ body_text: prepared.bodyText,
+ body_html: prepared.bodyHtml,
+ body_macro: bodyMacro,
db_id: currentDraftID(),
},
});