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): Saving blank drafts (#1973)

Evan Hutnik09993b1d33c8
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsx
index 3efba1d817..49adcce7fe 100644
--- a/js/app/packages/block-email/component/BaseInput.tsx
+++ b/js/app/packages/block-email/component/BaseInput.tsx
@@ -96,6 +96,7 @@ import { makeAttachmentPublic } from '../util/makeAttachmentPublic';
import { getFirstName } from '../util/name';
import {
clearEmailBody,
+ hasDraftContent,
prepareEmailBody,
prepareMacroBody,
registerToggleAppendedThread,
@@ -635,11 +636,12 @@ export function BaseInput(props: {
);
return null;
}
- // Fail if no body text, no attachments, and no subject
if (
- prepared.bodyText.trim() === '' &&
- form().attachments.list().length === 0 &&
- !form().subject()?.trim()
+ !hasDraftContent(
+ prepared.bodyText,
+ form().subject(),
+ form().attachments.list().length
+ )
) {
return null;
}
diff --git a/js/app/packages/block-email/component/Compose.tsx b/js/app/packages/block-email/component/Compose.tsx
index a4c50cad1f..6dbd6ef8f9 100644
--- a/js/app/packages/block-email/component/Compose.tsx
+++ b/js/app/packages/block-email/component/Compose.tsx
@@ -51,6 +51,7 @@ import {
} from '@lexical-core';
import {
clearEmailBody,
+ hasDraftContent,
prepareEmailBody,
} from '@block-email/util/prepareEmailBody';
import { convertEmailRecipientToContactInfo } from '@block-email/util/recipientConversion';
@@ -270,11 +271,12 @@ export function EmailCompose(props: EmailComposeProps) {
);
return null;
}
- // Fail if no body text, no attachments, and no subject
if (
- prepared.bodyText.trim() === '' &&
- form.attachments.list().length === 0 &&
- !form.subject()?.trim()
+ !hasDraftContent(
+ prepared.bodyText,
+ form.subject(),
+ form.attachments.list().length
+ )
) {
return null;
}
diff --git a/js/app/packages/block-email/util/prepareEmailBody.ts b/js/app/packages/block-email/util/prepareEmailBody.ts
index 8e65817274..0d12ecfb78 100644
--- a/js/app/packages/block-email/util/prepareEmailBody.ts
+++ b/js/app/packages/block-email/util/prepareEmailBody.ts
@@ -488,6 +488,23 @@ export function prepareEmailBody(
return { bodyHtml, bodyText, mentions };
}
+/**
+ * Returns true if the draft has meaningful user content worth saving.
+ * Auto-filled reply/forward subjects alone don't count.
+ */
+export function hasDraftContent(
+ bodyText: string,
+ subject: string | undefined,
+ attachmentCount: number
+): boolean {
+ const hasBody = bodyText.trim() !== '';
+ const hasAttachments = attachmentCount > 0;
+ const trimmedSubject = subject?.trim() ?? '';
+ const hasSubject = trimmedSubject.length > 0;
+ const subjectIsAutoFilled = /^(Re|Fwd?):/i.test(trimmedSubject);
+ return hasBody || hasAttachments || (hasSubject && !subjectIsAutoFilled);
+}
+
export function prepareMacroBody(bodyMacro: string): string {
// Remove macro-quote blocks from the markdown string
// We want these in the HTML, but not in body_macro