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.

feat(calendar): add reminders/notifications add and edit (#5725)

dev-rb326ffe28855e
diff --git a/apps/web/src/features/calendar/components/composer/EventForm.tsx b/apps/web/src/features/calendar/components/composer/EventForm.tsx
index 3e044de612..e88afe1d3c 100644
--- a/apps/web/src/features/calendar/components/composer/EventForm.tsx
+++ b/apps/web/src/features/calendar/components/composer/EventForm.tsx
@@ -8,6 +8,7 @@ import {
EventComposerGuestsPill,
EventComposerLocationPill,
EventComposerRecurrencePill,
+ EventComposerRemindersPill,
} from './EventPropertyPills';
import type {
EventEditorDisabledFields,
@@ -162,6 +163,16 @@ export function EventForm(props: EventFormProps) {
onChange={(location) => controller.setField('location', location)}
disabled={fieldIsDisabled('location')}
/>
+ <EventComposerRemindersPill
+ minutes={controller.reminderMinutes()}
+ usedSlots={
+ controller.reminderMinutes().length +
+ controller.preservedReminderCount()
+ }
+ canAdd={controller.canAddReminder()}
+ onChange={controller.setReminderMinutes}
+ disabled={fieldIsDisabled('reminders')}
+ />
</div>
</div>
diff --git a/apps/web/src/features/calendar/components/composer/EventPropertyPills.tsx b/apps/web/src/features/calendar/components/composer/EventPropertyPills.tsx
index 95a64fb9b6..c5c35f0c16 100644
--- a/apps/web/src/features/calendar/components/composer/EventPropertyPills.tsx
+++ b/apps/web/src/features/calendar/components/composer/EventPropertyPills.tsx
@@ -2,6 +2,7 @@ import { UserIcon } from '@core/component/UserIcon';
import { emailToId, recipientEntityMapper } from '@core/user';
import { Combobox } from '@kobalte/core/combobox';
import { Popover } from '@kobalte/core/popover';
+import BellSimpleIcon from '@phosphor/bell-simple.svg';
import CalendarDotsIcon from '@phosphor/calendar-dots.svg';
import CaretDownIcon from '@phosphor/caret-down.svg';
import MagnifyingGlassIcon from '@phosphor/magnifying-glass.svg';
@@ -20,6 +21,11 @@ import {
Show,
} from 'solid-js';
import { type VirtualizerHandle, VList } from 'virtua/solid';
+import {
+ formatReminderOffset,
+ REMINDER_OVERRIDES_MAX,
+ REMINDER_PRESET_MINUTES,
+} from '../../utils/event-reminders';
import {
type EventEditorCalendarOption,
type EventEditorGuestOption,
@@ -542,6 +548,137 @@ export function EventComposerLocationPill(
);
}
+export interface EventComposerRemindersPillProps {
+ minutes: number[];
+ usedSlots: number;
+ canAdd: boolean;
+ onChange: (minutes: number[]) => void;
+ disabled?: boolean;
+}
+
+const REMINDER_PRESET_MINUTE_SET = new Set(REMINDER_PRESET_MINUTES);
+const REMINDER_OPTION_CACHE = new Map<number, EventComposerSelectOption>();
+
+function reminderOption(minutes: number): EventComposerSelectOption {
+ const cached = REMINDER_OPTION_CACHE.get(minutes);
+ if (cached) return cached;
+ const option = {
+ value: String(minutes),
+ label: formatReminderOffset(minutes),
+ };
+ REMINDER_OPTION_CACHE.set(minutes, option);
+ return option;
+}
+
+const REMINDER_PRESET_OPTIONS = REMINDER_PRESET_MINUTES.map(reminderOption);
+
+function reminderOptions(customMinutesKey: string) {
+ if (customMinutesKey === '') return REMINDER_PRESET_OPTIONS;
+ return [
+ ...REMINDER_PRESET_OPTIONS,
+ ...customMinutesKey.split(',').map(Number).map(reminderOption),
+ ].sort((first, second) => Number(first.value) - Number(second.value));
+}
+
+function reminderPropertyLabel(minutes: number[]) {
+ if (minutes.length === 0) return 'Choose reminders';
+ if (minutes.length === 1) return formatReminderOffset(minutes[0]);
+ return `${minutes.length} notifications`;
+}
+
+/** Compact multi-select for event popup notification offsets. */
+export function EventComposerRemindersPill(
+ props: EventComposerRemindersPillProps
+) {
+ const customMinutesKey = createMemo(() =>
+ props.minutes
+ .filter((minutes) => !REMINDER_PRESET_MINUTE_SET.has(minutes))
+ .sort((first, second) => first - second)
+ .join(',')
+ );
+ const options = createMemo(() => reminderOptions(customMinutesKey()));
+ const selectedOptions = createMemo(() => {
+ const selected = new Set(props.minutes);
+ return options().filter((option) => selected.has(Number(option.value)));
+ });
+ const changeSelection = (selected: EventComposerSelectOption[]) => {
+ const next = selected
+ .map((option) => Number(option.value))
+ .sort((first, second) => first - second);
+ const current = [...props.minutes].sort((first, second) => first - second);
+ if (
+ next.length === current.length &&
+ next.every((minutes, index) => minutes === current[index])
+ ) {
+ return;
+ }
+ props.onChange(next);
+ };
+
+ return (
+ <Select<EventComposerSelectOption>
+ multiple
+ options={options()}
+ value={selectedOptions()}
+ onChange={changeSelection}
+ optionValue="value"
+ optionTextValue="label"
+ optionDisabled={(option) =>
+ !props.minutes.includes(Number(option.value)) && !props.canAdd
+ }
+ closeOnSelection={false}
+ selectionBehavior="toggle"
+ placeholder="Choose reminders"
+ disabled={props.disabled}
+ itemComponent={(itemProps) => (
+ <Select.Item item={itemProps.item}>
+ <OptionCheckBox
+ checked={props.minutes.includes(
+ Number(itemProps.item.rawValue.value)
+ )}
+ multiselect
+ />
+ <Select.ItemLabel class="min-w-0 flex-1 truncate">
+ {itemProps.item.rawValue.label}
+ </Select.ItemLabel>
+ </Select.Item>
+ )}
+ >
+ <Tooltip label="Set event notifications" placement="bottom">
+ <Select.Trigger
+ aria-label="Notifications"
+ class={cn(PROPERTY_TRIGGER_CLASS, 'max-w-48 overflow-hidden')}
+ >
+ <BellSimpleIcon class="size-3.5 shrink-0 text-ink-extra-muted" />
+ <Select.Value<EventComposerSelectOption>>
+ {(selectState) => (
+ <span class={cn('truncate', PROPERTY_VALUE_CLASS)}>
+ {reminderPropertyLabel(
+ selectState
+ .selectedOptions()
+ .map((option) => Number(option.value))
+ )}
+ </span>
+ )}
+ </Select.Value>
+ <Select.Icon />
+ </Select.Trigger>
+ </Tooltip>
+ <Select.Content class="w-56 p-0">
+ <div class="flex items-center justify-between border-edge-muted border-b px-3 py-2 text-xs text-ink-muted">
+ <span>Choose reminders</span>
+ <span
+ aria-label={`${props.usedSlots} of ${REMINDER_OVERRIDES_MAX} notifications selected`}
+ >
+ {props.usedSlots} / {REMINDER_OVERRIDES_MAX}
+ </span>
+ </div>
+ <Select.Listbox class="p-1.5" />
+ </Select.Content>
+ </Select>
+ );
+}
+
export interface EventComposerRecurrencePillProps {
options: EventComposerSelectOption[];
value: EventComposerSelectOption;
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 0837d48280..28d7793e97 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
@@ -1,4 +1,11 @@
import { type Accessor, batch, createMemo, createSignal } from 'solid-js';
+import {
+ buildReminderOverrides,
+ popupMinutes,
+ REMINDER_METHOD_POPUP,
+ REMINDER_OVERRIDES_MAX,
+ resolveReminderOverrides,
+} from '../../utils/event-reminders';
import {
parseRecurrenceConfig,
recurrenceConfigsEqual,
@@ -26,13 +33,14 @@ interface EventComposerFormSnapshot {
guestEmails: readonly string[];
location: string;
description: string;
+ reminderMinutes: readonly number[];
}
function normalizedGuestEmails(emails: readonly string[]) {
return emails.map((email) => email.trim().toLowerCase()).sort();
}
-function arraysEqual(first: readonly string[], second: readonly string[]) {
+function arraysEqual<Value>(first: readonly Value[], second: readonly Value[]) {
return (
first.length === second.length &&
first.every((value, index) => value === second[index])
@@ -70,7 +78,8 @@ function isEventComposerFormDirty(
normalizedGuestEmails(initial.guestEmails),
normalizedGuestEmails(current.guestEmails)
) ||
- !recurrenceLinesEqual(initial.recurrenceLines, current.recurrenceLines)
+ !recurrenceLinesEqual(initial.recurrenceLines, current.recurrenceLines) ||
+ !arraysEqual(initial.reminderMinutes, current.reminderMinutes)
);
}
@@ -82,7 +91,22 @@ export interface CreateCalendarEventFormControllerOptions {
}
function cloneValue(value: EventEditorInitialValues): EventEditorInitialValues {
- return { ...value, recurrenceLines: [...value.recurrenceLines] };
+ return {
+ ...value,
+ recurrenceLines: [...value.recurrenceLines],
+ reminders: value.reminders
+ ? {
+ ...value.reminders,
+ overrides: value.reminders.overrides?.map((reminder) => ({
+ ...reminder,
+ })),
+ }
+ : undefined,
+ };
+}
+
+function normalizedReminderMinutes(minutes: readonly number[]) {
+ return [...new Set(minutes)].sort((first, second) => first - second);
}
/** Caller-owned state and commands for the reusable calendar event form. */
@@ -114,20 +138,70 @@ export function createCalendarEventFormController(
const effectiveCalendarId = () =>
state().calendarId ?? options.calendarOptions()[0]?.id;
- const selectedCalendarOption = () =>
+ const calendarOptionFor = (calendarId: string | undefined) =>
options
.calendarOptions()
- .find((option) => option.id === effectiveCalendarId()) ??
- options.calendarOptions()[0];
+ .find(
+ (option) =>
+ option.id === (calendarId ?? options.calendarOptions()[0]?.id)
+ ) ?? options.calendarOptions()[0];
+
+ const selectedCalendarOption = () => calendarOptionFor(state().calendarId);
+
+ const resolvedReminderMinutesFor = (values: EventEditorInitialValues) =>
+ normalizedReminderMinutes(
+ popupMinutes(
+ resolveReminderOverrides(
+ values.reminders,
+ calendarOptionFor(values.calendarId)?.defaultReminders
+ )
+ )
+ );
+ const baselineReminderMinutes = () => resolvedReminderMinutesFor(state());
+ const initialReminderMinutes = () =>
+ resolvedReminderMinutesFor(initialValue());
+ const [reminderEdits, setReminderEdits] = createSignal<
+ number[] | undefined
+ >();
+ const reminderMinutes = createMemo(
+ () => reminderEdits() ?? baselineReminderMinutes()
+ );
+ const preservedReminderCount = createMemo(() => {
+ const reminders = state().reminders;
+ if (!reminders || reminders.useDefault) return 0;
+ return (reminders.overrides ?? []).filter(
+ (reminder) => reminder.method !== REMINDER_METHOD_POPUP
+ ).length;
+ });
+ const canAddReminder = () =>
+ reminderMinutes().length + preservedReminderCount() <
+ REMINDER_OVERRIDES_MAX;
+ const reminderUpdate = () => {
+ const edits = reminderEdits();
+ if (
+ edits === undefined ||
+ arraysEqual(
+ normalizedReminderMinutes(edits),
+ normalizedReminderMinutes(baselineReminderMinutes())
+ )
+ ) {
+ return undefined;
+ }
+ return buildReminderOverrides(edits, state().reminders);
+ };
const effectiveRecurrenceLines = () =>
recurrence.recurrenceLines() ?? initialValue().recurrenceLines;
- const value = createMemo<EventEditorInitialValues>(() => ({
- ...state(),
- recurrenceLines: [...effectiveRecurrenceLines()],
- guests: selectedGuests().map(guestEmail).join(', '),
- }));
+ const value = createMemo<EventEditorInitialValues>(() => {
+ const reminders = reminderUpdate();
+ return {
+ ...state(),
+ recurrenceLines: [...effectiveRecurrenceLines()],
+ guests: selectedGuests().map(guestEmail).join(', '),
+ reminders: reminders ?? state().reminders,
+ };
+ });
const snapshot = (): EventComposerFormSnapshot => ({
title: state().title,
@@ -139,6 +213,7 @@ export function createCalendarEventFormController(
guestEmails: selectedGuests().map(guestEmail),
location: state().location,
description: state().description,
+ reminderMinutes: normalizedReminderMinutes(reminderMinutes()),
});
const initialSnapshot = (): EventComposerFormSnapshot => ({
@@ -151,6 +226,7 @@ export function createCalendarEventFormController(
guestEmails: initialGuestEmails(),
location: initialValue().location,
description: initialValue().description,
+ reminderMinutes: normalizedReminderMinutes(initialReminderMinutes()),
});
const isDirty = createMemo(() =>
@@ -158,6 +234,15 @@ export function createCalendarEventFormController(
);
const notifyChange = () => options.onChange?.(value());
+
+ const setReminderMinutes = (minutes: number[]) => {
+ const normalized = normalizedReminderMinutes(minutes);
+ if (arraysEqual(normalized, normalizedReminderMinutes(reminderMinutes()))) {
+ return;
+ }
+ setReminderEdits(normalized);
+ notifyChange();
+ };
const replaceState = (next: EventEditorInitialValues) => {
setState(cloneValue(next));
notifyChange();
@@ -201,6 +286,7 @@ export function createCalendarEventFormController(
const time = recurrence.eventTime();
if (!time || !recurrence.canSave()) return undefined;
const current = state();
+ const reminders = reminderUpdate();
return {
title: current.title,
time,
@@ -209,6 +295,7 @@ export function createCalendarEventFormController(
guestEmails: selectedGuests().map(guestEmail),
location: current.location,
description: current.description,
+ ...(reminders ? { reminders } : {}),
};
};
@@ -220,6 +307,7 @@ export function createCalendarEventFormController(
setState(cloned);
setInitialGuestEmails(guests.map(guestEmail));
setSelectedGuestsState(guests);
+ setReminderEdits(undefined);
recurrence.replaceInitialValues(cloned);
});
};
@@ -232,6 +320,10 @@ export function createCalendarEventFormController(
selectedGuests,
effectiveCalendarId,
selectedCalendarOption,
+ reminderMinutes,
+ preservedReminderCount,
+ canAddReminder,
+ setReminderMinutes,
setField,
setStart,
setAllDay,
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 5aa7cb2c3f..41c844f8a6 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
@@ -4,6 +4,8 @@ import {
type WithCustomUserInput,
} from '@core/user/combinedRecipient';
import type { EventTime } from '@service-email/generated/schemas/eventTime';
+import type { EventReminderOverride } from '@service-storage/generated/schemas/eventReminderOverride';
+import type { EventReminders } from '@service-storage/generated/schemas/eventReminders';
import {
addDays,
addHours,
@@ -61,6 +63,8 @@ export interface EventEditorInitialValues {
guests: string;
location: string;
description: string;
+ /** Per-user reminder configuration; absent means the calendar default. */
+ reminders?: EventReminders;
}
/** Calendar option displayed by the event editor. */
@@ -68,6 +72,8 @@ export interface EventEditorCalendarOption {
id: string;
label: string;
color: string;
+ /** Provider defaults shown until the event's reminders are customized. */
+ defaultReminders?: EventReminderOverride[];
}
/** Editable fields that a create/edit owner may disable. */
@@ -80,7 +86,8 @@ type EventEditorField =
| 'calendar'
| 'guests'
| 'location'
- | 'description';
+ | 'description'
+ | 'reminders';
/** Field-level disabled state supplied by a create/edit owner. */
export type EventEditorDisabledFields = Partial<
@@ -96,6 +103,8 @@ export interface EventEditorSubmitValues {
guestEmails: string[];
location: string;
description: string;
+ /** Present only when the user changed the event's reminder configuration. */
+ reminders?: EventReminders;
}
export function defaultEditorInitialValues(
@@ -112,6 +121,7 @@ export function defaultEditorInitialValues(
guests: '',
location: '',
description: '',
+ reminders: undefined,
};
}
@@ -160,10 +170,11 @@ export function calendarEventToEditorInitialValues(
start,
end: shiftDateValue(exclusiveEnd, -1),
recurrenceLines: [...event.recurrenceLines],
- calendarId: event.calendar.id,
+ calendarId: event.calendarId ?? event.calendar.id,
guests,
location: event.location ?? '',
description: event.description ?? '',
+ reminders: event.reminders,
};
}
@@ -173,10 +184,11 @@ export function calendarEventToEditorInitialValues(
start: format(new Date(event.start), DATETIME_VALUE),
end: format(new Date(event.end), DATETIME_VALUE),
recurrenceLines: [...event.recurrenceLines],
- calendarId: event.calendar.id,
+ calendarId: event.calendarId ?? event.calendar.id,
guests,
location: event.location ?? '',
description: event.description ?? '',
+ reminders: event.reminders,
};
}
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 b4fec8a675..3b5ab87bfa 100644
--- a/apps/web/src/features/calendar/hooks/use-event-editor.ts
+++ b/apps/web/src/features/calendar/hooks/use-event-editor.ts
@@ -37,9 +37,9 @@ export function useEventEditor(props: UseEventEditorProps) {
});
const initialLines = createMemo(() => props.event()?.recurrenceLines ?? []);
- const calendarsQuery = useVisibleCalendarsQuery(() => ({
- enabled: !isEdit(),
- }));
+ // Event edits also need calendar metadata to resolve reminders that still
+ // follow the calendar defaults.
+ const calendarsQuery = useVisibleCalendarsQuery();
const contacts = useContacts();
const guestOptions = createMemo(() =>
@@ -54,11 +54,16 @@ export function useEventEditor(props: UseEventEditorProps) {
const calendarOptions = createMemo(() => {
const event = props.event();
if (event) {
+ const calendarId = event.calendarId ?? event.calendar.id;
+ const calendar = calendarsQuery.data?.find(
+ (candidate) => candidate.id === calendarId
+ );
return [
{
- id: event.calendar.id,
+ id: calendarId,
label: event.calendar.name || 'Calendar',
color: event.calendar.color,
+ defaultReminders: calendar?.defaultReminders,
},
];
}
@@ -67,6 +72,7 @@ export function useEventEditor(props: UseEventEditorProps) {
id: calendar.id,
label: calendarDisplayLabel(calendar, spansInboxes()),
color: calendar.color ?? DEFAULT_CALENDAR_SOURCE.color,
+ defaultReminders: calendar.defaultReminders,
}));
});
@@ -104,6 +110,7 @@ export function useEventEditor(props: UseEventEditorProps) {
...(recurrenceChanged
? { recurrenceLines: values.recurrenceLines }
: {}),
+ ...(values.reminders ? { reminders: values.reminders } : {}),
},
});
return;
@@ -117,6 +124,7 @@ export function useEventEditor(props: UseEventEditorProps) {
location: values.location === '' ? undefined : values.location,
description: values.description === '' ? undefined : values.description,
attendees: values.guestEmails.map((email) => ({ email })),
+ ...(values.reminders ? { reminders: values.reminders } : {}),
});
};