feat:activity log

This commit is contained in:
Rama Priyanto 2025-02-07 16:37:39 +07:00
parent 5bae5603b7
commit c3ea4dcd6d
12 changed files with 126 additions and 48 deletions

View File

@ -1,4 +1,4 @@
"use client" "use client";
import Login from "@/components/form/login"; import Login from "@/components/form/login";
import QudoLogin from "@/components/form/qudo-login"; import QudoLogin from "@/components/form/qudo-login";
@ -6,11 +6,10 @@ import Cookies from "js-cookie";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
export default function AuthPage() { export default function AuthPage() {
// const isAuthenticated = Cookies.get("is_authenticated") || "false";
const isAuthenticated = Cookies.get("is_authenticated") || "false"; // console.log("isAuthenticated : ", isAuthenticated);
console.log("isAuthenticated : ", isAuthenticated);
const [hasMounted, setHasMounted] = useState(false); const [hasMounted, setHasMounted] = useState(false);
useEffect(() => { useEffect(() => {
@ -21,8 +20,9 @@ export default function AuthPage() {
if (!hasMounted) return null; if (!hasMounted) return null;
return ( return (
isAuthenticated == "true" ? // isAuthenticated == "true" ?
<Login /> : <Login />
<QudoLogin /> // :
// <QudoLogin />
); );
} }

View File

@ -5,7 +5,7 @@ import { Button } from "@nextui-org/button";
import Link from "next/link"; import Link from "next/link";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import { close, error, loading } from "@/config/swal"; import { close, error, loading } from "@/config/swal";
import { getProfile, postSignIn, resetPassword } from "@/service/master-user"; import { postSignIn, resetPassword } from "@/service/master-user";
import { useRouter, useSearchParams } from "next/navigation"; import { useRouter, useSearchParams } from "next/navigation";
import Swal from "sweetalert2"; import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content"; import withReactContent from "sweetalert2-react-content";

View File

@ -10,6 +10,7 @@ import { checkUsernames, getProfile, postSignIn } from "@/service/master-user";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import Swal from "sweetalert2"; import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content"; import withReactContent from "sweetalert2-react-content";
import { saveActivity } from "@/service/activity-log";
export default function Login() { export default function Login() {
const router = useRouter(); const router = useRouter();
@ -53,6 +54,14 @@ export default function Login() {
sameSite: "strict", sameSite: "strict",
}); });
const profile = await getProfile(access_token); const profile = await getProfile(access_token);
const resActivity = await saveActivity(
{
activityTypeId: 1,
url: "https://kontenhumas.com/auth",
userId: profile?.data?.data?.id,
},
response?.data?.data?.id_token
);
console.log("PROFILE : ", profile?.data); console.log("PROFILE : ", profile?.data);
Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, {
expires: 1, expires: 1,
@ -85,8 +94,8 @@ export default function Login() {
expires: 1, expires: 1,
}); });
close();
router.push("/admin/dashboard"); router.push("/admin/dashboard");
close();
Cookies.set("status", "login", { Cookies.set("status", "login", {
expires: 1, expires: 1,
}); });

View File

@ -7,7 +7,7 @@ import { error, loading, close } from "@/config/swal";
import { Button, Input } from "@nextui-org/react"; import { Button, Input } from "@nextui-org/react";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { getProfile, postSignIn } from "@/service/master-user"; import { postSignIn } from "@/service/master-user";
const images = ["bg1.jpg", "bg2.jpg"]; const images = ["bg1.jpg", "bg2.jpg"];
@ -66,20 +66,6 @@ export default function QudoLogin() {
secure: true, secure: true,
sameSite: "strict", sameSite: "strict",
}); });
const profile = await getProfile();
console.log("PROFILE : ", profile?.data);
Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, {
expires: 1,
});
Cookies.set("uie", profile?.data?.data?.id, {
expires: 1,
});
Cookies.set("ufne", profile?.data?.data?.fullname, {
expires: 1,
});
Cookies.set("username", profile?.data?.data?.username, {
expires: 1,
});
close(); close();
router.push("/"); router.push("/");

File diff suppressed because one or more lines are too long

View File

@ -68,15 +68,15 @@ export default function NavbarHumas(props: { size: string }) {
const language = storedLanguage((state) => state.locale); const language = storedLanguage((state) => state.locale);
const setLanguage = storedLanguage((state) => state.setLocale); const setLanguage = storedLanguage((state) => state.setLocale);
useEffect(() => { // useEffect(() => {
if (!isAuthenticated) { // if (!isAuthenticated) {
onLogout(); // onLogout();
} // }
}, [token]); // }, [token]);
const onLogout = () => { const onLogout = () => {
Object.keys(Cookies.get()).forEach((cookieName) => { Object.keys(Cookies.get()).forEach((cookieName) => {
Cookies.remove(cookieName); Cookies.remove(cookieName, { path: "/" });
}); });
router.push("/auth"); router.push("/auth");
}; };

View File

@ -262,7 +262,7 @@ const Sidebar: React.FC<SidebarProps> = ({ updateSidebarData }) => {
const onLogout = () => { const onLogout = () => {
Object.keys(Cookies.get()).forEach((cookieName) => { Object.keys(Cookies.get()).forEach((cookieName) => {
Cookies.remove(cookieName); Cookies.remove(cookieName, { path: "/" });
}); });
router.push("/auth"); router.push("/auth");
}; };

View File

@ -20,8 +20,11 @@ import OTPInput from "react-otp-input";
import Swal from "sweetalert2"; import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content"; import withReactContent from "sweetalert2-react-content";
import { SendIcon, TimesIcon } from "@/components/icons"; import { SendIcon, TimesIcon } from "@/components/icons";
import { saveActivity } from "@/service/activity-log";
import { usePathname } from "next/navigation";
const userId = Cookies.get("uie"); const userId = Cookies.get("uie");
const token = Cookies.get("access_token");
const commentSchema = z.object({ const commentSchema = z.object({
name: z.string().min(1, { name: z.string().min(1, {
@ -43,7 +46,7 @@ const commentSchema = z.object({
export default function Comment(props: { id: string | null }) { export default function Comment(props: { id: string | null }) {
const { id } = props; const { id } = props;
const MySwal = withReactContent(Swal); const MySwal = withReactContent(Swal);
const pathname = usePathname();
const [needOtp, setNeedOtp] = useState(false); const [needOtp, setNeedOtp] = useState(false);
const [otpValue, setOtpValue] = useState(""); const [otpValue, setOtpValue] = useState("");
const [commentList, setCommentList] = useState<any>([]); const [commentList, setCommentList] = useState<any>([]);
@ -98,6 +101,13 @@ export default function Comment(props: { id: string | null }) {
error(res?.message); error(res?.message);
return false; return false;
} }
const req: any = {
activityTypeId: 5,
url: "https://kontenhumas.com/" + pathname,
articleId: Number(id),
};
const resActivity = await saveActivity(req);
reset(); reset();
fetchData(); fetchData();
setNeedOtp(false); setNeedOtp(false);
@ -151,8 +161,19 @@ export default function Comment(props: { id: string | null }) {
error(res?.message); error(res?.message);
return false; return false;
} }
const req: any = {
activityTypeId: 5,
url: "https://kontenhumas.com/" + pathname,
articleId: Number(id),
userId: Number(userId),
};
const resActivity = await saveActivity(req, token);
fetchData(); fetchData();
}; };
// const sendActivity = async () => {};
const editComment = async (idComment: number, parentId: number) => { const editComment = async (idComment: number, parentId: number) => {
const data = { const data = {
articleId: Number(id), articleId: Number(id),

View File

@ -5,20 +5,27 @@ import SidebarDetail from "../../page/sidebar-detail";
import RelatedNews from "../../page/related-news"; import RelatedNews from "../../page/related-news";
import Comment from "./comment"; import Comment from "./comment";
import { getArticleById, getListArticle } from "@/service/article"; import { getArticleById, getListArticle } from "@/service/article";
import { useParams } from "next/navigation"; import { useParams, usePathname } from "next/navigation";
import Link from "next/link"; import Link from "next/link";
import { ChevronRightIcon, UserIcon } from "@/components/icons"; import { ChevronRightIcon, UserIcon } from "@/components/icons";
import { close, loading } from "@/config/swal"; import { close, loading } from "@/config/swal";
import { saveActivity } from "@/service/activity-log";
import Cookies from "js-cookie";
const token = Cookies.get("access_token");
const uid = Cookies.get("uie");
export default function NewsDetailPage() { export default function NewsDetailPage() {
const params = useParams(); const params = useParams();
const id: any = params?.id; const id: any = params?.id;
const pathname = usePathname();
const [detailArticle, setDetailArticle] = useState(); const [detailArticle, setDetailArticle] = useState();
const [articles, setArticles] = useState<any>([]); const [articles, setArticles] = useState<any>([]);
useEffect(() => { useEffect(() => {
initFetch(); initFetch();
getArticles(); getArticles();
sendActivity();
}, []); }, []);
async function getArticles() { async function getArticles() {
@ -34,6 +41,19 @@ export default function NewsDetailPage() {
setDetailArticle(data); setDetailArticle(data);
close(); close();
}; };
const sendActivity = async () => {
let req: any = {
activityTypeId: 2,
url: "https://kontenhumas.com/" + pathname,
articleId: Number(id?.split("-")[0]),
};
if (uid) {
req.userId = Number(uid);
}
const resActivity = await saveActivity(req, token);
};
return ( return (
<div className="bg-white"> <div className="bg-white">
<div className="px-5 lg:px-0 lg:w-[75vw] lg:mx-auto py-8"> <div className="px-5 lg:px-0 lg:w-[75vw] lg:mx-auto py-8">

View File

@ -20,10 +20,15 @@ import {
UserIcon, UserIcon,
} from "../icons"; } from "../icons";
import { Button } from "@nextui-org/button"; import { Button } from "@nextui-org/button";
import { usePathname } from "next/navigation"; import { useParams, usePathname } from "next/navigation";
import Link from "next/link"; import Link from "next/link";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { image } from "@nextui-org/theme"; 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 }) { export default function DetailNews(props: { data: any; listArticle: any }) {
const { data, listArticle } = props; const { data, listArticle } = props;
@ -31,12 +36,25 @@ export default function DetailNews(props: { data: any; listArticle: any }) {
const [nextArticle, setNextArticle] = useState(""); const [nextArticle, setNextArticle] = useState("");
const [imageNow, setImageNow] = useState(0); const [imageNow, setImageNow] = useState(0);
const pathname = usePathname(); const pathname = usePathname();
const params = useParams();
const id: any = params?.id;
const shareText = "Humas Polri"; const shareText = "Humas Polri";
const handleShare = (platform: string) => { const handleShare = async (platform: string) => {
let shareLink = ""; let shareLink = "";
const urls = "https://kontenhumas.com/" + pathname; 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) { switch (platform) {
case "facebook": case "facebook":
shareLink = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent( shareLink = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(

20
service/activity-log.ts Normal file
View File

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

View File

@ -88,10 +88,14 @@ export async function otpValidation(email: string, otpCode: string) {
} }
export async function postArticleComment(data: any) { export async function postArticleComment(data: any) {
const headers = { const headers = token
"content-type": "application/json", ? {
Authorization: `Bearer ${token}`, "content-type": "application/json",
}; Authorization: `Bearer ${token}`,
}
: {
"content-type": "application/json",
};
return await httpPost(`/article-comments`, headers, data); return await httpPost(`/article-comments`, headers, data);
} }