feat: update articles admin
This commit is contained in:
parent
93b31c7d4e
commit
132485e5fc
|
|
@ -19,7 +19,7 @@ import Cookies from "js-cookie";
|
||||||
import {
|
import {
|
||||||
deleteArticle,
|
deleteArticle,
|
||||||
getArticleByCategory,
|
getArticleByCategory,
|
||||||
getListArticle,
|
getArticlePagination,
|
||||||
updateIsBannerArticle,
|
updateIsBannerArticle,
|
||||||
} from "@/service/article";
|
} from "@/service/article";
|
||||||
import {
|
import {
|
||||||
|
|
@ -91,9 +91,6 @@ export default function ArticleTable() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initState();
|
initState();
|
||||||
}, [page, showData, startDateValue, selectedCategories]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getCategories();
|
getCategories();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
@ -103,7 +100,7 @@ export default function ArticleTable() {
|
||||||
setCategories(data);
|
setCategories(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initState() {
|
const initState = useCallback(async () => {
|
||||||
loading();
|
loading();
|
||||||
const req = {
|
const req = {
|
||||||
limit: showData,
|
limit: showData,
|
||||||
|
|
@ -116,11 +113,11 @@ export default function ArticleTable() {
|
||||||
sort: "desc",
|
sort: "desc",
|
||||||
sortBy: "created_at",
|
sortBy: "created_at",
|
||||||
};
|
};
|
||||||
const res = await getListArticle(req);
|
const res = await getArticlePagination(req);
|
||||||
await getTableNumber(parseInt(showData), res.data?.data);
|
await getTableNumber(parseInt(showData), res.data?.data);
|
||||||
setTotalPage(res?.data?.meta?.totalPage);
|
setTotalPage(res?.data?.meta?.totalPage);
|
||||||
close();
|
close();
|
||||||
}
|
}, [page]);
|
||||||
|
|
||||||
const getTableNumber = async (limit: number, data: Article[]) => {
|
const getTableNumber = async (limit: number, data: Article[]) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { PaginationRequest } from "@/types/globals";
|
import { PaginationRequest } from "@/types/globals";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { httpGet } from "./http-config/http-base-services";
|
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) {
|
export async function getListArticle(props: PaginationRequest) {
|
||||||
const {
|
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) {
|
export async function getTopArticles(props: PaginationRequest) {
|
||||||
const { page, limit, search, startDate, endDate, isPublish, category } =
|
const { page, limit, search, startDate, endDate, isPublish, category } =
|
||||||
props;
|
props;
|
||||||
|
|
@ -75,7 +97,7 @@ export async function deleteArticle(id: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getArticleByCategory() {
|
export async function getArticleByCategory() {
|
||||||
return await httpGet(`/article-categories?limit=1000`);
|
return await httpGetInterceptor(`/article-categories?limit=1000`);
|
||||||
}
|
}
|
||||||
export async function getCategoryPagination(data: any) {
|
export async function getCategoryPagination(data: any) {
|
||||||
return await httpGet(
|
return await httpGet(
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ const defaultHeaders = {
|
||||||
"X-Client-Key": process.env.MEDOLS_CLIENT_KEY
|
"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 = {
|
const mergedHeaders = {
|
||||||
...defaultHeaders,
|
...defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@ const defaultHeaders = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function httpGetInterceptor(pathUrl: any) {
|
export async function httpGetInterceptor(pathUrl: any) {
|
||||||
|
console.log("X-HEADERS : ", defaultHeaders)
|
||||||
const response = await axiosInterceptorInstance
|
const response = await axiosInterceptorInstance
|
||||||
.get(pathUrl)
|
.get(pathUrl, { headers: defaultHeaders })
|
||||||
.catch((error) => error.response);
|
.catch((error) => error.response);
|
||||||
console.log("Response interceptor : ", response);
|
console.log("Response interceptor : ", response);
|
||||||
if (response?.status == 200 || response?.status == 201) {
|
if (response?.status == 200 || response?.status == 201) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue