feat(dimentorin): integrate mentors API - service layer + public list/detail pages

This commit is contained in:
asepharyana
2026-08-04 17:55:59 +07:00
parent 77eb755783
commit 7df4592a47
12 changed files with 542 additions and 651 deletions
+97
View File
@@ -0,0 +1,97 @@
import { api } from '../';
import {
TMentorAvailability,
TMentorDetail,
TMentorListParams,
TSessionFeedbackRequest,
TSessionListResponse,
TBookSessionRequest,
} from '../../types/dimentorin';
import { TResponseMessage } from '../../types/common';
export const getMentors = async (
params?: TMentorListParams
): Promise<TMentorDetail[]> => {
const { data } = await api({
method: 'GET',
url: '/dimentorin/mentors/public',
params,
});
return data;
};
export const getMentorDetail = async (id: string): Promise<TMentorDetail> => {
const { data } = await api({
method: 'GET',
url: `/dimentorin/mentors/public/${id}`,
});
return data;
};
export const getMentorMe = async (): Promise<TMentorDetail> => {
const { data } = await api({
method: 'GET',
url: '/dimentorin/mentors/me',
});
return data;
};
export const getMentorMeStatus = async (): Promise<{ status: string }> => {
const { data } = await api({
method: 'GET',
url: '/dimentorin/mentors/me/status',
});
return data;
};
export const getMentorAvailability = async (
id: string
): Promise<TMentorAvailability> => {
const { data } = await api({
method: 'GET',
url: `/dimentorin/mentors/${id}/availability`,
});
return data;
};
export const getMentorSessions = async (
id: string
): Promise<TSessionListResponse> => {
const { data } = await api({
method: 'GET',
url: `/dimentorin/mentors/${id}/sessions`,
});
return data;
};
export const getMySessions = async (): Promise<TSessionListResponse> => {
const { data } = await api({
method: 'GET',
url: '/dimentorin/sessions/me',
});
return data;
};
export const postBookSession = async (
mentorId: string,
payload: TBookSessionRequest
): Promise<TResponseMessage> => {
const { data } = await api({
method: 'POST',
url: `/dimentorin/mentors/${mentorId}/sessions/create`,
data: payload,
});
return data;
};
export const postSessionFeedback = async (
sessionId: string,
payload: TSessionFeedbackRequest
): Promise<TResponseMessage> => {
const { data } = await api({
method: 'POST',
url: `/dimentorin/sessions/${sessionId}/feedback/create`,
data: payload,
});
return data;
};
+24 -1
View File
@@ -1,6 +1,8 @@
import axios, { AxiosRequestConfig } from 'axios';
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
import Cookies from 'js-cookie';
export * from './auth';
export * from './dimentorin';
export * from './gacha';
export * from './users';
@@ -9,3 +11,24 @@ const config: AxiosRequestConfig = {
};
export const api = axios.create(config);
api.interceptors.request.use((config) => {
const raw = Cookies.get('token');
if (raw) {
try {
const parsed = JSON.parse(raw);
const token = parsed?.token?.access_token;
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
} catch {
// ignore malformed token
}
}
return config;
});
api.interceptors.response.use(
(response) => response,
(error: AxiosError) => Promise.reject(error)
);
+108
View File
@@ -0,0 +1,108 @@
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
import {
getMentorAvailability,
getMentorDetail,
getMentorMe,
getMentorMeStatus,
getMentorSessions,
getMentors,
getMySessions,
postBookSession,
postSessionFeedback,
} from '../../api/dimentorin';
import {
TBookSessionRequest,
TMentorAvailability,
TMentorDetail,
TMentorListParams,
TSessionFeedbackRequest,
TSessionListResponse,
} from '../../types/dimentorin';
import { TResponseError, TResponseMessage } from '../../types/common';
export const useGetMentors = (
params?: TMentorListParams
): UseQueryResult<TMentorDetail[], TResponseError> => {
return useQuery({
queryKey: ['get-mentors', params],
queryFn: async () => await getMentors(params),
});
};
export const useGetMentorDetail = (
id: string
): UseQueryResult<TMentorDetail, TResponseError> => {
return useQuery({
queryKey: ['get-mentor-detail', id],
queryFn: async () => await getMentorDetail(id),
enabled: !!id,
});
};
export const useGetMentorMe = (): UseQueryResult<
TMentorDetail,
TResponseError
> => {
return useQuery({
queryKey: ['get-mentor-me'],
queryFn: async () => await getMentorMe(),
});
};
export const useGetMentorMeStatus = (): UseQueryResult<
{ status: string },
TResponseError
> => {
return useQuery({
queryKey: ['get-mentor-me-status'],
queryFn: async () => await getMentorMeStatus(),
});
};
export const useGetMentorAvailability = (
id: string
): UseQueryResult<TMentorAvailability, TResponseError> => {
return useQuery({
queryKey: ['get-mentor-availability', id],
queryFn: async () => await getMentorAvailability(id),
enabled: !!id,
});
};
export const useGetMentorSessions = (
id: string
): UseQueryResult<TSessionListResponse, TResponseError> => {
return useQuery({
queryKey: ['get-mentor-sessions', id],
queryFn: async () => await getMentorSessions(id),
enabled: !!id,
});
};
export const useGetMySessions = (): UseQueryResult<
TSessionListResponse,
TResponseError
> => {
return useQuery({
queryKey: ['get-my-sessions'],
queryFn: async () => await getMySessions(),
});
};
export const usePostBookSession = (mentorId: string) => {
return useMutation({
mutationKey: ['post-book-session', mentorId],
mutationFn: async (payload: TBookSessionRequest) =>
await postBookSession(mentorId, payload),
});
};
export const usePostSessionFeedback = (sessionId: string) => {
return useMutation({
mutationKey: ['post-session-feedback', sessionId],
mutationFn: async (payload: TSessionFeedbackRequest) =>
await postSessionFeedback(sessionId, payload),
});
};
export type { TResponseMessage };
+1
View File
@@ -1,3 +1,4 @@
export * from './auth';
export * from './dimentorin';
export * from './gacha';
export * from './users';
@@ -0,0 +1,99 @@
import { TResponseList } from '../common';
export type TMentorListItem = {
id: string;
user_id: string;
fullname: string | null;
email: string | null;
status: string;
created_at: string;
updated_at: string;
};
export type TMentorDetail = {
id: string;
user_id: string;
fullname: string | null;
email: string | null;
legal_name: string | null;
gender: string | null;
domicile: string | null;
bio: string | null;
last_education: string | null;
linkedin_url: string | null;
github_url: string | null;
cv_url: string | null;
portfolio_url: string | null;
phone_for_verification: string | null;
industries: string[];
expertise: string[];
languages: string[];
current_company: string;
current_role: string;
years_of_experience: number;
topics_of_interest: string[];
preferred_mentee_level: string[];
preferred_mentoring_formats: string[];
availability_commitment: string;
mentoring_rate: number;
status: string;
created_at: string;
updated_at: string;
};
export type TMentorListParams = {
page?: number;
per_page?: number;
search?: string;
sort_by?: string;
order?: string;
};
export type TMentorListResponse = TMentorListItem[] | TResponseList<TMentorListItem>;
export type TAvailabilitySlot = {
date: string;
time: string;
available: boolean;
};
export type TMentorAvailability = {
mentor_id: string;
availability_commitment: string;
preferred_formats: string[];
slots: TAvailabilitySlot[];
booked_dates: string[];
};
export type TSessionListItem = {
id: string;
mentor_id: string;
mentee_id: string;
topic: string;
scheduled_at: string;
duration_minutes: number;
session_type: string;
status: string;
rating: number | null;
created_at: string;
mentee_email: string | null;
mentee_fullname: string | null;
};
export type TSessionListResponse = {
sessions: TSessionListItem[];
total: number;
};
export type TBookSessionRequest = {
topic: string;
scheduled_at: string;
description?: string | null;
duration_minutes?: number | null;
session_type?: string | null;
};
export type TSessionFeedbackRequest = {
feedback: string;
rating: number;
};
+1
View File
@@ -1,4 +1,5 @@
export * from './auth';
export * from './dimentorin';
export * from './gacha';
export * from './users';
export * from './roles';