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 QudoLogin from "@/components/form/qudo-login";
@ -6,10 +6,9 @@ import Cookies from "js-cookie";
import React, { useEffect, useState } from "react";
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);
@ -21,8 +20,9 @@ export default function AuthPage() {
if (!hasMounted) return null;
return (
isAuthenticated == "true" ?
<Login /> :
<QudoLogin />
// isAuthenticated == "true" ?
<Login />
// :
// <QudoLogin />
);
}

View File

@ -5,7 +5,7 @@ import { Button } from "@nextui-org/button";
import Link from "next/link";
import Cookies from "js-cookie";
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 Swal from "sweetalert2";
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 Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";
import { saveActivity } from "@/service/activity-log";
export default function Login() {
const router = useRouter();
@ -53,6 +54,14 @@ export default function Login() {
sameSite: "strict",
});
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);
Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, {
expires: 1,
@ -85,8 +94,8 @@ export default function Login() {
expires: 1,
});
close();
router.push("/admin/dashboard");
close();
Cookies.set("status", "login", {
expires: 1,
});

View File

@ -7,7 +7,7 @@ import { error, loading, close } from "@/config/swal";
import { Button, Input } from "@nextui-org/react";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { getProfile, postSignIn } from "@/service/master-user";
import { postSignIn } from "@/service/master-user";
const images = ["bg1.jpg", "bg2.jpg"];
@ -66,20 +66,6 @@ export default function QudoLogin() {
secure: true,
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();
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 setLanguage = storedLanguage((state) => state.setLocale);
useEffect(() => {
if (!isAuthenticated) {
onLogout();
}
}, [token]);
// useEffect(() => {
// if (!isAuthenticated) {
// onLogout();
// }
// }, [token]);
const onLogout = () => {
Object.keys(Cookies.get()).forEach((cookieName) => {
Cookies.remove(cookieName);
Cookies.remove(cookieName, { path: "/" });
});
router.push("/auth");
};

View File

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

View File

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

View File

@ -5,20 +5,27 @@ import SidebarDetail from "../../page/sidebar-detail";
import RelatedNews from "../../page/related-news";
import Comment from "./comment";
import { getArticleById, getListArticle } from "@/service/article";
import { useParams } from "next/navigation";
import { useParams, usePathname } from "next/navigation";
import Link from "next/link";
import { ChevronRightIcon, UserIcon } from "@/components/icons";
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() {
const params = useParams();
const id: any = params?.id;
const pathname = usePathname();
const [detailArticle, setDetailArticle] = useState();
const [articles, setArticles] = useState<any>([]);
useEffect(() => {
initFetch();
getArticles();
sendActivity();
}, []);
async function getArticles() {
@ -34,6 +41,19 @@ export default function NewsDetailPage() {
setDetailArticle(data);
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 (
<div className="bg-white">
<div className="px-5 lg:px-0 lg:w-[75vw] lg:mx-auto py-8">

View File

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

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