feat(dimentorin): articles page integrated with API (list, filter, detail)
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { api } from '../';
|
||||
import {
|
||||
TArticleDetail,
|
||||
TArticleListItem,
|
||||
TArticleListParams,
|
||||
TMentorAvailability,
|
||||
TMentorDetail,
|
||||
TMentorListParams,
|
||||
@@ -95,3 +98,38 @@ export const postSessionFeedback = async (
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getArticles = async (
|
||||
params?: TArticleListParams
|
||||
): Promise<TArticleListItem[]> => {
|
||||
const { data } = await api({
|
||||
method: 'GET',
|
||||
url: '/dimentorin/articles',
|
||||
params,
|
||||
});
|
||||
return data.data;
|
||||
};
|
||||
|
||||
export const getArticleCategories = async (): Promise<string[]> => {
|
||||
const { data } = await api({
|
||||
method: 'GET',
|
||||
url: '/dimentorin/articles/categories',
|
||||
});
|
||||
return data.data;
|
||||
};
|
||||
|
||||
export const getArticleBySlug = async (slug: string): Promise<TArticleDetail> => {
|
||||
const { data } = await api({
|
||||
method: 'GET',
|
||||
url: `/dimentorin/articles/slug/${slug}`,
|
||||
});
|
||||
return data.data;
|
||||
};
|
||||
|
||||
export const getArticleById = async (id: string): Promise<TArticleDetail> => {
|
||||
const { data } = await api({
|
||||
method: 'GET',
|
||||
url: `/dimentorin/articles/${id}`,
|
||||
});
|
||||
return data.data;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
|
||||
import {
|
||||
getArticleById,
|
||||
getArticleBySlug,
|
||||
getArticleCategories,
|
||||
getArticles,
|
||||
getMentorAvailability,
|
||||
getMentorDetail,
|
||||
getMentorMe,
|
||||
@@ -11,6 +15,9 @@ import {
|
||||
postSessionFeedback,
|
||||
} from '../../api/dimentorin';
|
||||
import {
|
||||
TArticleDetail,
|
||||
TArticleListItem,
|
||||
TArticleListParams,
|
||||
TBookSessionRequest,
|
||||
TMentorAvailability,
|
||||
TMentorDetail,
|
||||
@@ -105,4 +112,43 @@ export const usePostSessionFeedback = (sessionId: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
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 };
|
||||
|
||||
@@ -97,3 +97,26 @@ export type TSessionFeedbackRequest = {
|
||||
feedback: string;
|
||||
rating: number;
|
||||
};
|
||||
|
||||
export type TArticleListItem = {
|
||||
id: string;
|
||||
title: string;
|
||||
slug: string;
|
||||
category: string;
|
||||
excerpt: string;
|
||||
cover_url: string | null;
|
||||
author_name: string | null;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export type TArticleDetail = TArticleListItem & {
|
||||
content: string;
|
||||
is_published: boolean;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export type TArticleListParams = {
|
||||
page?: number;
|
||||
per_page?: number;
|
||||
category?: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user