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): hide Edit on snapshot copies and drop refused detail edits (#8627)

gbirman83cbec25d3d2
diff --git a/apps/web/src/features/block-calendar/components/EventComposerSplit.tsx b/apps/web/src/features/block-calendar/components/EventComposerSplit.tsx
index 94502c7abd..bd5e734c77 100644
--- a/apps/web/src/features/block-calendar/components/EventComposerSplit.tsx
+++ b/apps/web/src/features/block-calendar/components/EventComposerSplit.tsx
@@ -59,6 +59,7 @@ function EventComposerContent(
event: () => props.event,
macroCallsEnabled,
guestInvitesEnabled: useCalendarGuestInvitesFlag(),
+ onDetailEditsRefused: () => controller.resetDetails(),
onSaved: () => {
props.onSaveSuccess?.();
close();
diff --git a/apps/web/src/features/calendar-view/components/SelectedEventDetails.test.tsx b/apps/web/src/features/calendar-view/components/SelectedEventDetails.test.tsx
new file mode 100644
index 0000000000..d10d18a93e
--- /dev/null
+++ b/apps/web/src/features/calendar-view/components/SelectedEventDetails.test.tsx
@@ -0,0 +1,193 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import type { CalendarEvent } from '@app/features/calendar/types';
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import userEvent from '@testing-library/user-event';
+import { ImperativeDialogHost } from '@ui';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { SelectedEventDetails } from './SelectedEventDetails';
+
+const mocks = vi.hoisted(() => ({
+ mobile: false,
+ openComposer: vi.fn(),
+ deleteEvent: vi.fn(),
+}));
+
+vi.mock('@core/mobile/isMobile', () => ({ isMobile: () => mocks.mobile }));
+vi.mock('@queries/calendar/calendars', () => ({
+ useVisibleCalendarsQuery: () => ({ isSuccess: true, data: [] }),
+}));
+vi.mock('@queries/calendar/mutations', () => ({
+ useDeleteCalendarEventMutation: () => ({
+ mutate: mocks.deleteEvent,
+ isPending: false,
+ }),
+}));
+vi.mock(
+ '@app/features/calendar-view/components/use-open-event-composer',
+ () => ({
+ useOpenEventComposer: () => mocks.openComposer,
+ })
+);
+vi.mock(
+ '@app/features/calendar-view/components/use-forward-event-email',
+ () => ({
+ useForwardEventEmail: () => vi.fn(),
+ })
+);
+vi.mock('@app/features/calendar/hooks/create-guest-invite-controller', () => ({
+ createGuestInviteController: () => ({ editorOpen: () => false }),
+}));
+vi.mock('@app/features/calendar/hooks/use-calendar-ui-flag', () => ({
+ useCalendarGuestInvitesFlag: () => () => false,
+}));
+// The sections below the header have their own tests; this one is about the
+// header's actions.
+vi.mock('@app/features/calendar/components/EventDetails', () => ({
+ EventDetails: () => null,
+}));
+vi.mock('@app/features/calendar-view/components/EventGuests', () => ({
+ EventGuests: () => null,
+}));
+vi.mock('@app/features/calendar-view/components/EventJoinRequests', () => ({
+ EventJoinRequests: () => null,
+}));
+vi.mock('@app/features/calendar-view/components/EventRsvpSection', () => ({
+ EventRsvpSection: () => null,
+}));
+
+// jsdom has no CSS.escape. Closing the confirmation restores focus through a
+// selector built from class names, from a timer that can outlive the test.
+Object.defineProperty(globalThis, 'CSS', {
+ value: {
+ escape: (value: string) => value.replace(/[^\w-]/g, (char) => `\\${char}`),
+ },
+ configurable: true,
+});
+
+class ObserverStub {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+}
+
+const NO_CAPABILITIES = {
+ editDetails: false,
+ inviteGuests: false,
+ removeGuests: false,
+ setGuestPolicy: false,
+ rsvp: false,
+ organize: false,
+};
+
+function event(overrides: Partial<CalendarEvent> = {}): CalendarEvent {
+ return {
+ id: '["event-1","2026-10-23T19:00:00Z"]',
+ eventId: 'event-1',
+ occurrenceKey: '2026-10-23T19:00:00Z',
+ isCancelled: false,
+ isReadOnly: false,
+ guestPolicy: {
+ canModify: false,
+ canInviteOthers: true,
+ canSeeOtherGuests: true,
+ },
+ viewerCan: NO_CAPABILITIES,
+ attendees: [
+ {
+ email: '[email protected]',
+ isOptional: false,
+ isOrganizer: false,
+ isSelf: true,
+ responseStatus: 'accepted',
+ },
+ ],
+ organizerEmail: '[email protected]',
+ recurrenceLines: [],
+ title: 'Projects discussion',
+ start: '2026-10-23T19:00:00Z',
+ end: '2026-10-23T19:30:00Z',
+ allDay: false,
+ sourceCalendarIds: ['calendar-1'],
+ calendarId: 'calendar-1',
+ calendar: { id: 'calendar-1', name: 'Calendar', color: '#336699' },
+ visibleCalendars: [],
+ ...overrides,
+ };
+}
+
+function showDetails(selected: CalendarEvent) {
+ const boundary = document.createElement('div');
+ const anchor = document.createElement('div');
+ document.body.append(boundary, anchor);
+ render(() => (
+ <>
+ <SelectedEventDetails
+ boundary={boundary}
+ anchor={() => anchor}
+ event={() => selected}
+ timeFormat={() => '12-hour'}
+ onClose={vi.fn()}
+ />
+ <ImperativeDialogHost />
+ </>
+ ));
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ vi.stubGlobal('ResizeObserver', ObserverStub);
+ vi.stubGlobal('PointerEvent', MouseEvent);
+ vi.stubGlobal('scrollTo', vi.fn());
+});
+afterEach(() => {
+ cleanup();
+ document.body.replaceChildren();
+ vi.unstubAllGlobals();
+});
+
+describe.each([
+ ['desktop popover', false],
+ ['phone drawer', true],
+])('in the %s', (_surface, mobile) => {
+ beforeEach(() => {
+ mocks.mobile = mobile;
+ });
+
+ it('offers no Edit on a snapshot, and deletes it as the viewer’s copy', async () => {
+ const user = userEvent.setup();
+ showDetails(event({ isSnapshot: true }));
+
+ const deleteCopy = await screen.findByRole('button', {
+ name: 'Delete your copy',
+ });
+ expect(screen.queryByRole('button', { name: 'Edit event' })).toBeNull();
+ expect(screen.queryByRole('button', { name: 'Delete event' })).toBeNull();
+
+ await user.click(deleteCopy);
+ expect(
+ await screen.findByText(
+ 'Delete your copy of “Projects discussion”? The shared event stays as it is.'
+ )
+ ).toBeTruthy();
+ await user.click(screen.getByRole('button', { name: 'Delete' }));
+ expect(mocks.deleteEvent).toHaveBeenCalledWith({
+ eventId: 'event-1',
+ calendarId: 'calendar-1',
+ scope: 'all',
+ recurrenceId: undefined,
+ occurrenceKey: undefined,
+ });
+ });
+
+ it('keeps Edit for a guest the organizer does not let modify', async () => {
+ showDetails(event({ viewerCan: { ...NO_CAPABILITIES, rsvp: true } }));
+
+ expect(
+ await screen.findByRole('button', { name: 'Edit event' })
+ ).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Delete event' })).toBeTruthy();
+ });
+});
diff --git a/apps/web/src/features/calendar-view/components/SelectedEventDetails.tsx b/apps/web/src/features/calendar-view/components/SelectedEventDetails.tsx
index 1da8b970dc..755c02f93a 100644
--- a/apps/web/src/features/calendar-view/components/SelectedEventDetails.tsx
+++ b/apps/web/src/features/calendar-view/components/SelectedEventDetails.tsx
@@ -7,6 +7,10 @@ import {
type CalendarTimeFormat,
reminderCalendarIdOf,
} from '@app/features/calendar/types';
+import {
+ canDeleteCalendarEvent,
+ canEditCalendarEvent,
+} from '@app/features/calendar/utils/event-interaction';
import { handleOpenEventOutsidePress } from '@app/features/calendar/utils/open-event-outside-press';
import { TeamEventDetails } from '@app/features/calendar-team/components/team-event-details';
import { EventGuests } from '@app/features/calendar-view/components/EventGuests';
@@ -136,7 +140,7 @@ interface EventDetailsOverlayProps {
function EveryoneElseDeclinedNotice(props: {
event: CalendarEvent;
- canModify: boolean;
+ canEdit: boolean;
onDelete: () => void;
onReschedule: () => void;
}) {
@@ -155,7 +159,7 @@ function EveryoneElseDeclinedNotice(props: {
<div role="status" class="font-medium text-ink">
Everyone else declined this event
</div>
- <Show when={props.canModify}>
+ <Show when={props.canEdit}>
<div class="flex justify-end gap-1">
<Button variant="ghost" size="sm" onClick={props.onDelete}>
Delete
@@ -181,10 +185,8 @@ function EventDetailsDrawer(props: EventDetailsOverlayProps) {
() => props.event,
useCalendarGuestInvitesFlag()
);
- const canModify = () =>
- !props.event.teamProjection &&
- !props.event.isReadOnly &&
- !props.event.isCancelled;
+ const canEdit = () => canEditCalendarEvent(props.event);
+ const canDelete = () => canDeleteCalendarEvent(props.event);
const openEditor = () => {
openEventComposer({ event: props.event });
props.onOpenChange(false);
@@ -258,7 +260,7 @@ function EventDetailsDrawer(props: EventDetailsOverlayProps) {
<ArrowBendUpRightIcon />
</Button>
</Show>
- <Show when={canModify()}>
+ <Show when={canEdit()}>
<Button
label="Edit event"
variant="ghost"
@@ -269,8 +271,10 @@ function EventDetailsDrawer(props: EventDetailsOverlayProps) {
>
<PencilSimpleIcon />
</Button>
+ </Show>
+ <Show when={canDelete()}>
<Button
- label="Delete event"
+ label={deleteEventLabel(props.event)}
variant="ghost"
size="icon-md"
depth={3}
@@ -285,13 +289,13 @@ function EventDetailsDrawer(props: EventDetailsOverlayProps) {
<MobileDrawer.ScrollBody>
<EveryoneElseDeclinedNotice
event={props.event}
- canModify={canModify()}
+ canEdit={canEdit()}
onDelete={deleteDialog.open}
onReschedule={openEditor}
/>
<EventJoinRequests
eventId={props.event.eventId}
- canModify={canModify()}
+ canModify={canEdit()}
/>
<div class="px-3">
<Show
@@ -351,6 +355,11 @@ function useDeleteEventDialog(props: {
return { open, isOpen: dialog.isOpen };
}
+/** A snapshot is the viewer's own copy; deleting it leaves the meeting alone. */
+function deleteEventLabel(event: CalendarEvent) {
+ return event.isSnapshot ? 'Delete your copy' : 'Delete event';
+}
+
const DELETE_SCOPE_OPTIONS = [
{ scope: 'this_event', label: 'This event' },
{ scope: 'this_and_following', label: 'This and following events' },
@@ -391,28 +400,23 @@ function DeleteEventDialog(
});
};
+ const title = () => props.event.title || 'Untitled event';
+ const prompt = () =>
+ props.event.isSnapshot
+ ? `Delete your copy of “${title()}”? The shared event stays as it is.`
+ : `${isRecurring() ? 'Remove' : 'Delete'} “${title()}”? Guests will be notified.`;
+
return (
<DeleteDialog
open={props.open}
onOpenChange={props.onOpenChange}
- title="Delete event"
+ title={deleteEventLabel(props.event)}
pending={deleteEvent.isPending}
onDelete={confirm}
>
- <Show
- when={isRecurring()}
- fallback={
- <p>
- Delete “{props.event.title || 'Untitled event'}”? Guests will be
- notified.
- </p>
- }
- >
+ <Show when={isRecurring()} fallback={<p>{prompt()}</p>}>
<div class="flex flex-col gap-3">
- <p>
- Remove “{props.event.title || 'Untitled event'}”? Guests will be
- notified.
- </p>
+ <p>{prompt()}</p>
<RadioGroup
value={scope()}
onChange={(value) => setScope(value as CalendarDeletionScope)}
@@ -449,10 +453,8 @@ function EventDetailsPopover(props: EventDetailsPopoverProps) {
() => props.event,
useCalendarGuestInvitesFlag()
);
- const canModify = () =>
- !props.event.teamProjection &&
- !props.event.isReadOnly &&
- !props.event.isCancelled;
+ const canEdit = () => canEditCalendarEvent(props.event);
+ const canDelete = () => canDeleteCalendarEvent(props.event);
const openEditor = () => {
openEventComposer({ event: props.event });
props.onOpenChange(false);
@@ -547,7 +549,7 @@ function EventDetailsPopover(props: EventDetailsPopoverProps) {
<ArrowBendUpRightIcon />
</Button>
</Show>
- <Show when={canModify()}>
+ <Show when={canEdit()}>
<Button
label="Edit event"
variant="ghost"
@@ -558,8 +560,10 @@ function EventDetailsPopover(props: EventDetailsPopoverProps) {
>
<PencilSimpleIcon />
</Button>
+ </Show>
+ <Show when={canDelete()}>
<Button
- label="Delete event"
+ label={deleteEventLabel(props.event)}
variant="ghost"
size="icon-sm"
depth={3}
@@ -586,13 +590,13 @@ function EventDetailsPopover(props: EventDetailsPopoverProps) {
<div class="min-h-0 flex-auto overflow-y-auto overscroll-contain">
<EveryoneElseDeclinedNotice
event={props.event}
- canModify={canModify()}
+ canEdit={canEdit()}
onDelete={deleteDialog.open}
onReschedule={openEditor}
/>
<EventJoinRequests
eventId={props.event.eventId}
- canModify={canModify()}
+ canModify={canEdit()}
/>
<div class="px-3 pb-3">
<Show
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.description.test.tsx b/apps/web/src/features/calendar/components/composer/EventForm.description.test.tsx
new file mode 100644
index 0000000000..dc58dbb96c
--- /dev/null
+++ b/apps/web/src/features/calendar/components/composer/EventForm.description.test.tsx
@@ -0,0 +1,163 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { cleanup, render, screen, waitFor } from '@solidjs/testing-library';
+import userEvent from '@testing-library/user-event';
+import { createMemo, createSignal } from 'solid-js';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+
+vi.mock('@components/app/split-layout/split-router/mention-links', () => ({
+ useMacroMentionLinkResolver: () => () => undefined,
+}));
+// The description's typeahead menus need app providers this test is not
+// about; the editor itself is real.
+vi.mock('@core/component/LexicalMarkdown/component/menu/MentionsMenu', () => ({
+ MentionsMenu: () => null,
+}));
+vi.mock('@core/component/LexicalMarkdown/component/menu/EmojiMenu', () => ({
+ EmojiMenu: () => null,
+}));
+vi.mock('@core/component/LexicalMarkdown/component/menu/SnippetsMenu', () => ({
+ SnippetsMenu: () => null,
+}));
+
+import { createCalendarEventFormController } from './create-calendar-event-form-controller';
+import { EventForm } from './EventForm';
+import type {
+ EventEditorCalendarOption,
+ EventEditorDisabledFields,
+} from './event-form-model';
+
+class ObserverStub {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+}
+
+/** Reports each observed element once, which is how the editor learns it is mounted. */
+class ResizeObserverStub {
+ constructor(private readonly callback: ResizeObserverCallback) {}
+ observe() {
+ queueMicrotask(() => this.callback([], this));
+ }
+ unobserve() {}
+ disconnect() {}
+}
+
+const CALENDAR: EventEditorCalendarOption = {
+ id: 'work-calendar',
+ label: 'Work',
+ color: '#123456',
+};
+
+const LOCKED_DETAILS: EventEditorDisabledFields = {
+ calendar: true,
+ title: true,
+ start: true,
+ end: true,
+ allDay: true,
+ recurrence: true,
+ location: true,
+ description: true,
+ conference: true,
+};
+
+/** Renders the form with the real description editor. */
+function showForm(initiallyLocked: boolean) {
+ const [locked, setLocked] = createSignal(initiallyLocked);
+ let controller!: ReturnType<typeof createCalendarEventFormController>;
+ render(() => {
+ const calendarOptions = createMemo(() => [CALENDAR]);
+ controller = createCalendarEventFormController({
+ initialValue: {
+ title: 'Customer demo',
+ allDay: false,
+ start: '2030-01-01T12:00',
+ end: '2030-01-01T13:00',
+ recurrenceLines: [],
+ guests: '',
+ location: '',
+ description: 'Agenda',
+ conference: 'none',
+ calendarId: CALENDAR.id,
+ },
+ isEdit: true,
+ calendarOptions,
+ guestOptions: () => [],
+ });
+ return (
+ <EventForm
+ controller={controller}
+ macroCallsEnabled={false}
+ isEdit
+ disabledFields={locked() ? LOCKED_DETAILS : { calendar: true }}
+ detailsReadOnlyReason={
+ locked() ? 'Only the organizer can change this event.' : undefined
+ }
+ pending={false}
+ onCancel={vi.fn()}
+ onSubmit={vi.fn()}
+ />
+ );
+ });
+ return { controller: () => controller, setLocked };
+}
+
+beforeEach(() => {
+ Element.prototype.scrollIntoView = vi.fn();
+ // jsdom lays nothing out; Lexical measures the caret to keep it in view.
+ Range.prototype.getBoundingClientRect = () => new DOMRect();
+ vi.stubGlobal('ResizeObserver', ResizeObserverStub);
+ vi.stubGlobal('IntersectionObserver', ObserverStub);
+ vi.stubGlobal('scrollTo', vi.fn() as unknown as typeof window.scrollTo);
+});
+afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+});
+
+it('takes typing into an unlocked description', async () => {
+ const user = userEvent.setup();
+ const form = showForm(false);
+ const description = await screen.findByLabelText('Description');
+
+ await user.click(description);
+ await user.keyboard(' and notes');
+
+ await waitFor(() =>
+ expect(form.controller().state().description).toContain('notes')
+ );
+});
+
+it('refuses typing into a locked description', async () => {
+ const user = userEvent.setup();
+ const form = showForm(true);
+ const description = await screen.findByLabelText('Description');
+
+ expect(description.getAttribute('contenteditable')).toBe('false');
+ await user.click(description);
+ await user.keyboard(' and notes');
+
+ expect(description.textContent).toBe('Agenda');
+ expect(form.controller().state().description).toBe('Agenda');
+ expect(form.controller().isDirty()).toBe(false);
+});
+
+it('shows the event’s description again when its details lock after an edit', async () => {
+ const user = userEvent.setup();
+ const form = showForm(false);
+ await user.click(await screen.findByLabelText('Description'));
+ await user.keyboard(' and notes');
+ await waitFor(() =>
+ expect(form.controller().state().description).toContain('notes')
+ );
+
+ form.controller().resetDetails();
+ form.setLocked(true);
+
+ const description = await screen.findByLabelText('Description');
+ await waitFor(() => expect(description.textContent).toBe('Agenda'));
+ expect(description.getAttribute('contenteditable')).toBe('false');
+ expect(form.controller().isDirty()).toBe(false);
+});
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.test.tsx b/apps/web/src/features/calendar/components/composer/EventForm.test.tsx
index 61a1ec4ef6..40a63a3e11 100644
--- a/apps/web/src/features/calendar/components/composer/EventForm.test.tsx
+++ b/apps/web/src/features/calendar/components/composer/EventForm.test.tsx
@@ -150,6 +150,7 @@ it('keeps a guest the organizer does not let modify to their own reminders', asy
'disabled',
true
);
+ expect(screen.getByLabelText('Repeats')).toHaveProperty('disabled', true);
expect(
screen.getByRole('button', { name: /Video conferencing/ })
).toHaveProperty('disabled', true);
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.tsx b/apps/web/src/features/calendar/components/composer/EventForm.tsx
index f8c30c01f6..bafc25aa69 100644
--- a/apps/web/src/features/calendar/components/composer/EventForm.tsx
+++ b/apps/web/src/features/calendar/components/composer/EventForm.tsx
@@ -158,6 +158,30 @@ export function EventForm(props: EventFormProps) {
});
createEffect(() => props.onDirtyChange?.(controller.isDirty()));
+ const descriptionEditor = () => (
+ <MarkdownTextarea
+ resolveAppLink={resolveAppLink}
+ type="calendar"
+ initialHtml={calendarDescriptionToEditorHtml(initialDescription)}
+ editable={() => !fieldIsDisabled('description')}
+ onInitialized={(editor) => {
+ loadedDescription = exportCalendarDescription(editor);
+ }}
+ onChange={(_markdown, editor) => {
+ if (!editor) return;
+ const next = exportCalendarDescription(editor);
+ controller.setField(
+ 'description',
+ next === loadedDescription ? initialDescription : next
+ );
+ }}
+ placeholder="Add description..."
+ portalScope="local"
+ domRef={(element) => element.setAttribute('aria-label', 'Description')}
+ class="h-full w-full bg-transparent px-2 text-sm text-ink outline-none"
+ />
+ );
+
const submit = () => {
const values = controller.submitValues();
if (!values || formIsDisabled()) return;
@@ -251,31 +275,15 @@ export function EventForm(props: EventFormProps) {
class="block w-full"
>
<div class="h-12 overflow-y-auto">
- <MarkdownTextarea
- resolveAppLink={resolveAppLink}
- type="calendar"
- initialHtml={calendarDescriptionToEditorHtml(
- initialDescription
- )}
- editable={() => !fieldIsDisabled('description')}
- onInitialized={(editor) => {
- loadedDescription = exportCalendarDescription(editor);
- }}
- onChange={(_markdown, editor) => {
- if (!editor) return;
- const next = exportCalendarDescription(editor);
- controller.setField(
- 'description',
- next === loadedDescription ? initialDescription : next
- );
- }}
- placeholder="Add description..."
- portalScope="local"
- domRef={(element) =>
- element.setAttribute('aria-label', 'Description')
- }
- class="h-full w-full bg-transparent px-2 text-sm text-ink outline-none"
- />
+ {/* The editor reads the description only when it mounts.
+ Details that lock after a refused save return to the
+ event's own, so the editor mounts again to show them. */}
+ <Show
+ when={fieldIsReadOnly('description')}
+ fallback={descriptionEditor()}
+ >
+ {descriptionEditor()}
+ </Show>
</div>
</LockedField>
</Show>
@@ -302,12 +310,10 @@ export function EventForm(props: EventFormProps) {
options={controller.recurrenceOptions()}
value={controller.selectedRecurrenceOption()}
onChange={controller.changeRecurrenceChoice}
- disabled={formIsDisabled()}
+ disabled={fieldIsDisabled('recurrence')}
// A single occurrence has no recurrence rule of its own, so the
// recurrence cannot be edited while the scope is one event.
- readOnly={
- fieldIsReadOnly('recurrence') || editScope() === 'this_event'
- }
+ readOnly={editScope() === 'this_event'}
/>
</LockedField>
<Show when={!isOutOfOffice()}>
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 4c814dccb9..7c58668448 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
@@ -505,6 +505,46 @@ it('submits guest permissions only when they change', () => {
expect(controller.submitValues()?.guestPolicy).toBeUndefined();
});
+it('returns locked details to the event’s own and keeps the viewer’s reminders', () => {
+ const controller = controllerFor(
+ {
+ start: '2030-01-01T12:00',
+ end: '2030-01-01T13:00',
+ title: 'Planning',
+ location: 'Room 1',
+ description: 'Agenda',
+ recurrenceLines: ['RRULE:FREQ=DAILY'],
+ reminders: { useDefault: false, overrides: [] },
+ },
+ { isEdit: true }
+ );
+ controller.setField('title', 'Planning review');
+ controller.setField('location', 'Room 4');
+ controller.setField('description', 'Agenda and notes');
+ controller.setStart('2030-01-01T15:00');
+ controller.changeRecurrenceChoice('none');
+ controller.setReminderMinutes([30]);
+
+ controller.resetDetails();
+
+ expect(controller.submitValues()).toMatchObject({
+ title: 'Planning',
+ location: 'Room 1',
+ description: 'Agenda',
+ time: { kind: 'timed' },
+ reminders: {
+ useDefault: false,
+ overrides: [{ method: 'popup', minutes: 30 }],
+ },
+ });
+ expect(controller.state().start).toBe('2030-01-01T12:00');
+ expect(controller.recurrenceLines()).toEqual(['RRULE:FREQ=DAILY']);
+ expect(controller.isDirty()).toBe(true);
+
+ controller.setReminderMinutes([]);
+ expect(controller.isDirty()).toBe(false);
+});
+
it('drops guest permissions picked before switching to a calendar without them', () => {
const google = {
id: 'work',
diff --git a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts
index d6d6e3aa7d..5952e76034 100644
--- a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts
+++ b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts
@@ -580,6 +580,33 @@ export function createCalendarEventFormController(
};
};
+ /**
+ * Returns the event's details (what a guest without modify rights cannot
+ * change) to their loaded values, keeping the viewer's reminders, guests
+ * and guest permissions, so a form whose details just locked holds nothing
+ * it cannot save.
+ */
+ const resetDetails = () => {
+ const initial = initialValue();
+ batch(() => {
+ setState({
+ ...state(),
+ title: initial.title,
+ allDay: initial.allDay,
+ start: initial.start,
+ end: initial.end,
+ recurrenceLines: [...initial.recurrenceLines],
+ location: initial.location,
+ description: initial.description,
+ outOfOffice: initial.outOfOffice
+ ? { ...initial.outOfOffice }
+ : undefined,
+ });
+ recurrence.replaceInitialValues(initial);
+ });
+ notifyChange();
+ };
+
const replaceFromExternal = (next: EventEditorInitialValues) => {
const cloned = cloneValue(next);
const guests = initialGuestOptions(next.guests, options.guestOptions());
@@ -635,6 +662,7 @@ export function createCalendarEventFormController(
snapshot,
isDirty,
submitValues,
+ resetDetails,
replaceFromExternal,
};
}
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 b6ce20d9fc..43ba2de63e 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
@@ -1062,13 +1062,18 @@ describe('guests of an event the viewer was invited to', () => {
guestEmails: ['[email protected]'],
};
- function editorFor(event: CalendarEvent, invitesEnabled: boolean) {
+ function editorFor(
+ event: CalendarEvent,
+ invitesEnabled: boolean,
+ onDetailEditsRefused?: () => void
+ ) {
return createRoot((dispose) => ({
editor: useEventEditor({
event: () => event,
onSaved: vi.fn(),
macroCallsEnabled: () => false,
guestInvitesEnabled: () => invitesEnabled,
+ onDetailEditsRefused,
}),
dispose,
}));
@@ -1234,6 +1239,38 @@ describe('guests of an event the viewer was invited to', () => {
}
});
+ it('saves only the reminders of a snapshot of a shared meeting', async () => {
+ const snapshot = invitedEvent(
+ { ...mayInvite, inviteGuests: false, rsvp: false },
+ { isSnapshot: true }
+ );
+ const { editor, dispose } = editorFor(snapshot, true);
+ try {
+ expect(editor.disabledFields()).toMatchObject({
+ title: true,
+ start: true,
+ description: true,
+ location: true,
+ guests: true,
+ conference: true,
+ reminders: false,
+ });
+ await editor.save({
+ ...unchanged,
+ title: 'Planning review',
+ description: '<p>My notes</p>',
+ reminders: thirtyMinutes,
+ });
+ expect(mocks.updateEvent).toHaveBeenCalledOnce();
+ expect(mocks.updateEvent.mock.lastCall?.[0].patch).toEqual({
+ reminders: thirtyMinutes,
+ });
+ expect(mocks.inviteGuests).not.toHaveBeenCalled();
+ } finally {
+ dispose();
+ }
+ });
+
it('leaves the details editable for a guest the organizer lets modify', async () => {
const { editor, dispose } = editorFor(invitedEvent(mayModify), true);
try {
@@ -1250,12 +1287,18 @@ describe('guests of an event the viewer was invited to', () => {
it('locks the details when the server refuses a guest’s change', async () => {
mocks.updateEvent.mockRejectedValueOnce({ code: 'guests_cannot_modify' });
- const { editor, dispose } = editorFor(invitedEvent(mayModify), true);
+ const detailEditsRefused = vi.fn();
+ const { editor, dispose } = editorFor(
+ invitedEvent(mayModify),
+ true,
+ detailEditsRefused
+ );
try {
await editor.save({ ...unchanged, title: 'Planning review' });
expect(mocks.failure).toHaveBeenCalledWith(
'Only the organizer can change this event.'
);
+ expect(detailEditsRefused).toHaveBeenCalledOnce();
expect(editor.disabledFields()?.title).toBe(true);
expect(editor.detailsReadOnlyReason()).toBe(
'Only the organizer can change this event.'
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 32c2615da5..d6b5150773 100644
--- a/apps/web/src/features/calendar/hooks/use-event-editor.ts
+++ b/apps/web/src/features/calendar/hooks/use-event-editor.ts
@@ -110,6 +110,12 @@ interface UseEventEditorProps {
* when omitted.
*/
guestInvitesEnabled?: Accessor<boolean>;
+ /**
+ * Called when the server refuses a detail change and the details lock, so
+ * the form can return them to the event's own instead of holding changes
+ * it can no longer save.
+ */
+ onDetailEditsRefused?: () => void;
}
/** Shared create/edit query and mutation orchestration for any editor shell. */
@@ -444,6 +450,7 @@ export function useEventEditor(props: UseEventEditorProps) {
}
} else if (event && isGuestEditRefused(error)) {
setDetailEditsRefused(true);
+ props.onDetailEditsRefused?.();
toast.failure(GUEST_EDITS_RESTRICTED);
} else {
toast.failure(
diff --git a/apps/web/src/features/calendar/types.test.ts b/apps/web/src/features/calendar/types.test.ts
index 38193ba939..f6656db52b 100644
--- a/apps/web/src/features/calendar/types.test.ts
+++ b/apps/web/src/features/calendar/types.test.ts
@@ -339,6 +339,25 @@ describe('mapCalendarEventToFullCalendar', () => {
expect(modifiable.durationEditable).toBe(true);
});
+ it('fixes a snapshot of a shared meeting in place', () => {
+ const source = item([copy('primary')]);
+ source.event.isSnapshot = true;
+ source.event.viewerCan = {
+ editDetails: false,
+ inviteGuests: false,
+ removeGuests: false,
+ setGuestPolicy: false,
+ rsvp: false,
+ organize: false,
+ };
+ const snapshot = mapCalendarEventToFullCalendar(
+ mapCalendarOccurrence(source, { sourceById })
+ );
+
+ expect(snapshot.startEditable).toBe(false);
+ expect(snapshot.durationEditable).toBe(false);
+ });
+
it('keeps the occurrence identity and displayed title on the rendered event', () => {
const rendered = mapCalendarEventToFullCalendar(
mapCalendarOccurrence(item([copy('primary'), sharedCopy]), {
diff --git a/apps/web/src/features/calendar/utils/event-guest-editing.ts b/apps/web/src/features/calendar/utils/event-guest-editing.ts
index 6683f409be..ca37c8deb3 100644
--- a/apps/web/src/features/calendar/utils/event-guest-editing.ts
+++ b/apps/web/src/features/calendar/utils/event-guest-editing.ts
@@ -10,13 +10,16 @@ export const GUEST_EDITS_RESTRICTED =
/**
* Whether the viewer is a guest the organizer does not let modify the event,
- * so its title, time, description, location, recurrence and conferencing stay
- * as the organizer set them. Reminders stay the guest's own. Someone neither
- * organizing nor invited keeps what their calendar access allows, as on the
- * server.
+ * or holds a snapshot of a shared meeting, so its title, time, description,
+ * location, recurrence and conferencing stay as the organizer set them.
+ * Reminders stay the viewer's own. Someone neither organizing nor invited
+ * keeps what their calendar access allows, as on the server.
*/
export function guestEditsRestricted(event: CalendarEvent): boolean {
- return event.viewerCan.rsvp && !event.viewerCan.editDetails;
+ return (
+ event.isSnapshot === true ||
+ (event.viewerCan.rsvp && !event.viewerCan.editDetails)
+ );
}
function normalizeGuestEmail(email: string) {
diff --git a/apps/web/src/features/calendar/utils/event-interaction.ts b/apps/web/src/features/calendar/utils/event-interaction.ts
index cc46a1b4e8..1328e51447 100644
--- a/apps/web/src/features/calendar/utils/event-interaction.ts
+++ b/apps/web/src/features/calendar/utils/event-interaction.ts
@@ -32,12 +32,24 @@ export function calendarEventRenderIds(
: [calendarEventRenderId(event)];
}
+/** Whether the viewer may delete an occurrence from their calendar. */
+export function canDeleteCalendarEvent(event: CalendarEvent) {
+ return !event.teamProjection && !event.isReadOnly && !event.isCancelled;
+}
+
+/**
+ * Whether an occurrence opens in the event composer. A snapshot of a shared
+ * meeting does not: it keeps the organizer's details, and a composer that
+ * could change only its reminders reads as editing the meeting itself.
+ */
+export function canEditCalendarEvent(event: CalendarEvent) {
+ return canDeleteCalendarEvent(event) && !event.isSnapshot;
+}
+
/** Whether an occurrence can safely be moved or resized from the calendar. */
export function canEditCalendarEventTime(event: CalendarEvent) {
return (
- !event.teamProjection &&
- !event.isReadOnly &&
- !event.isCancelled &&
+ canEditCalendarEvent(event) &&
!guestEditsRestricted(event) &&
!isTimedPointEvent(event) &&
event.recurrenceLines.length === 0 &&
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index 613501314c..cebe2b9b26 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -477,8 +477,10 @@ invitation). That guest cannot drag or resize the event on the grid either. Some
neither organizing nor invited, such as a delegate on a shared calendar, keeps what their
calendar access allows. The update refuses a detail change from such a guest with 403
`guests_cannot_modify` (fields resent at their stored value are ignored, so the agent can
-pass them); the editor then shows the line in a toast and locks its details, and a refused
-drag snaps back with the same toast. The refusal covers a stale `viewerCan`, an event the
+pass them); the editor then shows the line in a toast, locks its details and returns them to
+the event's own (title, time, repeat, location and description, keeping notification and guest
+changes), so it never holds a change it cannot save, and a refused drag snaps back with the same
+toast. A locked description refuses typing, like the other locked fields. The refusal covers a stale `viewerCan`, an event the
viewer still sees as editable after the organizer turned modifying off, so check it without a
Google account on an event whose `viewerCan.editDetails` is still true, the only case where
the editor sends a detail change at all: answer `PATCH /events/{id}` with HTTP 403 and code
@@ -551,8 +553,11 @@ meeting's other guests and join link stay out and nobody is notified. If Google
the card says Google won't add the event to that calendar and points to `Download .ics`. The
mention then opens the snapshot, whose details say `Your copy of a shared event. It doesn't
update when the organizer changes it.` and offer no RSVP, `Add guests` or `Only the organizer can
-invite guests.` line, since none of it would reach the meeting; it can still be deleted and its
-reminders changed. If Google already holds the meeting on that calendar (an invitation Macro has
+invite guests.` line, since none of it would reach the meeting. It offers no `Edit event` on
+desktop or in the phone drawer, and the grid does not move or resize it: its details are the
+organizer's, and a composer that could change only its notifications would read as editing the
+meeting. Its delete button is `Delete your copy`, whose dialog says the shared event stays as it
+is. If Google already holds the meeting on that calendar (an invitation Macro has
not synced yet), nothing is imported, a sync is scheduled and the card reports that it is
already on their calendar. `Download .ics` saves the event as an iCalendar file and is not
flagged. `Ask to join` asks the person who shared the event to add the viewer as a guest; it