fix: clear a calendar's default reminders with an empty list instead of null #1209

This commit is contained in:
Linus Rath
2026-10-13 15:56:10 +02:00
parent 82450f3345
commit c878e51fce
2 changed files with 5 additions and 8 deletions
@@ -78,7 +78,7 @@ describe('Calendar default reminders settings', () => {
);
});
it('clears a list by sending null once its last reminder is removed', async () => {
it('clears a list by sending an empty map, which Stalwart accepts where it refuses null', async () => {
useCalendarStore.setState({
calendars: [makeCalendar({
defaultAlertsWithTime: {
@@ -93,6 +93,6 @@ describe('Calendar default reminders settings', () => {
fireEvent.click(screen.getByText('save'));
await waitFor(() => expect(updateCalendar).toHaveBeenCalledTimes(1));
expect(updateCalendar.mock.calls[0][2]).toEqual({ defaultAlertsWithTime: null, defaultAlertsWithoutTime: null });
expect(updateCalendar.mock.calls[0][2]).toEqual({ defaultAlertsWithTime: {}, defaultAlertsWithoutTime: {} });
});
});
@@ -172,13 +172,10 @@ export function CalendarDefaultAlertsForm({
const [timedRows, setTimedRows] = useState<AlertRow[]>(timed.rows);
const [allDayRows, setAllDayRows] = useState<AlertRow[]>(allDay.rows);
const toMap = (rows: AlertRow[], preserved: typeof timed.preserved) => {
const map = rowsToAlerts(rows, preserved);
return Object.keys(map).length > 0 ? map : null;
};
// An emptied list is sent as {}: Stalwart refuses null for these maps.
const submit = () => onSave({
defaultAlertsWithTime: toMap(timedRows, timed.preserved),
defaultAlertsWithoutTime: toMap(allDayRows, allDay.preserved),
defaultAlertsWithTime: rowsToAlerts(timedRows, timed.preserved),
defaultAlertsWithoutTime: rowsToAlerts(allDayRows, allDay.preserved),
});
return (