refactor: improve error message and handle active schedule deletion (#243)

This commit is contained in:
Sriram Hariharan
2024-10-01 10:42:36 -05:00
committed by GitHub
parent 5ca24dab82
commit 8bb6f901dc
4 changed files with 36 additions and 11 deletions

View File

@@ -17,10 +17,14 @@ export default async function deleteSchedule(scheduleId: string): Promise<string
throw new Error(`Schedule ${scheduleId} does not exist`);
}
if (scheduleIndex === activeIndex) {
throw new Error('Cannot delete active schedule');
throw new Error('You cannot delete your active schedule! Please switch to another schedule before deleting.');
}
schedules.splice(scheduleIndex, 1);
await UserScheduleStore.set('schedules', schedules);
if (activeIndex >= schedules.length) {
await UserScheduleStore.set('activeIndex', schedules.length - 1);
}
return undefined;
}