feat: humas service

This commit is contained in:
amd123 2024-04-04 17:30:07 +07:00
parent 2267ffcba9
commit 15e68f809d
5 changed files with 81 additions and 1 deletions

View File

@ -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,

View File

@ -157,7 +157,7 @@ export default function NavbarHumas() {
</DropdownMenu>
</Dropdown>
</div>
<div><Link href="/portal-ppid">Portal PPID</Link></div>
<div><Link href="http://103.82.242.92:5000/" target='_blank'>Portal PPID</Link></div>
<div>
<Dropdown className='dark:bg-[#1F1A17]'>
<NavbarItem>

8
service/article.ts Normal file
View File

@ -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);
}

View File

@ -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,
};
}
}

View File

@ -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;