diff --git a/frontend/src/pages/courses/courses-view.tsx b/frontend/src/pages/courses/courses-view.tsx index bc3c195..007a0c1 100644 --- a/frontend/src/pages/courses/courses-view.tsx +++ b/frontend/src/pages/courses/courses-view.tsx @@ -1,14 +1,12 @@ + import React, { ReactElement, useEffect } from 'react'; import Head from 'next/head' -import DatePicker from "react-datepicker"; -import "react-datepicker/dist/react-datepicker.css"; import dayjs from "dayjs"; import {useAppDispatch, useAppSelector} from "../../stores/hooks"; import {useRouter} from "next/router"; import { fetch } from '../../stores/courses/coursesSlice' -import {saveFile} from "../../helpers/fileSaver"; +import { fetch as fetchEnrollments, create as enrollInCourse } from '../../stores/enrollments/enrollmentsSlice' import dataFormatter from '../../helpers/dataFormatter'; -import ImageField from "../../components/ImageField"; import LayoutAuthenticated from "../../layouts/Authenticated"; import {getPageTitle} from "../../config"; import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton"; @@ -16,781 +14,235 @@ import SectionMain from "../../components/SectionMain"; import CardBox from "../../components/CardBox"; import BaseButton from "../../components/BaseButton"; import BaseDivider from "../../components/BaseDivider"; -import {mdiChartTimelineVariant} from "@mdi/js"; -import {SwitchField} from "../../components/SwitchField"; -import FormField from "../../components/FormField"; +import * as icon from "@mdi/js"; +import BaseIcon from "../../components/BaseIcon"; const CoursesView = () => { const router = useRouter() const dispatch = useAppDispatch() const { courses } = useAppSelector((state) => state.courses) + const { currentUser } = useAppSelector((state) => state.auth) + const { enrollments } = useAppSelector((state) => state.enrollments) - const { id } = router.query; - - function removeLastCharacter(str) { - console.log(str,`str`) - return str.slice(0, -1); - } useEffect(() => { - dispatch(fetch({ id })); - }, [dispatch, id]); + if (id) { + dispatch(fetch({ id })); + } + if (currentUser) { + dispatch(fetchEnrollments({ query: `?student=${currentUser.id}` })); + } + }, [dispatch, id, currentUser]); + const isEnrolled = Array.isArray(enrollments) && enrollments.some((e: any) => e.courseId === id); + const isLearner = currentUser?.app_role?.name === 'Learner'; + + const handleEnroll = async () => { + if (!id || !currentUser) return; + const data = { + course: id, + student: currentUser.id, + status: 'active', + enrolled_at: new Date().toISOString() + }; + await dispatch(enrollInCourse(data)); + dispatch(fetchEnrollments({ query: `?student=${currentUser.id}` })); + }; return ( <>
-Title
-{courses?.title}
-Subtitle
-{courses?.subtitle}
-Description
- {courses.description - ? - :No data
- } -Thumbnail
- {courses?.thumbnail?.length - ? ( -No Thumbnail
- } + )} +Status
-{courses?.status ?? 'No data'}
-Level
-{courses?.level ?? 'No data'}
-Category
-{courses?.category}
-Language
-{courses?.language}
-EstimatedDuration(Minutes)
-{courses?.estimated_duration_minutes || 'No data'}
-Instructor
- - -{courses?.instructor?.firstName ?? 'No data'}
- - - - - - - - - - - - - - - - - - -No PublishedAt
} -Lessons Course
-| Title | - - - - - - - -VideoURL | - - - -OrderIndex | - - - -Status | - - - -IsPreview | - - - -EstimatedMinutes | - - - -PublishedAt | - - -
|---|---|---|---|---|---|---|
| - { item.title } - | - - - - - - - -- { item.video_url } - | - - - -- { item.order_index } - | - - - -- { item.status } - | - - - -- { dataFormatter.booleanFormatter(item.is_preview) } - | - - - -- { item.estimated_minutes } - | - - - -- { dataFormatter.dateTimeFormatter(item.published_at) } - | - - -
{courses?.subtitle}
Enrollments Course
-| Status | - - - -EnrolledAt | - - - -CompletedAt | - - - -ProgressPercent | - - -
|---|---|---|---|
| - { item.status } - | - - - -- { dataFormatter.dateTimeFormatter(item.enrolled_at) } - | - - - -- { dataFormatter.dateTimeFormatter(item.completed_at) } - | - - - -- { item.progress_percent } - | - - -
No description available.
+ }Course_announcements Course
-| Title | - - - - - -PublishedAt | - - - -IsPublished | - - -
|---|---|---|
| - { item.title } - | - - - - - -- { dataFormatter.dateTimeFormatter(item.published_at) } - | - - - -- { dataFormatter.booleanFormatter(item.is_published) } - | - - -
Course_reviews Course
-| Rating | - - - -Comment | - - - -ReviewedAt | - - - -IsPublished | - - -
|---|---|---|---|
| - { item.rating } - | - - - -- { item.comment } - | - - - -- { dataFormatter.dateTimeFormatter(item.reviewed_at) } - | - - - -- { dataFormatter.booleanFormatter(item.is_published) } - | - - -
Level
+{courses?.level || 'Beginner'}
+Language
+{courses?.language || 'English'}
+Duration
+{courses?.estimated_duration_minutes || '0'} min
+Published
+{courses?.published_at ? dayjs(courses.published_at).format('MMM D, YYYY') : 'TBA'}
+{lesson.title}
+{lesson.estimated_minutes || 0} minutes
+No lessons available for this course yet.
+ )} +Ready to start your journey in {courses?.title}?
+Join thousands of students learning this today!
+{courses?.instructor?.firstName} {courses?.instructor?.lastName || ''}
+Expert Course Creator
+Total Courses
+{courses.length || 0}
+Total Users
+...
+Total Enrollments
+...
+- {`${widgetsRole?.role?.label || 'Users'}'s widgets`} -
- )} + return ( + <> +{enrollment.course?.subtitle}
+You haven't enrolled in any courses yet.
+Browse available courses below to get started!
+{course.category}
+{course.description?.replace(/<[^>]*>?/gm, '')}
This is a React.js/Node.js app generated by the Flatlogic Web App Generator
-For guides and documentation please check - your local README.md and the Flatlogic documentation
+ {/* Hero Section */} ++ Access high-quality education from anywhere in the world. Start your journey today with our comprehensive library of lessons. +
+© 2026 {title}. All rights reserved
- - Privacy Policy - -+ Everything you need to succeed +
+Well-organized content that guides you step-by-step through complex topics.
+Learn from industry professionals with years of real-world experience.
+Keep track of your learning milestones and completed lessons easily.
+Earn recognition for your hard work upon course completion.
+