diff --git a/components/Landing Page/HeaderNews.tsx b/components/Landing Page/HeaderNews.tsx index 4a38a67..896becc 100644 --- a/components/Landing Page/HeaderNews.tsx +++ b/components/Landing Page/HeaderNews.tsx @@ -8,8 +8,20 @@ import 'swiper/css/pagination'; import { Autoplay, Pagination, Navigation } from 'swiper/modules'; import Link from 'next/link'; import GPRKominfo from '../SocialMedia/GprKominfo'; +import { useEffect, useState } from 'react'; +import { getListArticle } from '@/service/article'; export default function HeaderNews() { + const [article, setArticle] = useState(); + + useEffect(() => { + async function getArticle() { + const response = await getListArticle(); + console.log("res", response?.data?.data); + } + getArticle(); + }, []); + const newsData = [ { id: 1, diff --git a/components/navbar/NavbarHumas.tsx b/components/navbar/NavbarHumas.tsx index 62e5368..c6e7fc3 100644 --- a/components/navbar/NavbarHumas.tsx +++ b/components/navbar/NavbarHumas.tsx @@ -157,7 +157,7 @@ export default function NavbarHumas() { -
Portal PPID
+
Portal PPID
diff --git a/service/article.ts b/service/article.ts new file mode 100644 index 0000000..5a2f632 --- /dev/null +++ b/service/article.ts @@ -0,0 +1,8 @@ +import { httpGet } from "./http-config/axios-base-service"; + +export async function getListArticle() { + const headers = { + "content-type": "application/json", + }; + return await httpGet(`/articles`, headers); +} \ No newline at end of file diff --git a/service/http-config/axios-base-service.ts b/service/http-config/axios-base-service.ts new file mode 100644 index 0000000..b9e2163 --- /dev/null +++ b/service/http-config/axios-base-service.ts @@ -0,0 +1,48 @@ +import axiosBaseInstance from "./http-base-service"; + +export async function httpPost(pathUrl: any, headers: any, data?: any) { + const response = await axiosBaseInstance + .post(pathUrl, data, { headers }) + .catch(function (error) { + console.log(error); + return error.response; + }); + console.log("Response base svc : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} + +export async function httpGet(pathUrl: any, headers: any) { + const response = await axiosBaseInstance + .get(pathUrl, { headers }) + .catch(function (error) { + console.log(error); + return error.response; + }); + console.log("Response base svc : ", response); + if (response?.status == 200 || response?.status == 201) { + return { + error: false, + message: "success", + data: response?.data, + }; + } else { + return { + error: true, + message: response?.data?.message || response?.data || null, + data: null, + }; + } +} + diff --git a/service/http-config/http-base-service.ts b/service/http-config/http-base-service.ts new file mode 100644 index 0000000..d195a7f --- /dev/null +++ b/service/http-config/http-base-service.ts @@ -0,0 +1,12 @@ +import axios from "axios"; + +const baseURL = "http://103.82.242.92:8888"; + +const axiosBaseInstance = axios.create({ + baseURL, + headers: { + "content-type": "application/json", + }, +}); + +export default axiosBaseInstance;