diff --git a/src/app/(app)/course/[courseId]/home/(hooks)/useTeamSets.tsx b/src/app/(app)/course/[courseId]/home/(hooks)/useTeamSets.tsx new file mode 100644 index 0000000..e69de29 diff --git a/src/app/(app)/course/[courseId]/home/(hooks)/useTotalStudents.tsx b/src/app/(app)/course/[courseId]/home/(hooks)/useTotalStudents.tsx new file mode 100644 index 0000000..5ef887c --- /dev/null +++ b/src/app/(app)/course/[courseId]/home/(hooks)/useTotalStudents.tsx @@ -0,0 +1,29 @@ +"use client"; + +import { useCourse } from "@/app/(app)/course/[courseId]/(hooks)/useCourse"; +import { useQuery } from "@tanstack/react-query"; + +const useTotalStudentsQuery = ({ courseId }: { courseId: number }) => { + const studentQuery = useQuery({ + queryKey: [`courses/${courseId}/students`], + }); + + return { + getTotalStudentsAsync: studentQuery.refetch, + ...studentQuery, + }; +}; + +export const useTotalStudents = () => { + const { courseId } = useCourse(); + const { data, isLoading, error, getTotalStudentsAsync } = useTotalStudentsQuery({ + courseId: Number(courseId), + }); + + return { + totalStudents: data?.count ?? 0, + isLoading, + error, + refetch: getTotalStudentsAsync, + }; +}; diff --git a/src/app/(app)/course/[courseId]/home/page.tsx b/src/app/(app)/course/[courseId]/home/page.tsx index bd6666d..a388557 100644 --- a/src/app/(app)/course/[courseId]/home/page.tsx +++ b/src/app/(app)/course/[courseId]/home/page.tsx @@ -1,16 +1,23 @@ "use client" import { useCourse } from "@/app/(app)/course/[courseId]/(hooks)/useCourse" import PageView from "@/components/views/Page" +import { useToast } from "@/hooks/use-toast" import { CircularProgressbar, buildStyles } from 'react-circular-progressbar' import 'react-circular-progressbar/dist/styles.css' -import { useStudents } from "../students/(hooks)/useStudents" import { CalculateOnboardingCompletion } from "./(hooks)/calculateOnboardingCompletion" +import { useTotalStudents } from "./(hooks)/useTotalStudents" const HomePage = () => { const { courseId } = useCourse() const { completionPercentage, nextStepTitle } = CalculateOnboardingCompletion() - const {totalStudents} = useStudents() + const { totalStudents, error } = useTotalStudents(); + const {toast} = useToast(); - console.log(totalStudents) + if (error) { + toast({ + title: "Error fetching students", + description: "There was an error fetching the number of student enrolled on your LMS.", + }) + } const attributes = [ "Requirement #1", @@ -81,7 +88,7 @@ const HomePage = () => {

Sign up Stats

diff --git a/src/app/(app)/course/[courseId]/page.tsx b/src/app/(app)/course/[courseId]/page.tsx index becb379..d3ecb63 100644 --- a/src/app/(app)/course/[courseId]/page.tsx +++ b/src/app/(app)/course/[courseId]/page.tsx @@ -1,7 +1,7 @@ import { redirect } from "next/navigation" const CourseHomepage = async ({ params }: { params: { courseId: string } }) => { - redirect(`/course/${params.courseId}/setup`) + redirect(`/course/${params.courseId}/home`) } export default CourseHomepage diff --git a/src/app/courses/page.tsx b/src/app/courses/page.tsx index 9056732..35ed77b 100644 --- a/src/app/courses/page.tsx +++ b/src/app/courses/page.tsx @@ -84,7 +84,7 @@ export default function CoursesPage() { router.push(`/course/${membership.id}/setup`)} + onClick={() => router.push(`/course/${membership.id}/home`)} > @@ -110,7 +110,7 @@ export default function CoursesPage() { router.push(`/course/${membership.id}/setup`)} + onClick={() => router.push(`/course/${membership.id}/home`)} >