-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from litespace-org/mk/student-dashboard
feat(ui): implemented full student dashboard
- Loading branch information
Showing
22 changed files
with
617 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Route } from "@/types/routes"; | ||
import { useFindUserRooms } from "@litespace/headless/chat"; | ||
import { useUser } from "@litespace/headless/context/user"; | ||
import { | ||
ChatSummary as Summary, | ||
type ChatSummaryProps, | ||
} from "@litespace/luna/Chat"; | ||
import { orUndefined } from "@litespace/sol/utils"; | ||
import { IRoom } from "@litespace/types"; | ||
import dayjs from "dayjs"; | ||
import { useMemo } from "react"; | ||
|
||
function asRooms( | ||
list: IRoom.FindUserRoomsApiRecord[] | null | ||
): ChatSummaryProps["rooms"] { | ||
if (!list) return []; | ||
|
||
return list.map((room) => ({ | ||
id: room.roomId, | ||
url: Route.Chat.concat("?room=", room.roomId.toString()), | ||
name: orUndefined(room.otherMember?.name), | ||
image: orUndefined(room.otherMember?.image), | ||
message: room.latestMessage?.text || "TODO", | ||
sentAt: room.latestMessage?.updatedAt || dayjs().toString(), // TODO | ||
read: room.unreadMessagesCount === 0, | ||
})); | ||
} | ||
|
||
export const ChatSummary = () => { | ||
const { user } = useUser(); | ||
const rooms = useFindUserRooms(user?.id, { size: 4 }); | ||
const organizedRooms = useMemo(() => asRooms(rooms.list), [rooms.list]); | ||
|
||
return ( | ||
<Summary | ||
loading={rooms.query.isPending} | ||
error={rooms.query.isError} | ||
retry={rooms.query.refetch} | ||
chatsUrl={Route.Chat} | ||
rooms={organizedRooms} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Route } from "@/types/routes"; | ||
import { useUser } from "@litespace/headless/context/user"; | ||
import { useInfiniteLessons } from "@litespace/headless/lessons"; | ||
import { useFormatMessage } from "@litespace/luna/hooks/intl"; | ||
import { PastLessonsTable } from "@litespace/luna/Lessons"; | ||
import { Typography } from "@litespace/luna/Typography"; | ||
import { ILesson, IUser } from "@litespace/types"; | ||
import { useCallback, useMemo, useState } from "react"; | ||
import BookLesson from "@/components/Lessons/BookLesson"; | ||
import { InView } from "react-intersection-observer"; | ||
import dayjs from "dayjs"; | ||
import { Loading } from "@litespace/luna/Loading"; | ||
|
||
function asLessons(list: ILesson.FindUserLessonsApiResponse["list"] | null) { | ||
if (!list) return []; | ||
|
||
return list.map((lesson) => { | ||
const teacher = lesson.members.find( | ||
(member) => member.role === IUser.Role.Tutor | ||
); | ||
return { | ||
id: lesson.lesson.id, | ||
start: lesson.lesson.start, | ||
duration: lesson.lesson.duration, | ||
tutor: { | ||
id: teacher?.userId || 0, | ||
name: teacher?.name || null, | ||
imageUrl: teacher?.image || null, | ||
}, | ||
}; | ||
}); | ||
} | ||
|
||
export const PastLessons = () => { | ||
const intl = useFormatMessage(); | ||
const [tutor, setTutor] = useState<number | null>(null); | ||
|
||
const closeRebookingDialog = useCallback(() => { | ||
setTutor(null); | ||
}, []); | ||
|
||
const openRebookingDialog = useCallback((tutorId: number) => { | ||
setTutor(tutorId); | ||
}, []); | ||
|
||
const { user } = useUser(); | ||
const now = useMemo(() => dayjs.utc().toISOString(), []); | ||
|
||
const lessonsQuery = useInfiniteLessons({ | ||
users: user ? [user?.id] : [], | ||
userOnly: true, | ||
before: now, | ||
}); | ||
|
||
const lessons = useMemo( | ||
() => asLessons(lessonsQuery.list), | ||
[lessonsQuery.list] | ||
); | ||
|
||
return ( | ||
<div className="grid gap-6 "> | ||
<Typography | ||
element="subtitle-2" | ||
weight="bold" | ||
className="text-natural-950 " | ||
> | ||
{intl("student-dashboard.previous-lessons.title")} | ||
</Typography> | ||
|
||
<PastLessonsTable | ||
tutorsRoute={Route.Tutors} | ||
onRebook={openRebookingDialog} | ||
lessons={lessons} | ||
loading={lessonsQuery.query.isPending} | ||
error={lessonsQuery.query.isError} | ||
retry={lessonsQuery.query.refetch} | ||
/> | ||
|
||
{!lessonsQuery.query.isFetching && lessonsQuery.query.hasNextPage ? ( | ||
<InView | ||
as="div" | ||
onChange={(inView) => { | ||
if (inView && lessonsQuery.query.hasNextPage) lessonsQuery.more(); | ||
}} | ||
/> | ||
) : null} | ||
|
||
{lessonsQuery.query.isFetching && !lessonsQuery.query.isLoading ? ( | ||
<Loading /> | ||
) : null} | ||
|
||
{tutor ? ( | ||
<BookLesson | ||
close={closeRebookingDialog} | ||
open={!!tutor} | ||
tutorId={tutor} | ||
/> | ||
) : null} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useFormatMessage } from "@litespace/luna/hooks/intl"; | ||
import { StudentOverview as Overview } from "@litespace/luna/StudentOverview"; | ||
import { Typography } from "@litespace/luna/Typography"; | ||
import { useFindPublicStudentStats } from "@litespace/headless/student"; | ||
|
||
export const StudentOverview = () => { | ||
const intl = useFormatMessage(); | ||
|
||
const statsQuery = useFindPublicStudentStats(); | ||
|
||
return ( | ||
<div className="grid gap-6 justify-items-start w-full"> | ||
<Typography | ||
element="subtitle-2" | ||
weight="bold" | ||
className="text-natural-950" | ||
> | ||
{intl("student-dashboard.overview.title")} | ||
</Typography> | ||
|
||
<Overview | ||
tutorCount={statsQuery.data?.tutorCount || 0} | ||
completedLessonCount={statsQuery.data?.completedLessonCount || 0} | ||
totalLearningTime={statsQuery.data?.totalLearningTime || 0} | ||
totalLessonCount={statsQuery.data?.completedLessonCount || 0} | ||
loading={statsQuery.isPending} | ||
error={statsQuery.isError} | ||
retry={statsQuery.refetch} | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Route } from "@/types/routes"; | ||
import { useUser } from "@litespace/headless/context/user"; | ||
import { useInfiniteLessons } from "@litespace/headless/lessons"; | ||
import { UpcomingLessonsSummary as Summary } from "@litespace/luna/Lessons"; | ||
import { ILesson, IUser } from "@litespace/types"; | ||
import dayjs from "dayjs"; | ||
import { useMemo } from "react"; | ||
|
||
function asUpcomingLessons( | ||
list: ILesson.FindUserLessonsApiResponse["list"] | null | ||
) { | ||
if (!list) return []; | ||
|
||
return list.map((item) => ({ | ||
start: item.lesson.start, | ||
tutorName: | ||
item.members.find((member) => member.role === IUser.Role.Tutor)?.name || | ||
null, | ||
url: Route.Call, | ||
})); | ||
} | ||
|
||
export const UpcomingLessons = () => { | ||
const { user } = useUser(); | ||
|
||
const now = useMemo(() => dayjs.utc().toISOString(), []); | ||
const lessonsQuery = useInfiniteLessons({ | ||
users: user ? [user?.id] : [], | ||
userOnly: true, | ||
after: now, | ||
size: 4, | ||
}); | ||
const lessons = useMemo( | ||
() => asUpcomingLessons(lessonsQuery.list), | ||
[lessonsQuery.list] | ||
); | ||
return ( | ||
<Summary | ||
loading={lessonsQuery.query.isPending} | ||
error={lessonsQuery.query.isError} | ||
retry={lessonsQuery.query.refetch} | ||
lessons={lessons} | ||
lessonsUrl={Route.UpcomingLessons} | ||
tutorsUrl={Route.Tutors} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
import React from "react"; | ||
import { ChatSummary } from "@/components/dashboard/ChatSummary"; | ||
import { UpcomingLessons } from "@/components/dashboard/UpcomingLessons"; | ||
import { PastLessons } from "@/components/dashboard/PastLessons"; | ||
import { StudentOverview } from "@/components/dashboard/StudentOverview"; | ||
|
||
const Dashboard: React.FC = () => { | ||
return <div>Dashboard</div>; | ||
return ( | ||
<div className="flex flex-row p-6 gap-6 max-w-screen-3xl mx-auto w-full"> | ||
<div className="flex flex-col gap-6 w-full"> | ||
<StudentOverview /> | ||
<PastLessons /> | ||
</div> | ||
<div className="flex flex-col gap-6 w-[312px] shrink-0"> | ||
<UpcomingLessons /> | ||
<ChatSummary /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Dashboard; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.