This commit is contained in:
Anang Yusman 2025-11-02 18:38:32 +08:00
parent c912b21b66
commit 1787bc51f6
9 changed files with 71 additions and 20 deletions

View File

@ -0,0 +1,19 @@
import DetailContent from "@/components/details/details-content";
import Footer from "@/components/landing-page/footer";
import Navbar from "@/components/landing-page/navbar";
import Image from "next/image";
export default function Slug() {
return (
<div className="relative min-h-screen font-[family-name:var(--font-geist-sans)]">
<div className="relative z-10 bg-[#F2F4F3] max-w-7xl mx-auto">
<Navbar />
<div className="flex-1">
<DetailContent />
</div>
<Footer />
</div>
</div>
);
}

View File

@ -2,7 +2,11 @@
import Image from "next/image"; import Image from "next/image";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import Link from "next/link"; import Link from "next/link";
import { getArticleById, getListArticle } from "@/service/article"; import {
getArticleById,
getArticleBySlug,
getListArticle,
} from "@/service/article";
import { close, error, loading } from "@/config/swal"; import { close, error, loading } from "@/config/swal";
import { useParams, usePathname } from "next/navigation"; import { useParams, usePathname } from "next/navigation";
import { Link2, MailIcon } from "lucide-react"; import { Link2, MailIcon } from "lucide-react";
@ -16,6 +20,7 @@ import {
} from "@/service/master-user"; } from "@/service/master-user";
import { saveActivity } from "@/service/activity-log"; import { saveActivity } from "@/service/activity-log";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { Badge } from "../ui/badge";
type TabKey = "trending" | "comments" | "latest"; type TabKey = "trending" | "comments" | "latest";
@ -25,6 +30,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { categories: {
@ -54,6 +60,7 @@ type Advertise = {
export default function DetailContent() { export default function DetailContent() {
const params = useParams(); const params = useParams();
const id = params?.id; const id = params?.id;
const slug = params?.slug;
const pathname = usePathname(); const pathname = usePathname();
const [page, setPage] = useState(1); const [page, setPage] = useState(1);
const [totalPage, setTotalPage] = useState(1); const [totalPage, setTotalPage] = useState(1);
@ -296,13 +303,13 @@ export default function DetailContent() {
async function initStateData() { async function initStateData() {
loading(); loading();
const res = await getArticleById(id); const res = await getArticleBySlug(slug);
const data = res.data?.data; const data = res?.data?.data;
setThumbnail(data?.thumbnailUrl); setThumbnail(data?.thumbnailUrl);
setDiseId(data?.aiArticleId); setDiseId(data?.aiArticleId);
setDetailFiles(data?.files); setDetailFiles(data?.files);
setArticleDetail(data); setArticleDetail(data); // <-- Add this
close(); close();
} }
@ -526,9 +533,17 @@ export default function DetailContent() {
</span> </span>
<div className="flex flex-wrap gap-2 mt-1"> <div className="flex flex-wrap gap-2 mt-1">
{articleDetail?.tags ? ( {articleDetail?.tags ? (
<span className="bg-gray-100 text-gray-700 text-sm px-2 py-1 rounded"> articleDetail.tags
{articleDetail.tags} .split(",") // pisahkan berdasarkan koma
</span> .map((tag: string, index: number) => (
<Badge
key={index}
variant="secondary"
className="text-sm"
>
{tag.trim()}
</Badge>
))
) : ( ) : (
<span className="text-sm text-gray-500">Tidak ada tag</span> <span className="text-sm text-gray-500">Tidak ada tag</span>
)} )}
@ -724,7 +739,7 @@ export default function DetailContent() {
{/* Artikel utama (featured) */} {/* Artikel utama (featured) */}
{articles.length > 0 && ( {articles.length > 0 && (
<div className="relative"> <div className="relative">
<Link href={`/detail/${articles[0]?.id}`}> <Link href={`/details/${articles[0]?.slug}`}>
<Image <Image
src={articles[0]?.thumbnailUrl || "/default.jpg"} src={articles[0]?.thumbnailUrl || "/default.jpg"}
alt={articles[0]?.title || "Recommended Article"} alt={articles[0]?.title || "Recommended Article"}
@ -758,7 +773,7 @@ export default function DetailContent() {
<div key={item.id}> <div key={item.id}>
<Link <Link
className="flex space-x-3" className="flex space-x-3"
href={`/detail/${item?.id}`} href={`/details/${item?.slug}`}
> >
<Image <Image
src={item.thumbnailUrl || "/default.jpg"} src={item.thumbnailUrl || "/default.jpg"}

View File

@ -9,6 +9,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { title: string }[]; categories: { title: string }[];
@ -51,7 +52,7 @@ export default function BannerNews() {
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4 p-4"> <div className="grid grid-cols-1 lg:grid-cols-3 gap-4 p-4">
{/* Artikel utama */} {/* Artikel utama */}
<div className="lg:col-span-2 relative"> <div className="lg:col-span-2 relative">
<Link href={`/detail/${mainArticle?.id}`}> <Link href={`/details/${mainArticle?.slug}`}>
<img <img
src={mainArticle.thumbnailUrl || mainArticle.files?.[0]?.fileUrl} src={mainArticle.thumbnailUrl || mainArticle.files?.[0]?.fileUrl}
alt={mainArticle.files?.[0]?.file_alt || mainArticle.title} alt={mainArticle.files?.[0]?.file_alt || mainArticle.title}
@ -72,7 +73,7 @@ export default function BannerNews() {
<div className="grid grid-cols-1 gap-4"> <div className="grid grid-cols-1 gap-4">
{sideArticles.map((article) => ( {sideArticles.map((article) => (
<div key={article.id} className="relative"> <div key={article.id} className="relative">
<Link href={`/detail/${article?.id}`}> <Link href={`/details/${article?.slug}`}>
<img <img
src={article.thumbnailUrl || article.files?.[0]?.fileUrl} src={article.thumbnailUrl || article.files?.[0]?.fileUrl}
alt={article.files?.[0]?.file_alt || article.title} alt={article.files?.[0]?.file_alt || article.title}

View File

@ -13,6 +13,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { title: string }[]; categories: { title: string }[];
@ -79,7 +80,7 @@ export default function BreakingNews() {
key={article.id} key={article.id}
className="bg-white border overflow-hidden shadow-sm hover:shadow-md transition" className="bg-white border overflow-hidden shadow-sm hover:shadow-md transition"
> >
<Link href={`/detail/${article?.id}`}> <Link href={`/details/${article?.slug}`}>
<div className="relative w-full h-40"> <div className="relative w-full h-40">
<Image <Image
src={ src={

View File

@ -13,6 +13,7 @@ type Article = {
title: string; title: string;
description: string; description: string;
categoryName: string; categoryName: string;
slug: string;
createdAt: string; createdAt: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
@ -98,7 +99,7 @@ export default function Header() {
key={post.id} key={post.id}
className="relative group overflow-hidden h-56 md:h-64" className="relative group overflow-hidden h-56 md:h-64"
> >
<Link href={`/detail/${post?.id}`}> <Link href={`/details/${post?.slug}`}>
<Image <Image
src={post.thumbnailUrl || "/default.jpg"} src={post.thumbnailUrl || "/default.jpg"}
alt={post.title} alt={post.title}
@ -144,7 +145,7 @@ export default function Header() {
key={post.id} key={post.id}
className="relative group overflow-hidden h-56 md:h-64" className="relative group overflow-hidden h-56 md:h-64"
> >
<Link href={`/detail/${post?.id}`}> <Link href={`/details/${post?.slug}`}>
<Image <Image
src={post.thumbnailUrl || "/default.jpg"} src={post.thumbnailUrl || "/default.jpg"}
alt={post.title} alt={post.title}

View File

@ -12,6 +12,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { title: string }[]; categories: { title: string }[];
@ -102,7 +103,7 @@ export default function LatestNews() {
{articles.slice(0, 5).map((article, index) => ( {articles.slice(0, 5).map((article, index) => (
<Link <Link
key={article.id} key={article.id}
href={`/detail/${article.id}`} href={`/details/${article.slug}`}
className={`grid grid-cols-1 md:grid-cols-2 gap-4 mb-6 items-center`} className={`grid grid-cols-1 md:grid-cols-2 gap-4 mb-6 items-center`}
> >
{/* Gambar */} {/* Gambar */}

View File

@ -12,6 +12,7 @@ type Article = {
description: string; description: string;
categoryName: string; categoryName: string;
createdAt: string; createdAt: string;
slug: string;
createdByName: string; createdByName: string;
thumbnailUrl: string; thumbnailUrl: string;
categories: { title: string }[]; categories: { title: string }[];
@ -221,7 +222,10 @@ export default function News() {
function PostItem({ post }: { post: Article }) { function PostItem({ post }: { post: Article }) {
return ( return (
<div className="flex gap-4 mb-6 pb-4"> <div className="flex gap-4 mb-6 pb-4">
<Link className="flex items-center gap-4 " href={`/detail/${post?.id}`}> <Link
className="flex items-center gap-4 "
href={`/details/${post?.slug}`}
>
<div className="relative w-40 h-28 flex-shrink-0"> <div className="relative w-40 h-28 flex-shrink-0">
<Image <Image
src={ src={

View File

@ -199,11 +199,11 @@ export default function ArticleTable() {
initState(); initState();
}; };
const copyUrlArticle = async (id: number) => { const copyUrlArticle = async (slug: any) => {
const url = const url =
`${window.location.protocol}//${window.location.host}` + `${window.location.protocol}//${window.location.host}` +
"/detail/" + "/details/" +
`${id}`; `${slug}`;
try { try {
await navigator.clipboard.writeText(url); await navigator.clipboard.writeText(url);
successToast("Success", "Article Copy to Clipboard"); successToast("Success", "Article Copy to Clipboard");
@ -263,7 +263,9 @@ export default function ArticleTable() {
</Button> </Button>
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent className="w-56"> <DropdownMenuContent className="w-56">
<DropdownMenuItem onClick={() => copyUrlArticle(article.id)}> <DropdownMenuItem
onClick={() => copyUrlArticle(article.slug)}
>
<CopyIcon className="mr-2 h-4 w-4" /> <CopyIcon className="mr-2 h-4 w-4" />
Copy Url Article Copy Url Article
</DropdownMenuItem> </DropdownMenuItem>

View File

@ -106,6 +106,13 @@ export async function getArticleById(id: any) {
return await httpGet(`/articles/${id}`, headers); return await httpGet(`/articles/${id}`, headers);
} }
export async function getArticleBySlug(slug: any) {
const headers = {
"content-type": "application/json",
};
return await httpGet(`/articles/slug/${slug}`, headers);
}
export async function deleteArticle(id: string) { export async function deleteArticle(id: string) {
const headers = { const headers = {
"content-type": "application/json", "content-type": "application/json",