diff --git a/components/page/detail-news.tsx b/components/page/detail-news.tsx
index a4ba980..ee83b17 100644
--- a/components/page/detail-news.tsx
+++ b/components/page/detail-news.tsx
@@ -20,10 +20,15 @@ import {
UserIcon,
} from "../icons";
import { Button } from "@nextui-org/button";
-import { usePathname } from "next/navigation";
+import { useParams, usePathname } from "next/navigation";
import Link from "next/link";
import { useEffect, useState } from "react";
import { image } from "@nextui-org/theme";
+import Cookies from "js-cookie";
+import { saveActivity } from "@/service/activity-log";
+
+const token = Cookies.get("access_token");
+const uid = Cookies.get("uie");
export default function DetailNews(props: { data: any; listArticle: any }) {
const { data, listArticle } = props;
@@ -31,12 +36,25 @@ export default function DetailNews(props: { data: any; listArticle: any }) {
const [nextArticle, setNextArticle] = useState("");
const [imageNow, setImageNow] = useState(0);
const pathname = usePathname();
+ const params = useParams();
+ const id: any = params?.id;
const shareText = "Humas Polri";
- const handleShare = (platform: string) => {
+ const handleShare = async (platform: string) => {
let shareLink = "";
const urls = "https://kontenhumas.com/" + pathname;
+ let req: any = {
+ activityTypeId: 3,
+ url: "https://kontenhumas.com/" + pathname,
+ articleId: Number(id?.split("-")[0]),
+ };
+ if (uid) {
+ req.userId = Number(uid);
+ }
+
+ const resActivity = await saveActivity(req, token);
+
switch (platform) {
case "facebook":
shareLink = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(
diff --git a/service/activity-log.ts b/service/activity-log.ts
new file mode 100644
index 0000000..287d862
--- /dev/null
+++ b/service/activity-log.ts
@@ -0,0 +1,20 @@
+import { PaginationRequest } from "@/types/globals";
+import {
+ httpDeleteInterceptor,
+ httpGet,
+ httpPost,
+ httpPut,
+} from "./http-config/axios-base-service";
+
+export async function saveActivity(data: any, token?: string) {
+ const headers = token
+ ? {
+ "content-type": "application/json",
+ Authorization: `Bearer ${token}`,
+ }
+ : {
+ "content-type": "application/json",
+ };
+ const pathUrl = `/activity-logs`;
+ return await httpPost(pathUrl, headers, data);
+}
diff --git a/service/master-user.ts b/service/master-user.ts
index aa38710..9ef15ca 100644
--- a/service/master-user.ts
+++ b/service/master-user.ts
@@ -88,10 +88,14 @@ export async function otpValidation(email: string, otpCode: string) {
}
export async function postArticleComment(data: any) {
- const headers = {
- "content-type": "application/json",
- Authorization: `Bearer ${token}`,
- };
+ const headers = token
+ ? {
+ "content-type": "application/json",
+ Authorization: `Bearer ${token}`,
+ }
+ : {
+ "content-type": "application/json",
+ };
return await httpPost(`/article-comments`, headers, data);
}