'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' import CourseThumbnailLanding from '@components/Objects/Thumbnails/CourseThumbnailLanding' interface LandingCustomProps { landing: { sections: LandingSection[] enabled: boolean } orgslug: string } 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': return (
{/* Logo */} {section.illustration?.image.url && (
{section.illustration.image.alt}
)} {/* Content */}

{section.heading.text}

{section.subheading.text}

{section.buttons.map((button, index) => ( {button.text} ))}
) case 'text-and-image': return (

{section.title}

{section.text}

{section.buttons.map((button, index) => ( {button.text} ))}
{section.image.alt}
) case 'logos': return (
{section.title && (

{section.title}

)}
{section.logos.map((logo, index) => (
{logo.alt}
))}
) case 'people': return (

{section.title}

{section.people.map((person, index) => (
{person.name}

{person.name}

{person.description}

))}
) 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}

{featuredCourses.map((course: any) => (
))} {featuredCourses.length === 0 && (
No featured courses selected
)}
) default: return null } } return (
{landing.sections.map((section) => renderSection(section))}
) } export default LandingCustom