feat(dimentorin): integrate mentors API - service layer + public list/detail pages
This commit is contained in:
@@ -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 };
|
||||
Reference in New Issue
Block a user