165 lines
4.0 KiB
TypeScript
165 lines
4.0 KiB
TypeScript
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
|
|
import {
|
|
getArticleById,
|
|
getArticleBySlug,
|
|
getArticleCategories,
|
|
getArticles,
|
|
getMentorAvailability,
|
|
getMentorDetail,
|
|
getMentorMe,
|
|
getMentorMeStatus,
|
|
getMentorSessions,
|
|
getMentors,
|
|
getMySessions,
|
|
postBookSession,
|
|
postRegisterMentor,
|
|
postSessionFeedback,
|
|
} from '../../api/dimentorin';
|
|
import {
|
|
TArticleDetail,
|
|
TArticleListItem,
|
|
TArticleListParams,
|
|
TBookSessionRequest,
|
|
TMentorAvailability,
|
|
TMentorDetail,
|
|
TMentorListParams,
|
|
TMentorRegisterRequest,
|
|
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 const usePostRegisterMentor = () => {
|
|
return useMutation({
|
|
mutationKey: ['post-register-mentor'],
|
|
mutationFn: async (payload: TMentorRegisterRequest) =>
|
|
await postRegisterMentor(payload),
|
|
});
|
|
};
|
|
|
|
export const useGetArticles = (
|
|
params?: TArticleListParams
|
|
): UseQueryResult<TArticleListItem[], TResponseError> => {
|
|
return useQuery({
|
|
queryKey: ['get-articles', params],
|
|
queryFn: async () => await getArticles(params),
|
|
});
|
|
};
|
|
|
|
export const useGetArticleCategories = (): UseQueryResult<
|
|
string[],
|
|
TResponseError
|
|
> => {
|
|
return useQuery({
|
|
queryKey: ['get-article-categories'],
|
|
queryFn: async () => await getArticleCategories(),
|
|
});
|
|
};
|
|
|
|
export const useGetArticleBySlug = (
|
|
slug: string
|
|
): UseQueryResult<TArticleDetail, TResponseError> => {
|
|
return useQuery({
|
|
queryKey: ['get-article-by-slug', slug],
|
|
queryFn: async () => await getArticleBySlug(slug),
|
|
enabled: !!slug,
|
|
});
|
|
};
|
|
|
|
export const useGetArticleById = (
|
|
id: string
|
|
): UseQueryResult<TArticleDetail, TResponseError> => {
|
|
return useQuery({
|
|
queryKey: ['get-article-by-id', id],
|
|
queryFn: async () => await getArticleById(id),
|
|
enabled: !!id,
|
|
});
|
|
};
|
|
|
|
export type { TResponseMessage };
|