1- import React from "react" ;
1+ import React , { useEffect , useState } from "react" ;
22import Link from "next/link" ;
33import Layout01 from "@layout/layout-01" ;
44import type { GetServerSideProps , NextPage } from "next" ;
@@ -7,6 +7,13 @@ import { options } from "@/pages/api/auth/options";
77import SEO from "@components/seo/page-seo" ;
88import Breadcrumb from "@components/breadcrumb" ;
99
10+ type Enrollment = {
11+ id : string ;
12+ courseId : string ;
13+ status : string ;
14+ progress : number ;
15+ } ;
16+
1017type PageProps = {
1118 user : {
1219 id : string ;
@@ -27,6 +34,49 @@ type PageWithLayout = NextPage<PageProps> & {
2734} ;
2835
2936const CoursesIndex : PageWithLayout = ( { user } ) => {
37+ const [ enrollments , setEnrollments ] = useState < Enrollment [ ] > ( [ ] ) ;
38+ const [ loading , setLoading ] = useState ( true ) ;
39+
40+ useEffect ( ( ) => {
41+ fetchEnrollments ( ) ;
42+ } , [ ] ) ;
43+
44+ const fetchEnrollments = async ( ) => {
45+ try {
46+ setLoading ( true ) ;
47+ const response = await fetch ( "/api/enrollment/enroll" ) ;
48+ const data = await response . json ( ) ;
49+
50+ if ( response . ok ) {
51+ setEnrollments ( data . enrollments ) ;
52+ }
53+ } catch ( error ) {
54+ console . error ( "Error fetching enrollments:" , error ) ;
55+ } finally {
56+ setLoading ( false ) ;
57+ }
58+ } ;
59+
60+ // Helper function to check if user is enrolled in a vertical
61+ // Map vertical slugs to course titles for enrollment checking
62+ const verticalCourseMap : Record < string , string [ ] > = {
63+ "software-engineering" : [ "Software Engineering" , "Full-Stack Development" , "Web Development" ] ,
64+ "data-engineering" : [ "Data Engineering" , "Data Science" ] ,
65+ "ai-engineering" : [ "AI Engineering" , "Machine Learning" , "Artificial Intelligence" ] ,
66+ "devops" : [ "DevOps" , "Cloud Engineering" ] ,
67+ "web-development" : [ "Web Development" , "Frontend Development" ] ,
68+ } ;
69+
70+ const isEnrolledInVertical = ( verticalSlug : string ) : boolean => {
71+ const matchingTitles = verticalCourseMap [ verticalSlug ] || [ ] ;
72+ return enrollments . some (
73+ ( enrollment ) =>
74+ enrollment . status === "ACTIVE" &&
75+ matchingTitles . some ( ( title ) =>
76+ enrollment . courseId . toLowerCase ( ) . includes ( title . toLowerCase ( ) )
77+ )
78+ ) ;
79+ } ;
3080
3181 return (
3282 < >
@@ -100,13 +150,21 @@ const CoursesIndex: PageWithLayout = ({ user }) => {
100150 { /* Software Engineering Vertical */ }
101151 < div className = "tw-group tw-overflow-hidden tw-rounded-xl tw-border tw-border-gray-100 tw-bg-white tw-shadow-lg tw-transition-all tw-duration-300 hover:tw-scale-105 hover:tw-shadow-2xl" >
102152 < div className = "tw-bg-gradient-to-br tw-from-primary tw-via-primary tw-to-primary/80 tw-p-8" >
103- < div className = "tw-mb-6 tw-flex tw-items-center" >
104- < div className = "tw-rounded-lg tw-bg-white/20 tw-p-3" >
105- < i className = "fas fa-code tw-text-3xl tw-text-white" />
153+ < div className = "tw-mb-6 tw-flex tw-items-center tw-justify-between" >
154+ < div className = "tw-flex tw-items-center" >
155+ < div className = "tw-rounded-lg tw-bg-white/20 tw-p-3" >
156+ < i className = "fas fa-code tw-text-3xl tw-text-white" />
157+ </ div >
158+ < h3 className = "tw-ml-4 tw-text-2xl tw-font-bold tw-text-white" >
159+ Software Engineering
160+ </ h3 >
106161 </ div >
107- < h3 className = "tw-ml-4 tw-text-2xl tw-font-bold tw-text-white" >
108- Software Engineering
109- </ h3 >
162+ { ! loading && isEnrolledInVertical ( "software-engineering" ) && (
163+ < span className = "tw-rounded-full tw-bg-white/90 tw-px-3 tw-py-1 tw-text-xs tw-font-semibold tw-text-primary" >
164+ < i className = "fas fa-check-circle tw-mr-1" />
165+ Enrolled
166+ </ span >
167+ ) }
110168 </ div >
111169 < p className = "tw-text-lg tw-leading-relaxed tw-text-white/95" >
112170 Master full-stack development, system design, and software
@@ -143,7 +201,11 @@ const CoursesIndex: PageWithLayout = ({ user }) => {
143201 href = "/courses/software-engineering"
144202 className = "tw-group tw-flex tw-w-full tw-items-center tw-justify-center tw-rounded-lg tw-bg-primary tw-px-6 tw-py-4 tw-font-semibold tw-text-white tw-transition-all tw-duration-200 hover:tw-bg-primary/90 hover:tw-shadow-lg"
145203 >
146- < span > View Vertical</ span >
204+ < span >
205+ { ! loading && isEnrolledInVertical ( "software-engineering" )
206+ ? "Continue Learning"
207+ : "View Vertical" }
208+ </ span >
147209 < i className = "fas fa-arrow-right tw-ml-2 tw-transition-transform tw-duration-200 group-hover:tw-translate-x-1" />
148210 </ Link >
149211 </ div >
@@ -152,13 +214,21 @@ const CoursesIndex: PageWithLayout = ({ user }) => {
152214 { /* Data Engineering Vertical */ }
153215 < div className = "tw-group tw-overflow-hidden tw-rounded-xl tw-border tw-border-gray-100 tw-bg-white tw-shadow-lg tw-transition-all tw-duration-300 hover:tw-scale-105 hover:tw-shadow-2xl" >
154216 < div className = "tw-bg-gradient-to-br tw-from-secondary tw-via-secondary tw-to-secondary/80 tw-p-8" >
155- < div className = "tw-mb-6 tw-flex tw-items-center" >
156- < div className = "tw-rounded-lg tw-bg-white/20 tw-p-3" >
157- < i className = "fas fa-database tw-text-3xl tw-text-white" />
217+ < div className = "tw-mb-6 tw-flex tw-items-center tw-justify-between" >
218+ < div className = "tw-flex tw-items-center" >
219+ < div className = "tw-rounded-lg tw-bg-white/20 tw-p-3" >
220+ < i className = "fas fa-database tw-text-3xl tw-text-white" />
221+ </ div >
222+ < h3 className = "tw-ml-4 tw-text-2xl tw-font-bold tw-text-white" >
223+ Data Engineering
224+ </ h3 >
158225 </ div >
159- < h3 className = "tw-ml-4 tw-text-2xl tw-font-bold tw-text-white" >
160- Data Engineering
161- </ h3 >
226+ { ! loading && isEnrolledInVertical ( "data-engineering" ) && (
227+ < span className = "tw-rounded-full tw-bg-white/90 tw-px-3 tw-py-1 tw-text-xs tw-font-semibold tw-text-secondary" >
228+ < i className = "fas fa-check-circle tw-mr-1" />
229+ Enrolled
230+ </ span >
231+ ) }
162232 </ div >
163233 < p className = "tw-text-lg tw-leading-relaxed tw-text-white/95" >
164234 Build data pipelines, work with big data technologies, and create
@@ -195,7 +265,11 @@ const CoursesIndex: PageWithLayout = ({ user }) => {
195265 href = "/courses/data-engineering"
196266 className = "tw-group tw-flex tw-w-full tw-items-center tw-justify-center tw-rounded-lg tw-bg-secondary tw-px-6 tw-py-4 tw-font-semibold tw-text-white tw-transition-all tw-duration-200 hover:tw-bg-secondary/90 hover:tw-shadow-lg"
197267 >
198- < span > View Vertical</ span >
268+ < span >
269+ { ! loading && isEnrolledInVertical ( "data-engineering" )
270+ ? "Continue Learning"
271+ : "View Vertical" }
272+ </ span >
199273 < i className = "fas fa-arrow-right tw-ml-2 tw-transition-transform tw-duration-200 group-hover:tw-translate-x-1" />
200274 </ Link >
201275 </ div >
@@ -204,13 +278,21 @@ const CoursesIndex: PageWithLayout = ({ user }) => {
204278 { /* AI Engineering Vertical */ }
205279 < div className = "tw-group tw-overflow-hidden tw-rounded-xl tw-border tw-border-gray-100 tw-bg-white tw-shadow-lg tw-transition-all tw-duration-300 hover:tw-scale-105 hover:tw-shadow-2xl" >
206280 < div className = "tw-bg-gradient-to-br tw-from-success tw-via-success tw-to-success/80 tw-p-8" >
207- < div className = "tw-mb-6 tw-flex tw-items-center" >
208- < div className = "tw-rounded-lg tw-bg-white/20 tw-p-3" >
209- < i className = "fas fa-brain tw-text-3xl tw-text-white" />
281+ < div className = "tw-mb-6 tw-flex tw-items-center tw-justify-between" >
282+ < div className = "tw-flex tw-items-center" >
283+ < div className = "tw-rounded-lg tw-bg-white/20 tw-p-3" >
284+ < i className = "fas fa-brain tw-text-3xl tw-text-white" />
285+ </ div >
286+ < h3 className = "tw-ml-4 tw-text-2xl tw-font-bold tw-text-white" >
287+ AI Engineering
288+ </ h3 >
210289 </ div >
211- < h3 className = "tw-ml-4 tw-text-2xl tw-font-bold tw-text-white" >
212- AI Engineering
213- </ h3 >
290+ { ! loading && isEnrolledInVertical ( "ai-engineering" ) && (
291+ < span className = "tw-rounded-full tw-bg-white/90 tw-px-3 tw-py-1 tw-text-xs tw-font-semibold tw-text-success" >
292+ < i className = "fas fa-check-circle tw-mr-1" />
293+ Enrolled
294+ </ span >
295+ ) }
214296 </ div >
215297 < p className = "tw-text-lg tw-leading-relaxed tw-text-white/95" >
216298 Develop AI/ML models, work with neural networks, and build
@@ -247,7 +329,11 @@ const CoursesIndex: PageWithLayout = ({ user }) => {
247329 href = "/courses/ai-engineering"
248330 className = "tw-group tw-flex tw-w-full tw-items-center tw-justify-center tw-rounded-lg tw-bg-success tw-px-6 tw-py-4 tw-font-semibold tw-text-white tw-transition-all tw-duration-200 hover:tw-bg-success/90 hover:tw-shadow-lg"
249331 >
250- < span > View Vertical</ span >
332+ < span >
333+ { ! loading && isEnrolledInVertical ( "ai-engineering" )
334+ ? "Continue Learning"
335+ : "View Vertical" }
336+ </ span >
251337 < i className = "fas fa-arrow-right tw-ml-2 tw-transition-transform tw-duration-200 group-hover:tw-translate-x-1" />
252338 </ Link >
253339 </ div >
0 commit comments