Skip to content

Commit 21eeada

Browse files
committed
fix(scheduled-tasks): clear duplicate pre-fill when starting a fresh create
The create modal had two open-sources (isCreateOpen + duplicatePrefill) that weren't coordinated. Starting a header/slot create now clears any duplicate pre-fill (and duplicating closes any open create), so a stale duplicate draft can never bleed into a blank or slot-seeded create.
1 parent 3a4d248 commit 21eeada

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

apps/sim/app/workspace/[workspaceId]/scheduled-tasks/scheduled-tasks.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,30 @@ export function ScheduledTasks() {
5656
/** Pre-fill for a duplicate — opens the create modal seeded from an existing task. */
5757
const [duplicatePrefill, setDuplicatePrefill] = useState<TaskPrefill | null>(null)
5858

59+
/** Starts a blank create, clearing any duplicate pre-fill so it can't bleed in. */
60+
const handleOpenCreate = useCallback(() => {
61+
setDuplicatePrefill(null)
62+
calendar.openCreate()
63+
}, [calendar.openCreate])
64+
65+
/** Starts a slot-seeded create, clearing any duplicate pre-fill. */
66+
const handleSelectSlot = useCallback(
67+
(date: Date, time?: string) => {
68+
setDuplicatePrefill(null)
69+
calendar.selectSlot(date, time)
70+
},
71+
[calendar.selectSlot]
72+
)
73+
5974
const handleDuplicate = useCallback(() => {
6075
if (!contextTask) return
6176
const seed = tasks.editSeedFor(contextTask)
6277
if (!seed) return
6378
const { scheduleId: _scheduleId, ...prefill } = seed
79+
calendar.closeCreate()
6480
setDuplicatePrefill(prefill)
6581
// eslint-disable-next-line react-hooks/exhaustive-deps
66-
}, [contextTask])
82+
}, [contextTask, calendar.closeCreate])
6783

6884
const handleTaskContextMenu = useCallback(
6985
(task: ScheduledTask, e: React.MouseEvent) => {
@@ -98,11 +114,11 @@ export function ScheduledTasks() {
98114
{
99115
text: 'New scheduled task',
100116
icon: Plus,
101-
onSelect: calendar.openCreate,
117+
onSelect: handleOpenCreate,
102118
variant: 'primary',
103119
},
104120
],
105-
[calendar.openCreate]
121+
[handleOpenCreate]
106122
)
107123

108124
return (
@@ -118,7 +134,7 @@ export function ScheduledTasks() {
118134
onNext={calendar.next}
119135
onToday={calendar.goToday}
120136
onSelectDate={calendar.goToDate}
121-
onSelectSlot={calendar.selectSlot}
137+
onSelectSlot={handleSelectSlot}
122138
onSelectTask={tasks.openTask}
123139
onTaskContextMenu={handleTaskContextMenu}
124140
onShowDay={calendar.openDay}
@@ -130,7 +146,7 @@ export function ScheduledTasks() {
130146
isOpen={isListContextMenuOpen}
131147
position={listContextMenuPosition}
132148
onClose={closeListContextMenu}
133-
onCreateSchedule={calendar.openCreate}
149+
onCreateSchedule={handleOpenCreate}
134150
/>
135151

136152
<TaskContextMenu

0 commit comments

Comments
 (0)