Skip to content

Commit e43d54a

Browse files
committed
fix(scheduled-tasks): restore the prior cadence when re-enabling recurrence
Toggling Recurring off collapsed frequency to 'once' but toggling back on forced 'daily' and cleared weekdays, so pausing a weekly/weekdays/monthly task and re-enabling it silently reset it to daily. Cache the last recurring cadence in a ref (written during render) and reinstate it on toggle-on, so a paused "Weekly on Mon" returns as weekly. This also subsumes the custom-cron restore — the ref remembers 'custom' across the one-time interval — so the toggle no longer special-cases cron.
1 parent 9512335 commit e43d54a

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
'use client'
22

3+
import { useRef } from 'react'
34
import { format } from 'date-fns'
45
import { ChipDatePicker, ChipModalField, Switch } from '@/components/emcn'
5-
import type { Recurrence } from '@/app/workspace/[workspaceId]/scheduled-tasks/utils/recurrence'
6+
import type {
7+
Recurrence,
8+
RecurrenceFrequency,
9+
} from '@/app/workspace/[workspaceId]/scheduled-tasks/utils/recurrence'
610

711
const WEEKDAY_PRESET = [1, 2, 3, 4, 5]
812
/** Seed count when the user first chooses "ends after N runs". */
@@ -50,6 +54,16 @@ interface RecurrenceSectionProps {
5054
* primitives.
5155
*/
5256
export function RecurrenceSection({ recurrence, onChange, launchDate }: RecurrenceSectionProps) {
57+
/**
58+
* The cadence to reinstate when recurrence is toggled back on. Toggling off
59+
* collapses `frequency` to `once`, dropping which preset was active, so the
60+
* last recurring cadence is cached here and restored — a paused "Weekly on
61+
* Mon" returns as weekly, not silently reset to daily. Written during render
62+
* (an idempotent cache), so it is current before the toggle handler reads it.
63+
*/
64+
const lastRecurringFrequency = useRef<RecurrenceFrequency>(DEFAULT_RECURRING_FREQUENCY)
65+
if (recurrence.frequency !== 'once') lastRecurringFrequency.current = recurrence.frequency
66+
5367
const launch = new Date(`${launchDate}T00:00`)
5468
const isRecurring = recurrence.frequency !== 'once'
5569

@@ -63,21 +77,13 @@ export function RecurrenceSection({ recurrence, onChange, launchDate }: Recurren
6377

6478
/**
6579
* Flips the one-time launch into a repeat and back. Toggling off keeps the
66-
* recurrence shape (cadence, end, and a passed-through `custom` cron) on the
67-
* object and only sets `frequency: 'once'` — the wire ignores everything but
68-
* `frequency` for a one-time task — so toggling back on restores `custom`
69-
* rather than silently rewriting a conversationally-authored cron to `daily`.
80+
* recurrence shape (weekdays, end, and a passed-through `custom` cron) on the
81+
* object and only collapses `frequency` to `once`; toggling back on reinstates
82+
* the remembered cadence, so neither a weekly preset nor a conversationally
83+
* authored custom cron is silently rewritten to daily.
7084
*/
7185
const handleRecurringToggle = (checked: boolean) => {
72-
if (!checked) {
73-
onChange({ ...recurrence, frequency: 'once' })
74-
return
75-
}
76-
onChange({
77-
...recurrence,
78-
frequency: recurrence.cron ? 'custom' : DEFAULT_RECURRING_FREQUENCY,
79-
weekdays: [],
80-
})
86+
onChange({ ...recurrence, frequency: checked ? lastRecurringFrequency.current : 'once' })
8187
}
8288

8389
const handleFrequencyChange = (value: string) => {

0 commit comments

Comments
 (0)