2025-01-04 03:44:57 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import HeaderManagement from "@/components/landing-page/header-management";
|
|
|
|
|
import SidebarManagement from "@/components/landing-page/sidebar-management";
|
|
|
|
|
import { close, error, loading, successCallback } from "@/config/swal";
|
|
|
|
|
import { getCookiesDecrypt } from "@/lib/utils";
|
2025-06-03 00:59:48 +00:00
|
|
|
import {
|
|
|
|
|
checkWishlistStatus,
|
|
|
|
|
deleteWishlist,
|
|
|
|
|
getContentRewritePagination,
|
|
|
|
|
getInfoProfile,
|
|
|
|
|
saveWishlist,
|
|
|
|
|
} from "@/service/landing/landing";
|
2025-01-04 03:44:57 +00:00
|
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
|
import Swal from "sweetalert2";
|
|
|
|
|
import withReactContent from "sweetalert2-react-content";
|
|
|
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
|
|
|
import { Link } from "@/i18n/routing";
|
2025-06-03 00:59:48 +00:00
|
|
|
import {
|
|
|
|
|
Popover,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
PopoverTrigger,
|
|
|
|
|
} from "@/components/ui/popover";
|
2025-01-10 15:14:49 +00:00
|
|
|
import { Icon } from "@iconify/react/dist/iconify.js";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { sendMediaUploadToEmail } from "@/service/media-tracking/media-tracking";
|
2025-01-13 05:29:14 +00:00
|
|
|
import ImageBlurry from "@/components/ui/image-blurry";
|
2025-02-06 10:34:22 +00:00
|
|
|
import Image from "next/image";
|
2025-02-15 14:43:19 +00:00
|
|
|
import { useTranslations } from "next-intl";
|
2025-11-17 17:31:00 +00:00
|
|
|
import { sendMediaRewriteToEmail } from "@/service/content/content";
|
2025-01-04 03:44:57 +00:00
|
|
|
|
2025-01-12 08:21:11 +00:00
|
|
|
const page = () => {
|
2025-01-04 03:44:57 +00:00
|
|
|
const [, setProfile] = useState();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const searchParams = useSearchParams();
|
|
|
|
|
const MySwal = withReactContent(Swal);
|
|
|
|
|
const page: any = searchParams?.get("page");
|
|
|
|
|
const title = searchParams?.get("title");
|
|
|
|
|
const category = searchParams?.get("category");
|
|
|
|
|
const pages = page ? page - 1 : 0;
|
|
|
|
|
const userId = getCookiesDecrypt("uie");
|
|
|
|
|
const userRoleId = getCookiesDecrypt("urie");
|
|
|
|
|
const [, setGetTotalPage] = useState();
|
|
|
|
|
const [totalContent, setTotalContent] = useState<any>();
|
|
|
|
|
const [contentImage, setContentImage] = useState([]);
|
|
|
|
|
const [categoryFilter] = useState([]);
|
|
|
|
|
const [formatFilter] = useState([]);
|
|
|
|
|
const [sortBy] = useState();
|
|
|
|
|
const [refresh, setRefresh] = useState(false);
|
|
|
|
|
const [, setCopySuccess] = useState("");
|
|
|
|
|
const [, setWishlistId] = useState();
|
2025-01-10 15:14:49 +00:00
|
|
|
const [emailShareList, setEmailShareList] = useState<any>();
|
|
|
|
|
const [emailShareInput, setEmailShareInput] = useState<any>();
|
|
|
|
|
const [emailMessageInput, setEmailMessageInput] = useState();
|
|
|
|
|
const id = searchParams?.get("id");
|
2025-02-15 14:43:19 +00:00
|
|
|
const t = useTranslations("LandingPage");
|
2025-01-04 03:44:57 +00:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
async function initState() {
|
|
|
|
|
loading();
|
|
|
|
|
const response = await getInfoProfile();
|
2025-01-10 03:30:32 +00:00
|
|
|
console.log(response?.data?.data);
|
2025-01-04 03:44:57 +00:00
|
|
|
setProfile(response?.data?.data);
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initState();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
getData();
|
|
|
|
|
}, [page, category, title, refresh]);
|
|
|
|
|
|
|
|
|
|
async function getData() {
|
2025-06-03 00:59:48 +00:00
|
|
|
const filter =
|
|
|
|
|
categoryFilter?.length > 0
|
|
|
|
|
? categoryFilter?.sort().join(",")
|
|
|
|
|
: category || "";
|
2025-01-04 03:44:57 +00:00
|
|
|
|
|
|
|
|
const name = title == undefined ? "" : title;
|
|
|
|
|
const format = formatFilter == undefined ? "" : formatFilter?.join(",");
|
|
|
|
|
|
|
|
|
|
const response = await getContentRewritePagination(pages);
|
|
|
|
|
|
2025-01-05 00:44:55 +00:00
|
|
|
setGetTotalPage(response?.data?.data?.totalPages);
|
|
|
|
|
setContentImage(response?.data?.data?.content);
|
2025-01-04 03:44:57 +00:00
|
|
|
// console.log("response", response);
|
2025-01-05 00:44:55 +00:00
|
|
|
setTotalContent(response?.data?.data?.totalElements);
|
|
|
|
|
console.log("KONTEN", response?.data?.data?.content);
|
2025-01-04 03:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
async function initState() {
|
|
|
|
|
getData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initState();
|
|
|
|
|
}, [page, refresh]);
|
|
|
|
|
|
|
|
|
|
function addDefaultSrc(ev: any) {
|
|
|
|
|
ev.target.src = "/assets/img/image404.png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function deleteProcess(id: any) {
|
|
|
|
|
loading();
|
|
|
|
|
const resDelete = await deleteWishlist(id);
|
|
|
|
|
|
2025-01-04 17:11:14 +00:00
|
|
|
if (resDelete?.error) {
|
2025-01-04 03:44:57 +00:00
|
|
|
error(resDelete.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setRefresh((prevRefresh) => !prevRefresh);
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDelete = (id: any) => {
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Hapus Data",
|
|
|
|
|
text: "",
|
|
|
|
|
icon: "warning",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
cancelButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonColor: "#d33",
|
|
|
|
|
confirmButtonText: "Hapus",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
deleteProcess(id);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const copyToClip = async (url: any) => {
|
2025-06-03 00:59:48 +00:00
|
|
|
await navigator.clipboard.writeText(
|
|
|
|
|
`https://mediahub.polri.go.id/image/detail/${url}`
|
|
|
|
|
);
|
2025-01-04 03:44:57 +00:00
|
|
|
setCopySuccess("Copied");
|
|
|
|
|
// toast.success("Link Berhasil Di Copy");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function checkWishlist(uploadId: any) {
|
|
|
|
|
if (userId) {
|
|
|
|
|
const res = await checkWishlistStatus(uploadId);
|
2025-01-04 17:11:14 +00:00
|
|
|
console.log(res?.data?.data);
|
|
|
|
|
// const isAlreadyOnWishlist = res?.data?.data == "-1" ? false : true;
|
2025-01-04 03:44:57 +00:00
|
|
|
// if (isAlreadyOnWishlist == true) {
|
|
|
|
|
// warning("Konten sudah Ada", `#`);
|
|
|
|
|
// }
|
2025-01-04 17:11:14 +00:00
|
|
|
setWishlistId(res?.data?.data); // setIsSaved(isAlreadyOnWishlist);
|
2025-01-04 03:44:57 +00:00
|
|
|
// console.log("isSave", isAlreadyOnWishlist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleSaveWishlist = async (uploadId: any) => {
|
|
|
|
|
if (Number(userRoleId) < 1 || userRoleId == undefined) {
|
|
|
|
|
router.push("/auth/login");
|
|
|
|
|
} else {
|
|
|
|
|
console.log("data", uploadId);
|
|
|
|
|
const data = {
|
|
|
|
|
mediaUploadId: uploadId,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loading();
|
|
|
|
|
checkWishlist(uploadId);
|
|
|
|
|
|
|
|
|
|
const res = await saveWishlist(data);
|
2025-01-04 17:11:14 +00:00
|
|
|
if (res?.error) {
|
2025-01-04 03:44:57 +00:00
|
|
|
error(res.message);
|
|
|
|
|
console.log("simpan data", res);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
successCallback("Konten Berhasil Disimpan");
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-01-02 11:53:11 +00:00
|
|
|
|
2025-11-17 17:31:00 +00:00
|
|
|
async function shareToEmail(uploadId: any) {
|
2025-01-12 07:41:04 +00:00
|
|
|
if (Number(userRoleId) < 1 || userRoleId == undefined) {
|
|
|
|
|
router.push("/auth/login");
|
|
|
|
|
} else {
|
|
|
|
|
const data = {
|
2025-11-17 17:31:00 +00:00
|
|
|
id: uploadId,
|
2025-01-12 07:41:04 +00:00
|
|
|
email: emailShareList || [emailShareInput],
|
|
|
|
|
};
|
|
|
|
|
loading();
|
2025-11-17 17:31:00 +00:00
|
|
|
const res = await sendMediaRewriteToEmail(data.id, data.email);
|
2025-01-12 07:41:04 +00:00
|
|
|
if (res?.error) {
|
|
|
|
|
error(res.message);
|
|
|
|
|
return false;
|
2025-01-10 15:14:49 +00:00
|
|
|
}
|
2025-01-12 07:41:04 +00:00
|
|
|
close();
|
|
|
|
|
successCallback("Konten Telah Dikirim");
|
2025-01-10 15:14:49 +00:00
|
|
|
}
|
2025-01-12 07:41:04 +00:00
|
|
|
}
|
2025-01-10 15:14:49 +00:00
|
|
|
|
2025-11-17 17:31:00 +00:00
|
|
|
|
2025-01-12 07:41:04 +00:00
|
|
|
const handleEmailList = (e: any) => {
|
|
|
|
|
const arrayEmail: any = [];
|
|
|
|
|
for (let i = 0; i < emailShareList?.length; i += 1) {
|
|
|
|
|
arrayEmail.push(emailShareList[i]);
|
|
|
|
|
}
|
|
|
|
|
if (e.which == 13) {
|
|
|
|
|
if (e.target.value) {
|
|
|
|
|
arrayEmail.push(e.target.value);
|
|
|
|
|
setEmailShareList(arrayEmail);
|
|
|
|
|
setEmailShareInput("");
|
2025-01-10 15:14:49 +00:00
|
|
|
}
|
2025-01-12 07:41:04 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
2025-01-10 15:14:49 +00:00
|
|
|
|
2025-01-02 11:53:11 +00:00
|
|
|
return (
|
2025-01-04 03:44:57 +00:00
|
|
|
<>
|
2025-01-02 11:53:11 +00:00
|
|
|
<HeaderManagement />
|
2025-01-31 12:51:04 +00:00
|
|
|
<div className="flex flex-col lg:flex-row">
|
2025-01-02 11:53:11 +00:00
|
|
|
<SidebarManagement />
|
2025-02-11 11:16:07 +00:00
|
|
|
<div className="w-full lg:w-2/3 p-8 lg:p-14">
|
|
|
|
|
<h1 className="text-2xl w-fit font-bold bg-[#bb3523] px-4 py-1 rounded-lg text-center text-white mb-4">
|
2025-07-06 09:23:45 +00:00
|
|
|
<span className="text-black">{t("gallery", { defaultValue: "Gallery" })} </span>
|
|
|
|
|
{t("content", { defaultValue: "Content" })} Rewrite
|
2025-02-11 11:16:07 +00:00
|
|
|
</h1>
|
2025-01-12 07:41:04 +00:00
|
|
|
<div className="">
|
2025-01-04 03:44:57 +00:00
|
|
|
{contentImage?.length > 0 ? (
|
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
|
|
|
|
{contentImage?.map((image: any) => (
|
2025-06-03 00:59:48 +00:00
|
|
|
<Card
|
|
|
|
|
key={image?.id}
|
|
|
|
|
className="hover:scale-105 transition-transform duration-300"
|
|
|
|
|
>
|
2025-02-15 14:43:19 +00:00
|
|
|
<CardContent className="flex flex-col text-xs lg:text-sm w-full p-0">
|
|
|
|
|
<div>
|
|
|
|
|
<div className="relative group overflow-hidden shadow-md hover:shadow-lg">
|
|
|
|
|
<div className="relative h-60 rounded-lg overflow-hidden">
|
2025-06-03 00:59:48 +00:00
|
|
|
<ImageBlurry
|
|
|
|
|
src={image?.thumbnailUrl}
|
|
|
|
|
alt={image?.title}
|
|
|
|
|
style={{
|
|
|
|
|
objectFit: "contain",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-06-07 13:28:41 +00:00
|
|
|
<div className="absolute bottom-0 left-0 right-0 bg-black text-white">
|
2025-06-03 00:59:48 +00:00
|
|
|
<Link
|
|
|
|
|
href={`/content-management/rewrite/detail/${image.id}`}
|
|
|
|
|
>
|
|
|
|
|
<p className="text-sm p-2 lg:text-base font-semibold truncate">
|
|
|
|
|
{image?.title}
|
|
|
|
|
</p>
|
2025-02-15 14:43:19 +00:00
|
|
|
</Link>
|
2025-06-07 13:28:41 +00:00
|
|
|
<p className="flex text-[10px] mr-1 mb-2 items-center justify-end self-end">
|
2025-02-15 14:43:19 +00:00
|
|
|
<Popover>
|
2025-06-03 00:59:48 +00:00
|
|
|
<PopoverTrigger
|
|
|
|
|
className="flex cursor-pointer"
|
|
|
|
|
asChild
|
|
|
|
|
>
|
2025-02-15 14:43:19 +00:00
|
|
|
<a className="flex justify-end items-end place-items-end">
|
2025-06-03 00:59:48 +00:00
|
|
|
<Icon
|
|
|
|
|
className="text-white ml-1"
|
|
|
|
|
fontSize={25}
|
|
|
|
|
icon="tabler:dots"
|
|
|
|
|
/>
|
2025-02-15 14:43:19 +00:00
|
|
|
</a>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
<PopoverContent className="w-52">
|
2025-06-07 13:28:41 +00:00
|
|
|
{/* <div
|
2025-06-03 00:59:48 +00:00
|
|
|
onClick={() =>
|
|
|
|
|
handleSaveWishlist(
|
|
|
|
|
image?.mediaUpload?.id
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
className="cursor-pointer flex flex-row gap-2 hover:text-red-800"
|
|
|
|
|
>
|
|
|
|
|
<Icon
|
|
|
|
|
icon="material-symbols:bookmark-outline"
|
|
|
|
|
fontSize={25}
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-base font-semibold mb-2">
|
2025-07-06 09:23:45 +00:00
|
|
|
{t("save", { defaultValue: "Save" })}
|
2025-06-03 00:59:48 +00:00
|
|
|
</p>
|
2025-06-07 13:28:41 +00:00
|
|
|
</div> */}
|
|
|
|
|
{/* <Link
|
2025-06-03 05:46:06 +00:00
|
|
|
href={`/content-management/rewrite/create/${image?.mediaUploadId}`}
|
2025-06-03 00:59:48 +00:00
|
|
|
className="flex flex-row hover:text-red-800 gap-2"
|
|
|
|
|
>
|
2025-02-15 14:43:19 +00:00
|
|
|
<Icon icon="jam:write" fontSize={25} />
|
2025-06-03 00:59:48 +00:00
|
|
|
<p className="text-base font-semibold mb-2">
|
|
|
|
|
Content Rewrite
|
|
|
|
|
</p>
|
2025-06-07 13:28:41 +00:00
|
|
|
</Link> */}
|
2025-02-15 14:43:19 +00:00
|
|
|
<div className="flex items-center gap-1 hover:text-red-800 w-full rounded-lg">
|
|
|
|
|
<Popover>
|
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
|
<button className="w-full flex flex-row items-center gap-3">
|
2025-06-03 00:59:48 +00:00
|
|
|
<Icon
|
|
|
|
|
icon="oi:share"
|
|
|
|
|
fontSize={20}
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-base font-semibold mb-1">
|
|
|
|
|
{" "}
|
2025-07-06 09:23:45 +00:00
|
|
|
{t("share", { defaultValue: "Share" })}
|
2025-06-03 00:59:48 +00:00
|
|
|
</p>
|
2025-02-15 14:43:19 +00:00
|
|
|
</button>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
<PopoverContent>
|
|
|
|
|
<div className="flex flex-col">
|
2025-06-03 00:59:48 +00:00
|
|
|
<h1 className="mb-2">
|
2025-07-06 09:23:45 +00:00
|
|
|
{t("shareTo", { defaultValue: "Share To" })}
|
2025-06-03 00:59:48 +00:00
|
|
|
</h1>
|
2025-02-15 14:43:19 +00:00
|
|
|
<div className="flex flex-col mb-2">
|
2025-06-03 00:59:48 +00:00
|
|
|
<p className="text-base font-semibold mb-1">
|
2025-07-06 09:23:45 +00:00
|
|
|
{t("destinationEmail", { defaultValue: "Destination Email" })}
|
2025-06-03 00:59:48 +00:00
|
|
|
</p>
|
|
|
|
|
<Input
|
|
|
|
|
value={emailShareInput}
|
|
|
|
|
onChange={(event) =>
|
|
|
|
|
setEmailShareInput(
|
|
|
|
|
event.target.value
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onKeyPress={handleEmailList}
|
|
|
|
|
type="email"
|
2025-07-06 09:23:45 +00:00
|
|
|
placeholder={t("pressEnter", { defaultValue: "Press Enter" })}
|
2025-06-03 00:59:48 +00:00
|
|
|
/>
|
2025-02-15 14:43:19 +00:00
|
|
|
</div>
|
2025-06-03 00:59:48 +00:00
|
|
|
<Button
|
|
|
|
|
className="bg-blue-500 text-white p-2 w-fit rounded-lg"
|
2025-11-17 17:31:00 +00:00
|
|
|
onClick={() => shareToEmail(image.id)}
|
2025-06-03 00:59:48 +00:00
|
|
|
>
|
2025-07-06 09:23:45 +00:00
|
|
|
{t("send", { defaultValue: "Send" })}
|
2025-02-15 14:43:19 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
2025-01-10 15:14:49 +00:00
|
|
|
</div>
|
2025-06-07 13:28:41 +00:00
|
|
|
<div
|
|
|
|
|
onClick={() =>
|
|
|
|
|
handleDelete(
|
|
|
|
|
image?.id
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
className="cursor-pointer flex flex-row gap-2 hover:text-red-800"
|
|
|
|
|
>
|
|
|
|
|
<Icon
|
|
|
|
|
icon="iconamoon:trash"
|
|
|
|
|
fontSize={25}
|
|
|
|
|
/>
|
|
|
|
|
<p className="text-base font-semibold mb-2">
|
2025-07-06 09:23:45 +00:00
|
|
|
{t("delete", { defaultValue: "Delete" })}
|
2025-06-07 13:28:41 +00:00
|
|
|
</p>
|
|
|
|
|
</div>
|
2025-02-15 14:43:19 +00:00
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
|
|
|
|
</p>
|
2025-01-10 15:14:49 +00:00
|
|
|
</div>
|
2025-02-15 14:43:19 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-01-10 15:14:49 +00:00
|
|
|
</div>
|
2025-01-04 03:44:57 +00:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<p className="flex items-center justify-center">
|
2025-06-03 00:59:48 +00:00
|
|
|
<Image
|
|
|
|
|
width={1920}
|
|
|
|
|
height={1080}
|
|
|
|
|
src="/assets/empty-data.png"
|
|
|
|
|
alt="empty"
|
|
|
|
|
className="h-52 w-52 my-4"
|
|
|
|
|
/>
|
2025-01-04 03:44:57 +00:00
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-01-02 11:53:11 +00:00
|
|
|
</div>
|
2025-01-04 03:44:57 +00:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
2025-01-02 11:53:11 +00:00
|
|
|
|
2025-01-04 03:44:57 +00:00
|
|
|
export default page;
|