Skip to content

Commit 9512335

Browse files
committed
fix(scheduled-tasks): clear custom cron when switching frequency away from custom
The Recurring toggle restores `frequency: 'custom'` when `recurrence.cron` is truthy, but switching the frequency dropdown away from custom kept the stale cron on the object — so editing a custom-cron task to Daily, then toggling Recurring off and back on, snapped it back to Custom and persisted the old cron. Clear `cron` in the non-custom frequency branches so it is present only while the cadence is genuinely custom (matching the type's "custom only" invariant), making the toggle's restore signal accurate. Also document the unreachable `once` branch in frequencyOptionFor as a type-exhaustiveness fallback (keeps the return type without a cast).
1 parent 2fce12f commit 9512335

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/scheduled-tasks/components/task-modal/recurrence-section.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ function isWeekdayPreset(weekdays: number[]): boolean {
2323
function frequencyOptionFor(recurrence: Recurrence): FrequencyOption {
2424
if (recurrence.frequency === 'weekly')
2525
return isWeekdayPreset(recurrence.weekdays) ? 'weekdays' : 'weekly'
26+
// Exhaustiveness fallback: callers gate on `isRecurring`, so `once` never
27+
// reaches here at runtime, but the dropdown can't represent it — mapping it to
28+
// a recurring default keeps the return type `FrequencyOption` without a cast.
2629
if (recurrence.frequency === 'once') return DEFAULT_RECURRING_FREQUENCY
2730
return recurrence.frequency
2831
}
@@ -81,16 +84,26 @@ export function RecurrenceSection({ recurrence, onChange, launchDate }: Recurren
8184
const option = value as FrequencyOption
8285
switch (option) {
8386
case 'daily':
84-
onChange({ ...recurrence, frequency: 'daily', weekdays: [] })
87+
onChange({ ...recurrence, frequency: 'daily', weekdays: [], cron: undefined })
8588
return
8689
case 'weekly':
87-
onChange({ ...recurrence, frequency: 'weekly', weekdays: [launch.getDay()] })
90+
onChange({
91+
...recurrence,
92+
frequency: 'weekly',
93+
weekdays: [launch.getDay()],
94+
cron: undefined,
95+
})
8896
return
8997
case 'weekdays':
90-
onChange({ ...recurrence, frequency: 'weekly', weekdays: [...WEEKDAY_PRESET] })
98+
onChange({
99+
...recurrence,
100+
frequency: 'weekly',
101+
weekdays: [...WEEKDAY_PRESET],
102+
cron: undefined,
103+
})
91104
return
92105
case 'monthly':
93-
onChange({ ...recurrence, frequency: 'monthly', weekdays: [] })
106+
onChange({ ...recurrence, frequency: 'monthly', weekdays: [], cron: undefined })
94107
return
95108
case 'custom':
96109
onChange({ ...recurrence, frequency: 'custom' })

0 commit comments

Comments
 (0)