feat: update articles admin

This commit is contained in:
hanif salafi 2025-07-03 17:15:38 +07:00
parent 93b31c7d4e
commit 132485e5fc
4 changed files with 32 additions and 12 deletions

View File

@ -19,7 +19,7 @@ import Cookies from "js-cookie";
import {
deleteArticle,
getArticleByCategory,
getListArticle,
getArticlePagination,
updateIsBannerArticle,
} from "@/service/article";
import {
@ -91,9 +91,6 @@ export default function ArticleTable() {
useEffect(() => {
initState();
}, [page, showData, startDateValue, selectedCategories]);
useEffect(() => {
getCategories();
}, []);
@ -103,7 +100,7 @@ export default function ArticleTable() {
setCategories(data);
}
async function initState() {
const initState = useCallback(async () => {
loading();
const req = {
limit: showData,
@ -116,11 +113,11 @@ export default function ArticleTable() {
sort: "desc",
sortBy: "created_at",
};
const res = await getListArticle(req);
const res = await getArticlePagination(req);
await getTableNumber(parseInt(showData), res.data?.data);
setTotalPage(res?.data?.meta?.totalPage);
close();
}
}, [page]);
const getTableNumber = async (limit: number, data: Article[]) => {
if (data) {

View File

@ -1,7 +1,7 @@
import { PaginationRequest } from "@/types/globals";
import Cookies from "js-cookie";
import { httpGet } from "./http-config/http-base-services";
import { httpDeleteInterceptor, httpPostInterceptor, httpPutInterceptor } from "./http-config/http-interceptor-services";
import { httpDeleteInterceptor, httpGetInterceptor, httpPostInterceptor, httpPutInterceptor } from "./http-config/http-interceptor-services";
export async function getListArticle(props: PaginationRequest) {
const {
@ -29,6 +29,28 @@ export async function getListArticle(props: PaginationRequest) {
);
}
export async function getArticlePagination(props: PaginationRequest) {
const {
page,
limit,
search,
startDate,
endDate,
category,
sortBy,
sort,
categorySlug,
isBanner,
} = props;
return await httpGetInterceptor(
`/articles?limit=${limit}&page=${page}&title=${search}&startDate=${startDate || ""}&endDate=${
endDate || ""
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
sort || "asc"
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}`
);
}
export async function getTopArticles(props: PaginationRequest) {
const { page, limit, search, startDate, endDate, isPublish, category } =
props;
@ -75,7 +97,7 @@ export async function deleteArticle(id: string) {
}
export async function getArticleByCategory() {
return await httpGet(`/article-categories?limit=1000`);
return await httpGetInterceptor(`/article-categories?limit=1000`);
}
export async function getCategoryPagination(data: any) {
return await httpGet(

View File

@ -5,8 +5,8 @@ const defaultHeaders = {
"X-Client-Key": process.env.MEDOLS_CLIENT_KEY
};
export async function httpGet(pathUrl: any, headers?: any) {
export async function httpGet(pathUrl: any, headers?: any) {
console.log("X-HEADERS : ", defaultHeaders)
const mergedHeaders = {
...defaultHeaders,
...headers,

View File

@ -9,8 +9,9 @@ const defaultHeaders = {
};
export async function httpGetInterceptor(pathUrl: any) {
console.log("X-HEADERS : ", defaultHeaders)
const response = await axiosInterceptorInstance
.get(pathUrl)
.get(pathUrl, { headers: defaultHeaders })
.catch((error) => error.response);
console.log("Response interceptor : ", response);
if (response?.status == 200 || response?.status == 201) {