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): improve scheduled send validation and recipient handling (#2255)

Evan Hutnikc61c84595590
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsx
index 14b3d98e74..eace14fb6a 100644
--- a/js/app/packages/block-email/component/BaseInput.tsx
+++ b/js/app/packages/block-email/component/BaseInput.tsx
@@ -81,6 +81,7 @@ import {
For,
type JSX,
Match,
+ on,
onCleanup,
onMount,
type Setter,
@@ -646,7 +647,10 @@ export function BaseInput(props: {
!hasDraftContent(
prepared.bodyText,
form().subject(),
- form().attachments.list().length
+ form().attachments.list().length,
+ form().recipients().to.length +
+ form().recipients().cc.length +
+ form().recipients().bcc.length
)
) {
return null;
@@ -1225,6 +1229,23 @@ export function BaseInput(props: {
}
};
+ // Unschedule when all recipients are removed
+ const totalRecipientCount = () => {
+ const r = form().recipients();
+ return r.to.length + r.cc.length + r.bcc.length;
+ };
+ createEffect(
+ on(
+ totalRecipientCount,
+ (count) => {
+ if (count === 0 && form().sendTime()) {
+ handleSendTimeChange(null);
+ }
+ },
+ { defer: true }
+ )
+ );
+
const isDraftSaving = () => saveDraftMutation.isPending;
const laggedIsDraftSaving = stickyGate(isDraftSaving, 250);
@@ -1629,6 +1650,11 @@ export function BaseInput(props: {
<EmailDateSelector
sendTime={form().sendTime() ?? null}
onSendTimeChange={handleSendTimeChange}
+ disabled={
+ form().recipients().to.length === 0 &&
+ form().recipients().cc.length === 0 &&
+ form().recipients().bcc.length === 0
+ }
disablePortal={isMobile()}
/>
</Show>
diff --git a/js/app/packages/block-email/component/Compose.tsx b/js/app/packages/block-email/component/Compose.tsx
index a7961fe259..d65bb35c24 100644
--- a/js/app/packages/block-email/component/Compose.tsx
+++ b/js/app/packages/block-email/component/Compose.tsx
@@ -28,9 +28,11 @@ import {
} from '@queries/email/thread';
import {
type Accessor,
+ createEffect,
createMemo,
createSignal,
type JSX,
+ on,
onMount,
Show,
Suspense,
@@ -273,7 +275,10 @@ export function EmailCompose(props: EmailComposeProps) {
!hasDraftContent(
prepared.bodyText,
form.subject(),
- form.attachments.list().length
+ form.attachments.list().length,
+ form.recipients().to.length +
+ form.recipients().cc.length +
+ form.recipients().bcc.length
)
) {
return null;
@@ -733,6 +738,23 @@ export function EmailCompose(props: EmailComposeProps) {
}
};
+ // Unschedule when all recipients are removed
+ const totalRecipientCount = () => {
+ const r = form.recipients();
+ return r.to.length + r.cc.length + r.bcc.length;
+ };
+ createEffect(
+ on(
+ totalRecipientCount,
+ (count) => {
+ if (count === 0 && form.sendTime()) {
+ handleSendTimeChange(null);
+ }
+ },
+ { defer: true }
+ )
+ );
+
const resetState = () => {
clearEmailBody(editor());
setContent('');
@@ -1051,6 +1073,11 @@ export function EmailCompose(props: EmailComposeProps) {
attachments={form.attachments.list()}
sendTime={form.sendTime()}
onSendTimeChange={handleSendTimeChange}
+ scheduleSendDisabled={
+ form.recipients().to.length === 0 &&
+ form.recipients().cc.length === 0 &&
+ form.recipients().bcc.length === 0
+ }
onSubmit={() => void onSubmit()}
isSubmitting={sendMutation.isPending}
isDraftSaving={laggedIsDraftSaving()}
diff --git a/js/app/packages/block-email/component/ComposeEmailInput.tsx b/js/app/packages/block-email/component/ComposeEmailInput.tsx
index 8478ffc508..22ef044b79 100644
--- a/js/app/packages/block-email/component/ComposeEmailInput.tsx
+++ b/js/app/packages/block-email/component/ComposeEmailInput.tsx
@@ -71,6 +71,7 @@ type ComposeEmailInputProps = {
onContentChange?: (content: string) => void;
sendTime?: Date | null;
onSendTimeChange?: (date: Date | null) => void;
+ scheduleSendDisabled?: boolean;
mobileScrollRef?: Accessor<HTMLElement | undefined>;
};
@@ -339,6 +340,7 @@ export function ComposeEmailInput(props: ComposeEmailInputProps) {
<EmailDateSelector
sendTime={props.sendTime}
onSendTimeChange={props.onSendTimeChange}
+ disabled={props.scheduleSendDisabled}
compact
/>
</Show>
@@ -406,6 +408,7 @@ export function ComposeEmailInput(props: ComposeEmailInputProps) {
<EmailDateSelector
sendTime={props.sendTime}
onSendTimeChange={props.onSendTimeChange}
+ disabled={props.scheduleSendDisabled}
/>
</Show>
<Show when={props.hasDraft && !props.isDraftSaving}>
diff --git a/js/app/packages/block-email/component/date-selector.tsx b/js/app/packages/block-email/component/date-selector.tsx
index 5c40c2ba26..11a4ee1a31 100644
--- a/js/app/packages/block-email/component/date-selector.tsx
+++ b/js/app/packages/block-email/component/date-selector.tsx
@@ -42,6 +42,7 @@ type DateSelectorProps = {
withTime?: boolean;
/** Render content inline instead of in a portal (avoids keyboard positioning issues on mobile) */
disablePortal?: boolean;
+ disabled?: boolean;
trigger?:
| JSX.Element
| ((props: { selectedDate: Date | null }) => JSX.Element);
@@ -264,6 +265,7 @@ export const DateSelector = (props: DateSelectorProps) => {
return (
<Combobox<DateSelectorOption>
open={isOpen()}
+ disabled={props.disabled}
multiple={false}
value={selectedOption()}
options={options()}
diff --git a/js/app/packages/block-email/component/email-date-selector.tsx b/js/app/packages/block-email/component/email-date-selector.tsx
index c641565979..99bda6028b 100644
--- a/js/app/packages/block-email/component/email-date-selector.tsx
+++ b/js/app/packages/block-email/component/email-date-selector.tsx
@@ -16,6 +16,8 @@ interface EmailDateSelectorProps {
compact?: boolean;
/** Render content inline instead of in a portal */
disablePortal?: boolean;
+ /** Disable the schedule button */
+ disabled?: boolean;
}
export const EmailDateSelector: VoidComponent<EmailDateSelectorProps> = (
props
@@ -26,6 +28,7 @@ export const EmailDateSelector: VoidComponent<EmailDateSelectorProps> = (
<DateSelector
selectedDate={props.sendTime}
onSelectDate={props.onSendTimeChange}
+ disabled={props.disabled}
disablePriorToDate={new Date()}
disableAfterDate={addYears(new Date(), 1)}
disablePortal={props.disablePortal}
@@ -46,6 +49,7 @@ export const EmailDateSelector: VoidComponent<EmailDateSelectorProps> = (
>
<Button
size="icon-sm"
+ disabled={props.disabled}
class={cn(
showExpanded() &&
'size-auto gap-1 bg-accent/20 text-accent-ink hover:!bg-accent/15 hover:!text-accent-ink'
diff --git a/js/app/packages/block-email/util/prepareEmailBody.ts b/js/app/packages/block-email/util/prepareEmailBody.ts
index fdbcb8ad4e..abcf08921c 100644
--- a/js/app/packages/block-email/util/prepareEmailBody.ts
+++ b/js/app/packages/block-email/util/prepareEmailBody.ts
@@ -514,14 +514,21 @@ export function prepareEmailBody(
export function hasDraftContent(
bodyText: string,
subject: string | undefined,
- attachmentCount: number
+ attachmentCount: number,
+ recipientCount?: number
): boolean {
const hasBody = bodyText.trim() !== '';
const hasAttachments = attachmentCount > 0;
+ const hasRecipients = (recipientCount ?? 0) > 0;
const trimmedSubject = subject?.trim() ?? '';
const hasSubject = trimmedSubject.length > 0;
const subjectIsAutoFilled = /^(Re|Fwd?):/i.test(trimmedSubject);
- return hasBody || hasAttachments || (hasSubject && !subjectIsAutoFilled);
+ return (
+ hasBody ||
+ hasAttachments ||
+ hasRecipients ||
+ (hasSubject && !subjectIsAutoFilled)
+ );
}
export function prepareMacroBody(bodyMacro: string): string {