diff --git a/apps/dimentorin/src/app/(public)/mentoring/[id]/_components/sections/senpai-statistics.tsx b/apps/dimentorin/src/app/(public)/mentoring/[id]/_components/sections/senpai-statistics.tsx index db06cac..086843d 100644 --- a/apps/dimentorin/src/app/(public)/mentoring/[id]/_components/sections/senpai-statistics.tsx +++ b/apps/dimentorin/src/app/(public)/mentoring/[id]/_components/sections/senpai-statistics.tsx @@ -1,14 +1,23 @@ import { StarFilled } from "@ant-design/icons"; import { For } from "@imphnen-frontend-service/utils"; +import { useGetMentorStats } from "@imphnen-frontend-service/service"; import { FC } from "react"; -const SENPAI_STATISTIC = [ - { name: 'Total Sessions', count: 8 }, - { name: 'Mentee Impact', count: 1000 }, - { name: 'Response Time', count: '30 Minute' } -] +type Props = { + mentorId?: string; +}; + +const formatCount = (n: number) => (n >= 1000 ? `${(n / 1000).toFixed(n >= 100000 ? 0 : 1)}k` : `${n}`); + +export const StatisticsSection: FC = ({ mentorId }) => { + const { data: stats } = useGetMentorStats(mentorId ?? "") + + const SENPAI_STATISTIC: { name: string; count: string }[] = [ + { name: 'Total Sessions', count: formatCount(stats?.total_sessions ?? 0) }, + { name: 'Mentee Impact', count: formatCount(stats?.unique_mentees ?? 0) }, + { name: 'Avg Rating', count: stats && stats.avg_rating > 0 ? `${stats.avg_rating}/5` : '-' }, + ] -export const StatisticsSection: FC = () => { return (

Senpai Statistics

diff --git a/apps/dimentorin/src/app/(public)/mentoring/[id]/page.tsx b/apps/dimentorin/src/app/(public)/mentoring/[id]/page.tsx index bbb3e4d..ac6edfd 100644 --- a/apps/dimentorin/src/app/(public)/mentoring/[id]/page.tsx +++ b/apps/dimentorin/src/app/(public)/mentoring/[id]/page.tsx @@ -40,7 +40,7 @@ export const Components: FC = () => {
- +
diff --git a/libs/service/src/api/dimentorin/index.ts b/libs/service/src/api/dimentorin/index.ts index b3a12c3..a3ea0ee 100644 --- a/libs/service/src/api/dimentorin/index.ts +++ b/libs/service/src/api/dimentorin/index.ts @@ -7,6 +7,7 @@ import { TMentorDetail, TMentorListParams, TMentorRegisterRequest, + TMentorStats, TSessionFeedbackRequest, TSessionListResponse, TBookSessionRequest, @@ -135,6 +136,14 @@ export const getArticleById = async (id: string): Promise => { return data.data; }; +export const getMentorStats = async (mentorId: string): Promise => { + const { data } = await api({ + method: 'GET', + url: `/dimentorin/mentors/${mentorId}/stats`, + }); + return data.data; +}; + export const postRegisterMentor = async ( payload: TMentorRegisterRequest ): Promise => { diff --git a/libs/service/src/hooks/dimentorin/index.ts b/libs/service/src/hooks/dimentorin/index.ts index eabeeb7..58b5591 100644 --- a/libs/service/src/hooks/dimentorin/index.ts +++ b/libs/service/src/hooks/dimentorin/index.ts @@ -9,6 +9,7 @@ import { getMentorMe, getMentorMeStatus, getMentorSessions, + getMentorStats, getMentors, getMySessions, postBookSession, @@ -24,6 +25,7 @@ import { TMentorDetail, TMentorListParams, TMentorRegisterRequest, + TMentorStats, TSessionFeedbackRequest, TSessionListResponse, } from '../../types/dimentorin'; @@ -69,12 +71,22 @@ export const useGetMentorMeStatus = (): UseQueryResult< }; export const useGetMentorAvailability = ( - id: string + mentorId: string ): UseQueryResult => { return useQuery({ - queryKey: ['get-mentor-availability', id], - queryFn: async () => await getMentorAvailability(id), - enabled: !!id, + queryKey: ['get-mentor-availability', mentorId], + queryFn: async () => await getMentorAvailability(mentorId), + enabled: !!mentorId, + }); +}; + +export const useGetMentorStats = ( + mentorId: string +): UseQueryResult => { + return useQuery({ + queryKey: ['get-mentor-stats', mentorId], + queryFn: async () => await getMentorStats(mentorId), + enabled: !!mentorId, }); }; diff --git a/libs/service/src/types/dimentorin/index.ts b/libs/service/src/types/dimentorin/index.ts index 767c8da..0fa9ec3 100644 --- a/libs/service/src/types/dimentorin/index.ts +++ b/libs/service/src/types/dimentorin/index.ts @@ -98,6 +98,13 @@ export type TSessionFeedbackRequest = { rating: number; }; +export type TMentorStats = { + mentor_id: string; + total_sessions: number; + unique_mentees: number; + avg_rating: number; +}; + export type TArticleListItem = { id: string; title: string;