/** * File: page.tsx * Created by: AI Assistant * Date: 2025-11-29 * Purpose: Video list page for kreatiVortex platform * Part of: kreatiVortex - Platform Pembelajaran Tari Online */ 'use client'; import { Link } from '@/i18n/routing'; import ActionButton from '@/components/ActionButton'; import VideoCard from '@/components/VideoCard'; import { useFetch } from '@/hooks/useFetch'; import { useTranslations } from 'next-intl'; import { Video } from 'lucide-react'; import { useState, useEffect } from 'react'; import { canUploadVideos } from '@/lib/admin'; interface VideoData extends Record { id: string; title: string; description: string; videoType: 'YOUTUBE' | 'LOCAL'; videoUrl: string; viewCount: number; createdAt: string; isPublic: boolean; uploaderId: string; uploader: { user: { name: string; }; }; } export default function VideosPage() { const t = useTranslations('Videos'); const { data: videos, loading, refetch } = useFetch('/api/videos'); const [userProfile, setUserProfile] = useState(null); useEffect(() => { // Fetch user profile to check permissions const fetchProfile = async () => { try { const response = await fetch('/api/user/profile', { credentials: 'include' }); if (response.ok) { const data = await response.json(); setUserProfile(data.data); } } catch (error) { console.error('Error fetching user profile:', error); } }; fetchProfile(); }, []); const handleDelete = async (videoId: string) => { if (!confirm(t('confirmDelete'))) { return; } try { const response = await fetch(`/api/videos/${videoId}`, { method: 'DELETE', credentials: 'include' }); if (response.ok) { // Refresh videos list using refetch instead of window.reload await refetch(); } else { alert(t('errorOccurred')); } } catch (error) { console.error('Error deleting video:', error); alert(t('errorOccurred')); } }; return (
{/* Header */}

{t('title')}

{t('subtitle')}

{canUploadVideos(userProfile) && ( {t('uploadButton')} )}
{/* Loading State */} {loading ? (

{t('loading')}

) : videos && videos.length > 0 ? ( /* Video Grid */
{videos.map((video) => ( ))}
) : ( /* Empty State */
)}
); }