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(calendar): send only changed fields when updating reminders (#7337)

gbirman2ba6152d094d
diff --git a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
index 8b30c6d522..1068106e6c 100644
--- a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
+++ b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.test.ts
@@ -64,6 +64,79 @@ function controllerFor(
});
}
+describe('recurrence submission', () => {
+ const originalRule =
+ 'RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR';
+ const recurringValue = {
+ title: 'Prod Deploy',
+ start: '2026-10-01T18:00',
+ end: '2026-10-01T18:30',
+ recurrenceLines: [originalRule],
+ };
+
+ it('preserves the original rule when a recurrence edit is reverted', () => {
+ const controller = controllerFor(recurringValue, { isEdit: true });
+ controller.changeRecurrenceChoice('daily');
+ expect(controller.submitValues()?.recurrenceLines).toEqual([
+ 'RRULE:FREQ=DAILY',
+ ]);
+ controller.changeRecurrenceChoice('weekdays');
+ expect(controller.submitValues()?.recurrenceLines).toEqual([originalRule]);
+ });
+
+ it('still submits recurrence removal', () => {
+ const controller = controllerFor(recurringValue, { isEdit: true });
+ controller.changeRecurrenceChoice('none');
+ expect(controller.submitValues()?.recurrenceLines).toEqual([]);
+ });
+
+ it('still submits custom recurrence edits', () => {
+ const controller = controllerFor(recurringValue, { isEdit: true });
+ controller.changeRecurrenceChoice('custom');
+ controller.setCustomConfig((config) => ({ ...config, interval: 2 }));
+ expect(controller.submitValues()?.recurrenceLines).toEqual([
+ 'RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR',
+ ]);
+ });
+
+ it('updates a date-dependent preset when the start day changes', () => {
+ const controller = controllerFor(
+ { ...recurringValue, recurrenceLines: ['RRULE:FREQ=WEEKLY;BYDAY=TH'] },
+ { isEdit: true }
+ );
+ controller.setStart('2026-10-02T18:00');
+ controller.setField('end', '2026-10-02T18:30');
+ expect(controller.submitValues()?.recurrenceLines).toEqual([
+ 'RRULE:FREQ=WEEKLY;BYDAY=FR',
+ ]);
+ });
+
+ it('converts UNTIL when changing a timed event to all-day', () => {
+ const controller = controllerFor(
+ {
+ ...recurringValue,
+ recurrenceLines: ['RRULE:FREQ=DAILY;UNTIL=20261231T180000Z'],
+ },
+ { isEdit: true }
+ );
+ controller.setAllDay(true);
+ expect(controller.submitValues()?.recurrenceLines).toEqual([
+ 'RRULE:FREQ=DAILY;UNTIL=20261231',
+ ]);
+ });
+
+ it('uses the new original rule after replacing external values', () => {
+ const controller = controllerFor(recurringValue, { isEdit: true });
+ controller.changeRecurrenceChoice('daily');
+ const nextRule = 'RRULE:INTERVAL=1;FREQ=DAILY;UNTIL=20261231T180000Z';
+ controller.replaceFromExternal({
+ ...controller.state(),
+ recurrenceLines: [nextRule],
+ });
+ expect(controller.submitValues()?.recurrenceLines).toEqual([nextRule]);
+ });
+});
+
describe('pastEventWarning', () => {
it('warns when a new event with guests already ended', () => {
const controller = controllerFor({
diff --git a/apps/web/src/features/calendar/components/composer/event-form-model.ts b/apps/web/src/features/calendar/components/composer/event-form-model.ts
index 756c2dd450..46df4f665b 100644
--- a/apps/web/src/features/calendar/components/composer/event-form-model.ts
+++ b/apps/web/src/features/calendar/components/composer/event-form-model.ts
@@ -518,21 +518,27 @@ export function createEventEditorState(options: CreateEventEditorStateOptions) {
const choice = recurrenceChoice();
if (choice === 'existing') return undefined;
if (choice === 'none') return [];
- if (choice === 'custom') {
- return buildRecurrenceLines(
- customConfig(),
- options.state().allDay,
- options.recurrenceTimeZone
- );
+ const config =
+ choice === 'custom'
+ ? customConfig()
+ : presets().find((candidate) => candidate.id === choice)?.config;
+ if (!config) return undefined;
+ const originalConfig = initialConfig();
+ if (
+ originalConfig &&
+ options.state().allDay === initialValues().allDay &&
+ recurrenceConfigsEqual(config, originalConfig)
+ ) {
+ // Rebuilding an untouched rule can reorder fields, drop provider details
+ // like WKST, or change UNTIL precision. Preserve it so a private reminder
+ // edit does not accidentally request an organizer-only series update.
+ return initialValues().recurrenceLines;
}
- const preset = presets().find((candidate) => candidate.id === choice);
- return preset
- ? buildRecurrenceLines(
- preset.config,
- options.state().allDay,
- options.recurrenceTimeZone
- )
- : undefined;
+ return buildRecurrenceLines(
+ config,
+ options.state().allDay,
+ options.recurrenceTimeZone
+ );
};
const dateRangeError = createMemo(() => {
const current = options.state();
diff --git a/apps/web/src/features/calendar/hooks/use-event-editor.test.ts b/apps/web/src/features/calendar/hooks/use-event-editor.test.ts
index 35d94af7f3..d378192373 100644
--- a/apps/web/src/features/calendar/hooks/use-event-editor.test.ts
+++ b/apps/web/src/features/calendar/hooks/use-event-editor.test.ts
@@ -1,5 +1,6 @@
import { createRoot } from 'solid-js';
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { createCalendarEventFormController } from '../components/composer/create-calendar-event-form-controller';
import {
calendarEventToEditorInitialValues,
type EventEditorSubmitValues,
@@ -97,6 +98,203 @@ beforeEach(() => {
mocks.updateMeeting.mockResolvedValue({ id: 'meeting-1' });
});
+describe('editing event times', () => {
+ function editorFor(overrides: Partial<CalendarEvent> = {}) {
+ return createRoot((dispose) => {
+ const event: CalendarEvent = {
+ ...savedEvent,
+ location: '',
+ recurrenceLines: ['RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR'],
+ reminders: {
+ useDefault: false,
+ overrides: [{ method: 'popup', minutes: 10 }],
+ },
+ ...overrides,
+ };
+ const onSaved = vi.fn();
+ const editor = useEventEditor({
+ event: () => event,
+ onSaved,
+ macroCallsEnabled: () => false,
+ });
+ const form = createCalendarEventFormController({
+ initialValue: calendarEventToEditorInitialValues(event),
+ isEdit: true,
+ calendarOptions: editor.calendarOptions,
+ guestOptions: () => [],
+ });
+ return { editor, form, event, onSaved, dispose };
+ });
+ }
+
+ describe.each(['all', 'this_event'] as const)('%s scope', (scope) => {
+ it.each([
+ 'RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR',
+ 'RRULE:BYDAY=FR,TH,WE,TU,MO;FREQ=WEEKLY',
+ 'RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;UNTIL=20261231T180000Z',
+ ])('removes only reminders without rewriting %s', async (rule) => {
+ const { editor, form, onSaved, dispose } = editorFor({
+ recurrenceLines: [rule],
+ });
+ try {
+ form.setReminderMinutes([]);
+ await editor.save(form.submitValues()!, scope);
+ expect(mocks.updateEvent).toHaveBeenCalledOnce();
+ expect(mocks.updateEvent.mock.lastCall?.[0].patch).toEqual({
+ reminders: { useDefault: false, overrides: [] },
+ });
+ expect(onSaved).toHaveBeenCalledOnce();
+ } finally {
+ dispose();
+ }
+ });
+
+ it.each([
+ { label: 'timed', overrides: {} },
+ {
+ label: 'timed with seconds and an explicit offset',
+ overrides: {
+ start: '2026-09-22T10:00:37-04:00',
+ end: '2026-09-22T11:00:42-04:00',
+ },
+ },
+ {
+ label: 'all-day',
+ overrides: {
+ allDay: true,
+ start: '2026-09-22',
+ end: '2026-09-24',
+ },
+ },
+ ])(
+ 'preserves $label timing when only reminders change',
+ async ({ overrides }) => {
+ const { editor, form, event, onSaved, dispose } = editorFor(overrides);
+ try {
+ form.setReminderMinutes([5]);
+ const submitted = form.submitValues();
+ expect(submitted).toBeDefined();
+ await editor.save(submitted!, scope);
+
+ expect(mocks.updateEvent).toHaveBeenCalledOnce();
+ const request = mocks.updateEvent.mock.lastCall?.[0];
+ expect(request.scope).toBe(scope);
+ expect(request.recurrenceId).toBe(
+ scope === 'this_event' ? event.occurrenceKey : undefined
+ );
+ expect(request.patch).toEqual({
+ reminders: {
+ useDefault: false,
+ overrides: [{ method: 'popup', minutes: 5 }],
+ },
+ });
+ expect(onSaved).toHaveBeenCalledOnce();
+ expect(mocks.failure).not.toHaveBeenCalled();
+ } finally {
+ dispose();
+ }
+ }
+ );
+
+ it.each(['start', 'end', 'allDay'] as const)(
+ 'still sends intentional %s changes',
+ async (field) => {
+ const { editor, form, dispose } = editorFor();
+ try {
+ if (field === 'allDay') form.setAllDay(true);
+ else if (field === 'start') form.setStart('2026-09-21T18:00');
+ else form.setField('end', '2026-10-01T18:30');
+ const submitted = form.submitValues();
+ expect(submitted).toBeDefined();
+ await editor.save(submitted!, scope);
+ expect(mocks.updateEvent.mock.lastCall?.[0].patch.time).toEqual(
+ submitted!.time
+ );
+ } finally {
+ dispose();
+ }
+ }
+ );
+ });
+
+ it.each([
+ {
+ label: 'Google Meet',
+ conferenceUrl: 'https://meet.google.com/abc-defg-hij',
+ conferenceProvider: 'google_meet' as const,
+ location: 'Meeting room',
+ description: '<p>Deploy checklist</p>',
+ },
+ { label: 'Macro call', location: savedEvent.location },
+ ])('sends only reminders on an invited $label event', async (overrides) => {
+ const { editor, form, onSaved, dispose } = editorFor({
+ ...overrides,
+ attendees: [
+ {
+ email: '[email protected]',
+ isOrganizer: true,
+ isSelf: false,
+ isOptional: false,
+ responseStatus: 'accepted',
+ },
+ {
+ email: '[email protected]',
+ isOrganizer: false,
+ isSelf: true,
+ isOptional: false,
+ responseStatus: 'accepted',
+ },
+ ],
+ });
+ mocks.updateEvent.mockImplementationOnce(async ({ patch }) => {
+ if (Object.keys(patch).some((field) => field !== 'reminders')) {
+ throw new Error('Forbidden');
+ }
+ return { id: 'event-1' };
+ });
+ try {
+ form.setReminderMinutes([5]);
+ await editor.save(form.submitValues()!, 'all');
+ expect(mocks.updateEvent).toHaveBeenCalledOnce();
+ expect(onSaved).toHaveBeenCalledOnce();
+ expect(mocks.failure).not.toHaveBeenCalled();
+ } finally {
+ dispose();
+ }
+ });
+
+ it('closes an unchanged event without sending an empty patch', async () => {
+ const { editor, form, onSaved, dispose } = editorFor();
+ try {
+ await editor.save(form.submitValues()!, 'all');
+ expect(mocks.updateEvent).not.toHaveBeenCalled();
+ expect(onSaved).toHaveBeenCalledOnce();
+ } finally {
+ dispose();
+ }
+ });
+
+ it.each(['title', 'location', 'description'] as const)(
+ 'still sends intentional %s edits and clearing',
+ async (field) => {
+ const { editor, form, dispose } = editorFor({
+ title: 'Prod Deploy',
+ location: 'Meeting room',
+ description: '<p>Checklist</p>',
+ });
+ try {
+ form.setField(field, field === 'title' ? 'Updated deploy' : '');
+ await editor.save(form.submitValues()!, 'all');
+ expect(mocks.updateEvent.mock.lastCall?.[0].patch).toEqual({
+ [field]: field === 'title' ? 'Updated deploy' : '',
+ });
+ } finally {
+ dispose();
+ }
+ }
+ );
+});
+
describe('scheduling a Macro call', () => {
it.each(['off', 'loading'] as const)(
'saves a calendar event without creating a call when the flag is %s',
@@ -296,10 +494,12 @@ describe('scheduling a Macro call', () => {
description: initial.description,
conferenceChoice: 'none',
});
- expect(mocks.updateEvent.mock.lastCall?.[0].patch.location).toBe(
- event.location
+ expect(mocks.updateEvent.mock.lastCall?.[0].patch).not.toHaveProperty(
+ 'location'
+ );
+ expect(mocks.updateEvent.mock.lastCall?.[0].patch).not.toHaveProperty(
+ 'description'
);
- expect(mocks.updateEvent.mock.lastCall?.[0].patch.description).toBe('');
expect(mocks.createMeeting).not.toHaveBeenCalled();
expect(mocks.updateMeeting).not.toHaveBeenCalled();
} finally {
diff --git a/apps/web/src/features/calendar/hooks/use-event-editor.ts b/apps/web/src/features/calendar/hooks/use-event-editor.ts
index c4e3a5ef95..b155e65f21 100644
--- a/apps/web/src/features/calendar/hooks/use-event-editor.ts
+++ b/apps/web/src/features/calendar/hooks/use-event-editor.ts
@@ -13,7 +13,9 @@ import {
} from '@queries/call/meetings';
import type { CalendarUpdateScope } from '@service-email/client';
import { type Accessor, createMemo, createSignal } from 'solid-js';
+import { match } from 'ts-pattern';
import {
+ buildEventTime,
calendarEventToEditorInitialValues,
type EventEditorDisabledFields,
type EventEditorSubmitValues,
@@ -51,6 +53,29 @@ function editsPrimaryCopy(event: CalendarEvent) {
return reminderCalendarIdOf(event) === event.calendarId;
}
+function hasTimeChanged(
+ event: CalendarEvent,
+ time: EventEditorSubmitValues['time']
+) {
+ // Compare at the editor's precision, which omits seconds. An unchanged
+ // occurrence must not replace the series start or its provider time zone.
+ const initial = buildEventTime(calendarEventToEditorInitialValues(event));
+ return match([initial, time])
+ .with(
+ [{ kind: 'timed' }, { kind: 'timed' }],
+ ([before, after]) =>
+ new Date(before.startsAt).getTime() !==
+ new Date(after.startsAt).getTime() ||
+ new Date(before.endsAt).getTime() !== new Date(after.endsAt).getTime()
+ )
+ .with(
+ [{ kind: 'allDay' }, { kind: 'allDay' }],
+ ([before, after]) =>
+ before.startDate !== after.startDate || before.endDate !== after.endDate
+ )
+ .otherwise(() => true);
+}
+
interface UseEventEditorProps {
event: Accessor<CalendarEvent | undefined>;
onSaved: () => void;
@@ -263,8 +288,13 @@ export function useEventEditor(props: UseEventEditorProps) {
const effectiveScope: CalendarUpdateScope = scope ?? 'all';
const targetsOneOccurrence = effectiveScope === 'this_event';
+ const initialContent = removeCalendarMacroCall(event, existingMeetingUrl);
const content =
- event.eventType === 'out_of_office'
+ event.eventType === 'out_of_office' ||
+ (existingMeetingUrl &&
+ wantsMacroCall &&
+ cleanContent.location === initialContent.location &&
+ cleanContent.description === initialContent.description)
? {
location: event.location ?? '',
description: event.description ?? '',
@@ -297,10 +327,14 @@ export function useEventEditor(props: UseEventEditorProps) {
: undefined,
occurrenceKey: targetsOneOccurrence ? event.occurrenceKey : undefined,
patch: {
- title: values.title,
- time: values.time,
- location: content.location,
- description: content.description,
+ ...(values.title !== event.title ? { title: values.title } : {}),
+ ...(hasTimeChanged(event, values.time) ? { time: values.time } : {}),
+ ...(content.location !== (event.location ?? '')
+ ? { location: content.location }
+ : {}),
+ ...(content.description !== (event.description ?? '')
+ ? { description: content.description }
+ : {}),
...(recurrenceChanged
? { recurrenceLines: values.recurrenceLines }
: {}),
@@ -314,7 +348,9 @@ export function useEventEditor(props: UseEventEditorProps) {
...(values.outOfOffice ? { outOfOffice: values.outOfOffice } : {}),
},
};
- await update.mutateAsync(updateArgs);
+ if (Object.keys(updateArgs.patch).length > 0) {
+ await update.mutateAsync(updateArgs);
+ }
calendarSaved = true;
if (needsCall() && canManageCall && !existingMeetingUrl) {
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 2d6982c123..30a09aad6e 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -1227,6 +1227,16 @@ the copy Macro's alerts fire from and whose guest list and join link Macro recor
editor only lets them be changed there. Answering an invitation likewise addresses the
primary copy. The details popover and the editor act on the displayed copy, so editing or
deleting it targets that calendar's event at Google.
+When changing only a reminder in the event editor, choose `All events` to apply it
+to the recurring series or `This event` for one occurrence. Saving preserves the
+existing dates, time zone, title, location, description, and repeat rule unless those controls
+changed. To verify, open a later occurrence of an event you were invited to,
+change the reminder, and inspect the PATCH: it should include only `reminders`
+plus the calendar and scope identifiers. Also verify that intentional edits to
+the start, end, all-day setting, title, location, description, or repeat rule are still sent.
+Test reminder removal as well as changing its time, including a series whose stored
+rule contains `INTERVAL=1`, `WKST`, differently ordered weekdays, or a precise `UNTIL`:
+an untouched rule must not be reformatted and included in a reminder-only PATCH.
As in Google Calendar, the guests row of the details popover (a bottom sheet on phones)
carries `Copy guest emails` and `Email guests` icon buttons. Copying puts every guest's
address on the clipboard, comma-separated. Emailing opens a new email addressed to every