Skip to content

Commit 4d06d7f

Browse files
fix(lesson-editor): redirect to edit URL after first draft save to prevent duplicate lessons
When creating a new lesson and clicking Save Draft, the context had no initialData so every subsequent save called createLesson again instead of updateLesson. Fix: redirect to /lessons/:id after the first successful create regardless of publish state, so the edit page loads with initialData set and all further saves hit updateLesson. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 433e33b commit 4d06d7f

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

components/teacher/lesson-editor/lesson-editor-context.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ export function LessonEditorProvider({
167167

168168
if (publish) {
169169
router.push(`/dashboard/teacher/courses/${courseId}`)
170+
} else if (!initialData) {
171+
// New lesson saved as draft — redirect to edit URL so subsequent saves
172+
// call updateLesson instead of createLesson (prevents duplicates)
173+
router.push(`/dashboard/teacher/courses/${courseId}/lessons/${result.data.lessonId}`)
170174
} else {
171175
setSaveSuccess(true)
172176
setLoading(false)

0 commit comments

Comments
 (0)