diff --git a/apps/web/components/Landings/LandingCustom.tsx b/apps/web/components/Landings/LandingCustom.tsx index 17777af8..b83fdc8f 100644 --- a/apps/web/components/Landings/LandingCustom.tsx +++ b/apps/web/components/Landings/LandingCustom.tsx @@ -1,5 +1,11 @@ +'use client' + import React from 'react' import { LandingSection } from '@components/Dashboard/Pages/Org/OrgEditLanding/landing_types' +import CourseThumbnail from '@components/Objects/Thumbnails/CourseThumbnail' +import useSWR from 'swr' +import { getOrgCourses } from '@services/courses/courses' +import { useLHSession } from '@components/Contexts/LHSessionContext' interface LandingCustomProps { landing: { @@ -10,6 +16,15 @@ interface LandingCustomProps { } function LandingCustom({ landing, orgslug }: LandingCustomProps) { + const session = useLHSession() as any + const access_token = session?.data?.tokens?.access_token + + // Fetch all courses for the organization + const { data: allCourses } = useSWR( + orgslug ? [orgslug, access_token] : null, + ([slug, token]) => getOrgCourses(slug, null, token) + ) + const renderSection = (section: LandingSection) => { switch (section.type) { case 'hero': @@ -149,19 +164,42 @@ function LandingCustom({ landing, orgslug }: LandingCustomProps) { ) case 'featured-courses': + if (!allCourses) { + return ( +
+

{section.title}

+
Loading courses...
+
+ ) + } + + const featuredCourses = allCourses.filter((course: any) => + section.courses.includes(course.course_uuid) + ) + return (
-

{section.title}

-
- {section.courses.map((course, index) => ( -
- {/* Course card content - you'll need to fetch course details */} -

Course ID: {course.course_uuid}

+

{section.title}

+
+ {featuredCourses.map((course: any) => ( +
+
))} + {featuredCourses.length === 0 && ( +
+ No featured courses selected +
+ )}
)