feat(dimentorin): senpai statistics from API (total sessions, mentee impact, avg rating)
This commit is contained in:
+15
-6
@@ -1,14 +1,23 @@
|
|||||||
import { StarFilled } from "@ant-design/icons";
|
import { StarFilled } from "@ant-design/icons";
|
||||||
import { For } from "@imphnen-frontend-service/utils";
|
import { For } from "@imphnen-frontend-service/utils";
|
||||||
|
import { useGetMentorStats } from "@imphnen-frontend-service/service";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
|
|
||||||
const SENPAI_STATISTIC = [
|
type Props = {
|
||||||
{ name: 'Total Sessions', count: 8 },
|
mentorId?: string;
|
||||||
{ name: 'Mentee Impact', count: 1000 },
|
};
|
||||||
{ name: 'Response Time', count: '30 Minute' }
|
|
||||||
]
|
const formatCount = (n: number) => (n >= 1000 ? `${(n / 1000).toFixed(n >= 100000 ? 0 : 1)}k` : `${n}`);
|
||||||
|
|
||||||
|
export const StatisticsSection: FC<Props> = ({ 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 (
|
return (
|
||||||
<div className="md:mb-10">
|
<div className="md:mb-10">
|
||||||
<h2 className="text-xs font-semibold mb-3 md:text-[15px] xl:text-[19px]">Senpai Statistics</h2>
|
<h2 className="text-xs font-semibold mb-3 md:text-[15px] xl:text-[19px]">Senpai Statistics</h2>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export const Components: FC = () => {
|
|||||||
|
|
||||||
<div className="bg-white px-4 py-5 md:px-8 md:pb-6 md:pt-0 xl:py-7 xl:flex xl:gap-x-10">
|
<div className="bg-white px-4 py-5 md:px-8 md:pb-6 md:pt-0 xl:py-7 xl:flex xl:gap-x-10">
|
||||||
<div className="space-y-10 md:space-y-7 xl:flex-1">
|
<div className="space-y-10 md:space-y-7 xl:flex-1">
|
||||||
<StatisticsSection />
|
<StatisticsSection mentorId={mentor?.id} />
|
||||||
<TopicsSection />
|
<TopicsSection />
|
||||||
|
|
||||||
<div className="px-6 py-8 rounded-md shadow-md">
|
<div className="px-6 py-8 rounded-md shadow-md">
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
TMentorDetail,
|
TMentorDetail,
|
||||||
TMentorListParams,
|
TMentorListParams,
|
||||||
TMentorRegisterRequest,
|
TMentorRegisterRequest,
|
||||||
|
TMentorStats,
|
||||||
TSessionFeedbackRequest,
|
TSessionFeedbackRequest,
|
||||||
TSessionListResponse,
|
TSessionListResponse,
|
||||||
TBookSessionRequest,
|
TBookSessionRequest,
|
||||||
@@ -135,6 +136,14 @@ export const getArticleById = async (id: string): Promise<TArticleDetail> => {
|
|||||||
return data.data;
|
return data.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getMentorStats = async (mentorId: string): Promise<TMentorStats> => {
|
||||||
|
const { data } = await api({
|
||||||
|
method: 'GET',
|
||||||
|
url: `/dimentorin/mentors/${mentorId}/stats`,
|
||||||
|
});
|
||||||
|
return data.data;
|
||||||
|
};
|
||||||
|
|
||||||
export const postRegisterMentor = async (
|
export const postRegisterMentor = async (
|
||||||
payload: TMentorRegisterRequest
|
payload: TMentorRegisterRequest
|
||||||
): Promise<TResponseMessage> => {
|
): Promise<TResponseMessage> => {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
getMentorMe,
|
getMentorMe,
|
||||||
getMentorMeStatus,
|
getMentorMeStatus,
|
||||||
getMentorSessions,
|
getMentorSessions,
|
||||||
|
getMentorStats,
|
||||||
getMentors,
|
getMentors,
|
||||||
getMySessions,
|
getMySessions,
|
||||||
postBookSession,
|
postBookSession,
|
||||||
@@ -24,6 +25,7 @@ import {
|
|||||||
TMentorDetail,
|
TMentorDetail,
|
||||||
TMentorListParams,
|
TMentorListParams,
|
||||||
TMentorRegisterRequest,
|
TMentorRegisterRequest,
|
||||||
|
TMentorStats,
|
||||||
TSessionFeedbackRequest,
|
TSessionFeedbackRequest,
|
||||||
TSessionListResponse,
|
TSessionListResponse,
|
||||||
} from '../../types/dimentorin';
|
} from '../../types/dimentorin';
|
||||||
@@ -69,12 +71,22 @@ export const useGetMentorMeStatus = (): UseQueryResult<
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useGetMentorAvailability = (
|
export const useGetMentorAvailability = (
|
||||||
id: string
|
mentorId: string
|
||||||
): UseQueryResult<TMentorAvailability, TResponseError> => {
|
): UseQueryResult<TMentorAvailability, TResponseError> => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['get-mentor-availability', id],
|
queryKey: ['get-mentor-availability', mentorId],
|
||||||
queryFn: async () => await getMentorAvailability(id),
|
queryFn: async () => await getMentorAvailability(mentorId),
|
||||||
enabled: !!id,
|
enabled: !!mentorId,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetMentorStats = (
|
||||||
|
mentorId: string
|
||||||
|
): UseQueryResult<TMentorStats, TResponseError> => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ['get-mentor-stats', mentorId],
|
||||||
|
queryFn: async () => await getMentorStats(mentorId),
|
||||||
|
enabled: !!mentorId,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,13 @@ export type TSessionFeedbackRequest = {
|
|||||||
rating: number;
|
rating: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TMentorStats = {
|
||||||
|
mentor_id: string;
|
||||||
|
total_sessions: number;
|
||||||
|
unique_mentees: number;
|
||||||
|
avg_rating: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type TArticleListItem = {
|
export type TArticleListItem = {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user