- PaymentStep: selectable VA/QRIS method, rate from mentor.mentoring_rate (fallback 50000), onMethodChange - AppointmentModal: book session -> create payment -> route to VA/QRIS step with real payment data; then success - QrisPaymentStep/VAPaymentStep: show real total + external_ref (VA number/QR ref) + expiry - service lib: TPayment/TCreatePaymentRequest types + postCreatePayment/getMyPayments/getPaymentById/postConfirmPayment + hooks - build verified, payments flow bundled
218 lines
5.3 KiB
TypeScript
218 lines
5.3 KiB
TypeScript
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
|
|
import {
|
|
getArticleById,
|
|
getArticleBySlug,
|
|
getArticleCategories,
|
|
getArticles,
|
|
getMentorAvailability,
|
|
getMentorDetail,
|
|
getMentorMe,
|
|
getMentorMeStatus,
|
|
getMentorSessions,
|
|
getMentorStats,
|
|
getMentors,
|
|
getMyPayments,
|
|
getMySessions,
|
|
getPaymentById,
|
|
postBookSession,
|
|
postConfirmPayment,
|
|
postCreatePayment,
|
|
postRegisterMentor,
|
|
postSessionFeedback,
|
|
} from '../../api/dimentorin';
|
|
import {
|
|
TArticleDetail,
|
|
TArticleListItem,
|
|
TArticleListParams,
|
|
TBookSessionRequest,
|
|
TCreatePaymentRequest,
|
|
TMentorAvailability,
|
|
TMentorDetail,
|
|
TMentorListParams,
|
|
TMentorRegisterRequest,
|
|
TMentorStats,
|
|
TPayment,
|
|
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 = (
|
|
mentorId: string
|
|
): UseQueryResult<TMentorAvailability, TResponseError> => {
|
|
return useQuery({
|
|
queryKey: ['get-mentor-availability', mentorId],
|
|
queryFn: async () => await getMentorAvailability(mentorId),
|
|
enabled: !!mentorId,
|
|
});
|
|
};
|
|
|
|
export const useGetMentorStats = (
|
|
mentorId: string
|
|
): UseQueryResult<TMentorStats, TResponseError> => {
|
|
return useQuery({
|
|
queryKey: ['get-mentor-stats', mentorId],
|
|
queryFn: async () => await getMentorStats(mentorId),
|
|
enabled: !!mentorId,
|
|
});
|
|
};
|
|
|
|
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 usePostCreatePayment = (sessionId: string) => {
|
|
return useMutation({
|
|
mutationKey: ['post-create-payment', sessionId],
|
|
mutationFn: async (payload: TCreatePaymentRequest) =>
|
|
await postCreatePayment(sessionId, payload),
|
|
});
|
|
};
|
|
|
|
export const useGetMyPayments = (): UseQueryResult<
|
|
TPayment[],
|
|
TResponseError
|
|
> => {
|
|
return useQuery({
|
|
queryKey: ['get-my-payments'],
|
|
queryFn: async () => await getMyPayments(),
|
|
});
|
|
};
|
|
|
|
export const useGetPaymentById = (
|
|
id: string
|
|
): UseQueryResult<TPayment, TResponseError> => {
|
|
return useQuery({
|
|
queryKey: ['get-payment-by-id', id],
|
|
queryFn: async () => await getPaymentById(id),
|
|
enabled: !!id,
|
|
});
|
|
};
|
|
|
|
export const usePostConfirmPayment = () => {
|
|
return useMutation({
|
|
mutationKey: ['post-confirm-payment'],
|
|
mutationFn: async (id: string) => await postConfirmPayment(id),
|
|
});
|
|
};
|
|
|
|
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 };
|