feat: integrate landing page with real API and add CMS to backoffice

Landing page:
- Events page now fetches from /v1/landing/cms/events (was hardcoded JSON)
- Testimonials section and page fetch from /v1/landing/cms/testimonials
- Removed dummy data, uses ISR with 60s revalidation
- Replaced thumbnail images with text-based cards (API has no thumbnails)
- Avatar initials for testimonials instead of placeholder images

Backoffice CMS:
- Added Events management page (/cms-events) with full CRUD
- Added Testimonials management page (/cms-testimonials) with full CRUD
- Both follow existing backoffice patterns (DataTable, modals, search, pagination)
- Added CMS section to sidebar navigation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
maulanasdqn
2026-04-10 14:42:24 +07:00
co-authored by Claude Opus 4.6
parent 414e4d19b8
commit 2cba806cd5
14 changed files with 1697 additions and 112 deletions
@@ -1,16 +1,72 @@
'use client';
import TESTIMONIALS from '@/data/testimonials.json';
import { buttonVariants } from '@components';
import { motion, useInView } from 'framer-motion';
import Image from 'next/image';
import Link from 'next/link';
import { useRef } from 'react';
import { useEffect, useRef, useState } from 'react';
import { FaQuoteLeft } from 'react-icons/fa';
interface ApiTestimonial {
id: number;
user_id: number;
user_fullname: string;
role: string;
content: string;
created_at: string;
is_deleted: boolean;
}
interface Testimonial {
id: number;
name: string;
role: string;
text: string;
}
const AVATAR_COLORS = [
'bg-primary-500 text-white',
'bg-blue-500 text-white',
'bg-green-500 text-white',
'bg-purple-500 text-white',
'bg-orange-500 text-white',
'bg-pink-500 text-white',
];
function getAvatarColor(index: number) {
return AVATAR_COLORS[index % AVATAR_COLORS.length];
}
function getInitial(name: string) {
return name.charAt(0).toUpperCase();
}
export function TestimonialSection() {
const ref = useRef(null);
const isInView = useInView(ref, { once: true, amount: 0.1 });
const [testimonials, setTestimonials] = useState<Testimonial[]>([]);
useEffect(() => {
fetch('https://api.imphnen.dev/v1/landing/cms/testimonials')
.then((res) => {
if (!res.ok) throw new Error('Failed to fetch');
return res.json();
})
.then((json) => {
const items: Testimonial[] = (json.data as ApiTestimonial[])
.filter((t) => !t.is_deleted)
.slice(0, 6)
.map((t) => ({
id: t.id,
name: t.user_fullname,
role: t.role,
text: t.content,
}));
setTestimonials(items);
})
.catch(() => {
setTestimonials([]);
});
}, []);
const containerVariants = {
hidden: { opacity: 0 },
@@ -59,7 +115,7 @@ export function TestimonialSection() {
initial="hidden"
animate={isInView ? 'visible' : 'hidden'}
>
{TESTIMONIALS.map((testimonial) => (
{testimonials.map((testimonial, index) => (
<motion.div
key={testimonial.id}
variants={itemVariants}
@@ -67,14 +123,11 @@ export function TestimonialSection() {
>
<div className="flex flex-col space-y-4">
<div className="flex items-center gap-4">
<Image
src={testimonial.image}
alt={testimonial.name}
width={48}
height={48}
className="w-12 h-12 rounded-full object-cover"
unoptimized
/>
<div
className={`w-12 h-12 rounded-full flex items-center justify-center text-lg font-semibold ${getAvatarColor(index)}`}
>
{getInitial(testimonial.name)}
</div>
<div>
<h4 className="font-semibold text-gray-900">
{testimonial.name}
+126 -86
View File
@@ -1,11 +1,28 @@
'use client';
import events from '@/data/events.json';
import { buttonVariants } from '@components';
import { cn } from '@utils';
import Image from 'next/image';
import { HiCalendar, HiClock, HiLocationMarker } from 'react-icons/hi';
interface ApiEvent {
id: number;
name: string;
description: string;
detail_link: string;
price: number;
is_online: boolean;
is_deleted: boolean;
location: string;
start_date: string;
end_date: string;
created_at: string;
updated_at: string;
}
interface ApiResponse {
data: ApiEvent[];
meta: Record<string, unknown>;
version: string;
}
const formatDate = (dateString: string) => {
const date = new Date(dateString);
return date.toLocaleDateString('id-ID', {
@@ -30,110 +47,123 @@ const getEventStatus = (endDate: string) => {
return end > now ? 'upcoming' : 'past';
};
export default function EventsPage() {
async function fetchEvents(): Promise<ApiEvent[]> {
const res = await fetch(
'https://api.imphnen.dev/v1/landing/cms/events',
{ next: { revalidate: 60 } }
);
if (!res.ok) {
return [];
}
const json: ApiResponse = await res.json();
return json.data.filter((e) => !e.is_deleted);
}
export default async function EventsPage() {
const events = await fetchEvents();
const sortedEvents = [...events].sort(
(a, b) =>
new Date(b.start_date).getTime() - new Date(a.start_date).getTime()
);
if (sortedEvents.length === 0) {
return (
<section className="min-h-screen bg-background container py-10">
<p className="text-center text-muted-foreground">
Belum ada event tersedia.
</p>
</section>
);
}
return (
<section className="min-h-screen bg-background container py-10">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<div className="col-span-full">
<div className="rounded-xl shadow-sm hover:shadow-md transition-shadow duration-200 overflow-hidden bg-card">
<div className="grid md:grid-cols-2">
<div className="min-h-96 bg-muted relative">
<Image
src={sortedEvents[0].thumbnail}
alt={sortedEvents[0].name}
fill
className="object-cover object-top"
sizes="(max-width: 768px) 100vw, 50vw"
priority
unoptimized
/>
</div>
<div className="p-8 flex flex-col">
<div className="flex items-center gap-2 mb-4">
<span className="bg-primary/20 text-primary text-xs px-2.5 py-1 rounded-full">
Event Terbaru
</span>
<span
className={cn(
'px-2 py-1 rounded-full text-xs',
getEventStatus(sortedEvents[0].end_date) === 'upcoming'
? 'bg-primary/20 text-primary'
: 'bg-muted text-muted-foreground'
)}
>
{getEventStatus(sortedEvents[0].end_date) === 'upcoming'
? 'Upcoming'
: 'Selesai'}
</span>
</div>
<h2 className="text-2xl font-bold mb-4 text-foreground">
{sortedEvents[0].name}
</h2>
<div className="space-y-3 mb-6 text-sm text-muted-foreground">
<div className="flex items-center gap-2">
<HiCalendar className="w-4 h-4" />
<span>{formatDate(sortedEvents[0].start_date)}</span>
</div>
<div className="flex items-center gap-2">
<HiClock className="w-4 h-4" />
<span>
{formatTime(sortedEvents[0].start_date)} -{' '}
{formatTime(sortedEvents[0].end_date)} WIB
</span>
</div>
<div className="flex items-center gap-2">
<HiLocationMarker className="w-4 h-4" />
<span>
{sortedEvents[0].type === 'online'
? 'Online'
: sortedEvents[0].location}
</span>
</div>
{sortedEvents[0].price > 0 && (
<div className="mt-1 font-medium">
Rp {sortedEvents[0].price.toLocaleString('id-ID')}
</div>
)}
</div>
<p className="text-muted-foreground mb-6 line-clamp-4">
{sortedEvents[0].description}
</p>
<a
href={sortedEvents[0].detail_link}
target="_blank"
<div className="p-8 flex flex-col">
<div className="flex items-center gap-2 mb-4">
<span className="bg-primary/20 text-primary text-xs px-2.5 py-1 rounded-full">
Event Terbaru
</span>
<span
className={cn(
buttonVariants({ variant: 'bordered' }),
'mt-auto w-full md:w-fit'
'px-2 py-1 rounded-full text-xs',
getEventStatus(sortedEvents[0].end_date) === 'upcoming'
? 'bg-primary/20 text-primary'
: 'bg-muted text-muted-foreground'
)}
>
Lihat Detail
</a>
{getEventStatus(sortedEvents[0].end_date) === 'upcoming'
? 'Upcoming'
: 'Selesai'}
</span>
<span
className={cn(
'px-2 py-1 rounded-full text-xs',
sortedEvents[0].is_online
? 'bg-blue-100 text-blue-700'
: 'bg-green-100 text-green-700'
)}
>
{sortedEvents[0].is_online ? 'Online' : 'Onsite'}
</span>
</div>
<h2 className="text-2xl font-bold mb-4 text-foreground">
{sortedEvents[0].name}
</h2>
<div className="space-y-3 mb-6 text-sm text-muted-foreground">
<div className="flex items-center gap-2">
<HiCalendar className="w-4 h-4" />
<span>{formatDate(sortedEvents[0].start_date)}</span>
</div>
<div className="flex items-center gap-2">
<HiClock className="w-4 h-4" />
<span>
{formatTime(sortedEvents[0].start_date)} -{' '}
{formatTime(sortedEvents[0].end_date)} WIB
</span>
</div>
<div className="flex items-center gap-2">
<HiLocationMarker className="w-4 h-4" />
<span>
{sortedEvents[0].is_online
? 'Online'
: sortedEvents[0].location}
</span>
</div>
{sortedEvents[0].price > 0 && (
<div className="mt-1 font-medium">
Rp {sortedEvents[0].price.toLocaleString('id-ID')}
</div>
)}
</div>
<p className="text-muted-foreground mb-6 line-clamp-4">
{sortedEvents[0].description}
</p>
<a
href={sortedEvents[0].detail_link}
target="_blank"
className={cn(
buttonVariants({ variant: 'bordered' }),
'mt-auto w-full md:w-fit'
)}
>
Lihat Detail
</a>
</div>
</div>
</div>
{sortedEvents.slice(1).map((event) => (
<div
key={event.name}
key={event.id}
className="rounded-xl shadow-sm hover:shadow-md transition-shadow duration-200 bg-card"
>
<div className="h-48 bg-muted relative">
<Image
src={event.thumbnail}
alt={event.name}
fill
className="object-cover object-top rounded-t-xl"
sizes="(max-width: 768px) 100vw, 33vw"
unoptimized
/>
</div>
<div className="p-6">
<div className="flex justify-between items-start mb-4">
<span
@@ -148,6 +178,16 @@ export default function EventsPage() {
? 'Upcoming'
: 'Selesai'}
</span>
<span
className={cn(
'px-2 py-1 rounded-full text-xs',
event.is_online
? 'bg-blue-100 text-blue-700'
: 'bg-green-100 text-green-700'
)}
>
{event.is_online ? 'Online' : 'Onsite'}
</span>
</div>
<h3 className="text-lg font-semibold mb-3 text-foreground">
{event.name}
@@ -160,7 +200,7 @@ export default function EventsPage() {
<div className="flex items-center gap-2">
<HiLocationMarker className="w-4 h-4" />
<span>
{event.type === 'online' ? 'Online' : event.location}
{event.is_online ? 'Online' : event.location}
</span>
</div>
{event.price > 0 && (
@@ -1,11 +1,58 @@
import TESTIMONIALS from '@/data/testimonials.json';
import { Button } from '@components';
import Image from 'next/image';
import Link from 'next/link';
import { BsChatLeftQuote } from 'react-icons/bs';
import { FaQuoteLeft } from 'react-icons/fa';
export default function Page() {
interface ApiTestimonial {
id: number;
user_id: number;
user_fullname: string;
role: string;
content: string;
created_at: string;
is_deleted: boolean;
}
interface ApiResponse {
data: ApiTestimonial[];
meta: Record<string, unknown>;
version: string;
}
const AVATAR_COLORS = [
'bg-primary-500 text-white',
'bg-blue-500 text-white',
'bg-green-500 text-white',
'bg-purple-500 text-white',
'bg-orange-500 text-white',
'bg-pink-500 text-white',
];
function getAvatarColor(index: number) {
return AVATAR_COLORS[index % AVATAR_COLORS.length];
}
function getInitial(name: string) {
return name.charAt(0).toUpperCase();
}
async function fetchTestimonials() {
const res = await fetch(
'https://api.imphnen.dev/v1/landing/cms/testimonials',
{ next: { revalidate: 60 } }
);
if (!res.ok) {
return [];
}
const json: ApiResponse = await res.json();
return json.data.filter((t) => !t.is_deleted);
}
export default async function Page() {
const testimonials = await fetchTestimonials();
return (
<div className="min-h-screen">
<div className="py-16 px-4 text-center border-b border-border">
@@ -21,31 +68,28 @@ export default function Page() {
</div>
<div className="grid gap-8 md:gap-6 grid-cols-1 md:grid-cols-2 lg:grid-cols-3 my-16 container">
{TESTIMONIALS.map((testimonial) => (
{testimonials.map((testimonial, index) => (
<div
key={testimonial.id}
className="p-6 bg-white rounded-xl shadow-sm hover:shadow-md transition-shadow duration-300"
>
<div className="flex flex-col space-y-4">
<div className="flex items-center gap-4">
<Image
src={testimonial.image}
alt={testimonial.name}
width={48}
height={48}
className="w-12 h-12 rounded-full object-cover"
unoptimized
/>
<div
className={`w-12 h-12 rounded-full flex items-center justify-center text-lg font-semibold ${getAvatarColor(index)}`}
>
{getInitial(testimonial.user_fullname)}
</div>
<div>
<h4 className="font-semibold text-gray-900">
{testimonial.name}
{testimonial.user_fullname}
</h4>
<p className="text-sm text-gray-600">{testimonial.role}</p>
</div>
</div>
<div className="text-gray-600 relative">
<FaQuoteLeft className="text-primary-500/30 w-6 h-6 mb-2" />
<p className="text-sm/relaxed">{testimonial.text}</p>
<p className="text-sm/relaxed">{testimonial.content}</p>
</div>
</div>
</div>