diff --git a/src/components/GenerateCourse/AICourseContent.tsx b/src/components/GenerateCourse/AICourseContent.tsx index 9e0c4564c..c03a6f473 100644 --- a/src/components/GenerateCourse/AICourseContent.tsx +++ b/src/components/GenerateCourse/AICourseContent.tsx @@ -22,6 +22,7 @@ import { AILimitsPopup } from './AILimitsPopup'; import { RegenerateOutline } from './RegenerateOutline'; type AICourseContentProps = { + courseCreatorId: string; courseSlug?: string; course: AiCourse; isLoading: boolean; @@ -30,7 +31,14 @@ type AICourseContentProps = { }; export function AICourseContent(props: AICourseContentProps) { - const { course, courseSlug, isLoading, error, onRegenerateOutline } = props; + const { + course, + courseSlug, + isLoading, + error, + onRegenerateOutline, + courseCreatorId, + } = props; const [showUpgradeModal, setShowUpgradeModal] = useState(false); const [showAILimitsPopup, setShowAILimitsPopup] = useState(false); @@ -382,6 +390,7 @@ export function AICourseContent(props: AICourseContentProps) { > {viewMode === 'module' && ( <AICourseLesson + courseCreatorId={courseCreatorId} courseSlug={courseSlug!} progress={aiCourseProgress} activeModuleIndex={activeModuleIndex} diff --git a/src/components/GenerateCourse/AICourseLesson.tsx b/src/components/GenerateCourse/AICourseLesson.tsx index c213aac01..8186d7fbf 100644 --- a/src/components/GenerateCourse/AICourseLesson.tsx +++ b/src/components/GenerateCourse/AICourseLesson.tsx @@ -27,8 +27,11 @@ import { queryClient } from '../../stores/query-client'; import { AICourseFollowUp } from './AICourseFollowUp'; import './AICourseFollowUp.css'; import { RegenerateLesson } from './RegenerateLesson'; +import { useAuth } from '../../hooks/use-auth'; +import { useToast } from '../../hooks/use-toast'; type AICourseLessonProps = { + courseCreatorId: string; courseSlug: string; progress: string[]; @@ -47,6 +50,7 @@ type AICourseLessonProps = { export function AICourseLesson(props: AICourseLessonProps) { const { + courseCreatorId, courseSlug, progress = [], @@ -63,6 +67,8 @@ export function AICourseLesson(props: AICourseLessonProps) { onUpgrade, } = props; + const user = useAuth(); + const toast = useToast(); const [isLoading, setIsLoading] = useState(true); const [isGenerating, setIsGenerating] = useState(false); const [error, setError] = useState(''); @@ -182,6 +188,9 @@ export function AICourseLesson(props: AICourseLessonProps) { data, ); }, + onError: (error) => { + toast.error(error?.message || 'Something went wrong'); + }, }, queryClient, ); @@ -203,7 +212,9 @@ export function AICourseLesson(props: AICourseLessonProps) { isLoading; const cantGoBack = - (activeModuleIndex === 0 && activeLessonIndex === 0) || isGenerating || isLoading; + (activeModuleIndex === 0 && activeLessonIndex === 0) || + isGenerating || + isLoading; return ( <div className="mx-auto max-w-4xl"> @@ -231,7 +242,9 @@ export function AICourseLesson(props: AICourseLessonProps) { }} /> <button - disabled={isLoading || isTogglingDone} + disabled={ + isLoading || isTogglingDone || user?.id !== courseCreatorId + } className={cn( 'flex items-center gap-1.5 rounded-full bg-black py-1 pl-2 pr-3 text-sm text-white hover:bg-gray-800 disabled:opacity-50 max-lg:text-xs', isLessonDone diff --git a/src/components/GenerateCourse/GenerateAICourse.tsx b/src/components/GenerateCourse/GenerateAICourse.tsx index 95ea38935..64a021daf 100644 --- a/src/components/GenerateCourse/GenerateAICourse.tsx +++ b/src/components/GenerateCourse/GenerateAICourse.tsx @@ -7,10 +7,12 @@ import { generateCourse } from '../../helper/generate-ai-course'; import { useQuery } from '@tanstack/react-query'; import { getAiCourseOptions } from '../../queries/ai-course'; import { queryClient } from '../../stores/query-client'; +import { useAuth } from '../../hooks/use-auth'; type GenerateAICourseProps = {}; export function GenerateAICourse(props: GenerateAICourseProps) { + const user = useAuth(); const [term, setTerm] = useState(''); const [difficulty, setDifficulty] = useState(''); const [sessionId, setSessionId] = useState(''); @@ -149,6 +151,7 @@ export function GenerateAICourse(props: GenerateAICourseProps) { return ( <AICourseContent + courseCreatorId={user?.id!} courseSlug={courseSlug} course={course} isLoading={isLoading} diff --git a/src/components/GenerateCourse/GetAICourse.tsx b/src/components/GenerateCourse/GetAICourse.tsx index 2ce9ee67a..27fdef95a 100644 --- a/src/components/GenerateCourse/GetAICourse.tsx +++ b/src/components/GenerateCourse/GetAICourse.tsx @@ -92,6 +92,7 @@ export function GetAICourse(props: GetAICourseProps) { return ( <AICourseContent + courseCreatorId={aiCourse?.userId!} course={{ title: aiCourse?.title || '', modules: aiCourse?.modules || [],