@@ -0,0 +1,413 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { FaTimes, FaPlus, FaTrash, FaUpload, FaImage } from 'react-icons/fa';
|
||||
import { Album, Song } from '@/lib/types';
|
||||
|
||||
interface AddAlbumModalProps {
|
||||
show: boolean;
|
||||
onClose: () => void;
|
||||
onAdd: (album: Album) => void;
|
||||
}
|
||||
|
||||
export default function AddAlbumModal({ show, onClose, onAdd }: AddAlbumModalProps) {
|
||||
const [title, setTitle] = useState('');
|
||||
const [year, setYear] = useState('');
|
||||
const [genre, setGenre] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
const [price, setPrice] = useState('');
|
||||
const [coverImage, setCoverImage] = useState('');
|
||||
const [coverImageFile, setCoverImageFile] = useState<File | null>(null);
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [songs, setSongs] = useState<Song[]>([{ id: '', title: '', duration: '', previewUrl: '', fullUrl: '' }]);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const handleAddSong = () => {
|
||||
setSongs([...songs, { id: '', title: '', duration: '', previewUrl: '', fullUrl: '' }]);
|
||||
};
|
||||
|
||||
const handleRemoveSong = (index: number) => {
|
||||
if (songs.length > 1) {
|
||||
setSongs(songs.filter((_, i) => i !== index));
|
||||
}
|
||||
};
|
||||
|
||||
const handleSongChange = (index: number, field: 'title' | 'duration' | 'previewUrl' | 'fullUrl', value: string) => {
|
||||
const updatedSongs = [...songs];
|
||||
updatedSongs[index][field] = value;
|
||||
setSongs(updatedSongs);
|
||||
};
|
||||
|
||||
const handleCoverImageChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
setCoverImageFile(file);
|
||||
setIsUploading(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('folder', 'album-covers');
|
||||
|
||||
const response = await fetch('/api/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Upload failed');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
setCoverImage(data.url);
|
||||
} catch (err) {
|
||||
setError('Failed to upload cover image');
|
||||
setCoverImageFile(null);
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
|
||||
// Validation
|
||||
if (!title.trim()) {
|
||||
setError('Title is required');
|
||||
return;
|
||||
}
|
||||
|
||||
const yearNum = parseInt(year);
|
||||
if (!year || yearNum < 1900 || yearNum > new Date().getFullYear() + 1) {
|
||||
setError('Please enter a valid year');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!genre.trim()) {
|
||||
setError('Genre is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!description.trim()) {
|
||||
setError('Description is required');
|
||||
return;
|
||||
}
|
||||
|
||||
const priceNum = parseFloat(price);
|
||||
if (!price || priceNum <= 0) {
|
||||
setError('Please enter a valid price');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate songs
|
||||
for (let i = 0; i < songs.length; i++) {
|
||||
if (!songs[i].title.trim()) {
|
||||
setError(`Song ${i + 1} title is required`);
|
||||
return;
|
||||
}
|
||||
if (!songs[i].duration.trim()) {
|
||||
setError(`Song ${i + 1} duration is required`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Create album
|
||||
const albumId = title.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
|
||||
const albumSongs: Song[] = songs.map((song, index) => ({
|
||||
id: `${albumId}-${index + 1}`,
|
||||
title: song.title,
|
||||
duration: song.duration,
|
||||
previewUrl: song.previewUrl || '/audio/preview-1.mp3',
|
||||
fullUrl: song.fullUrl || '/audio/default-full.mp3',
|
||||
}));
|
||||
|
||||
const newAlbum: Album = {
|
||||
id: albumId,
|
||||
title,
|
||||
coverImage: coverImage || '/albums/default-cover.jpg',
|
||||
year: yearNum,
|
||||
genre,
|
||||
description,
|
||||
price: priceNum,
|
||||
songs: albumSongs,
|
||||
};
|
||||
|
||||
onAdd(newAlbum);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setTitle('');
|
||||
setYear('');
|
||||
setGenre('');
|
||||
setDescription('');
|
||||
setPrice('');
|
||||
setCoverImage('');
|
||||
setCoverImageFile(null);
|
||||
setSongs([{ id: '', title: '', duration: '', previewUrl: '', fullUrl: '' }]);
|
||||
setError('');
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{show && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="fixed inset-0 bg-black/80 backdrop-blur-sm z-50 flex items-center justify-center p-4"
|
||||
onClick={handleClose}
|
||||
>
|
||||
<motion.div
|
||||
initial={{ scale: 0.9, opacity: 0 }}
|
||||
animate={{ scale: 1, opacity: 1 }}
|
||||
exit={{ scale: 0.9, opacity: 0 }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="glass-effect rounded-2xl max-w-2xl w-full max-h-[90vh] overflow-y-auto p-8 border-2 border-accent-cyan/30"
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h2 className="text-2xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-accent-cyan to-accent-orange">
|
||||
Add New Album
|
||||
</h2>
|
||||
<button
|
||||
onClick={handleClose}
|
||||
className="p-2 hover:bg-white/10 rounded-full transition-colors"
|
||||
aria-label="Close"
|
||||
>
|
||||
<FaTimes className="text-xl text-gray-400" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Form */}
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{/* Title */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Album Title *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="Enter album title"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Cover Image Upload */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Album Cover Image
|
||||
</label>
|
||||
<div className="flex items-center gap-4">
|
||||
<label className="flex-1 cursor-pointer">
|
||||
<div className="flex items-center justify-center gap-2 px-4 py-3 bg-white/5 border border-white/10 rounded-lg hover:bg-white/10 transition-colors">
|
||||
{isUploading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-2 border-accent-cyan border-t-transparent"></div>
|
||||
<span className="text-gray-400 text-sm">Uploading...</span>
|
||||
</>
|
||||
) : coverImage ? (
|
||||
<>
|
||||
<FaImage className="text-accent-cyan" />
|
||||
<span className="text-accent-cyan text-sm">Image Uploaded</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<FaUpload className="text-gray-400" />
|
||||
<span className="text-gray-400 text-sm">Choose Image</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={handleCoverImageChange}
|
||||
className="hidden"
|
||||
disabled={isUploading}
|
||||
/>
|
||||
</label>
|
||||
{coverImage && (
|
||||
<div className="w-16 h-16 rounded-lg overflow-hidden border border-white/10">
|
||||
<img src={coverImage} alt="Cover preview" className="w-full h-full object-cover" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-2">
|
||||
Upload an album cover image (max 5MB, JPG/PNG/WEBP)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Year and Genre */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Year *
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
value={year}
|
||||
onChange={(e) => setYear(e.target.value)}
|
||||
placeholder="2024"
|
||||
min="1900"
|
||||
max={new Date().getFullYear() + 1}
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Genre *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={genre}
|
||||
onChange={(e) => setGenre(e.target.value)}
|
||||
placeholder="Progressive Rock"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Description *
|
||||
</label>
|
||||
<textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="Enter album description"
|
||||
rows={3}
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500 resize-none"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Price */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Price ($) *
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
value={price}
|
||||
onChange={(e) => setPrice(e.target.value)}
|
||||
placeholder="9.99"
|
||||
min="0.01"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Songs */}
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<label className="block text-sm font-medium text-gray-300">
|
||||
Songs *
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleAddSong}
|
||||
className="px-3 py-1 bg-accent-cyan/20 hover:bg-accent-cyan/30 text-accent-cyan rounded-lg text-sm flex items-center gap-1 transition-colors"
|
||||
>
|
||||
<FaPlus className="text-xs" />
|
||||
Add Song
|
||||
</button>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
{songs.map((song, index) => (
|
||||
<div key={index} className="p-4 bg-white/5 rounded-lg border border-white/10 space-y-2">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-sm font-medium text-gray-300">Song {index + 1}</span>
|
||||
{songs.length > 1 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleRemoveSong(index)}
|
||||
className="p-1.5 bg-red-500/20 hover:bg-red-500/30 text-red-400 rounded-lg transition-colors"
|
||||
aria-label="Remove song"
|
||||
>
|
||||
<FaTrash className="text-xs" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={song.title}
|
||||
onChange={(e) => handleSongChange(index, 'title', e.target.value)}
|
||||
placeholder="Song title"
|
||||
className="px-3 py-2 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500 text-sm"
|
||||
required
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={song.duration}
|
||||
onChange={(e) => handleSongChange(index, 'duration', e.target.value)}
|
||||
placeholder="3:45"
|
||||
className="px-3 py-2 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500 text-sm"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<input
|
||||
type="url"
|
||||
value={song.fullUrl}
|
||||
onChange={(e) => handleSongChange(index, 'fullUrl', e.target.value)}
|
||||
placeholder="Song URL (e.g., https://example.com/song.mp3)"
|
||||
className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500 text-sm"
|
||||
/>
|
||||
<input
|
||||
type="url"
|
||||
value={song.previewUrl}
|
||||
onChange={(e) => handleSongChange(index, 'previewUrl', e.target.value)}
|
||||
placeholder="Preview URL (optional - 30s clip)"
|
||||
className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500 text-sm"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Error Message */}
|
||||
{error && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: -10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
className="p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-red-300 text-sm"
|
||||
>
|
||||
{error}
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Submit Button */}
|
||||
<div className="flex gap-3 pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClose}
|
||||
className="flex-1 py-3 bg-white/10 hover:bg-white/20 rounded-lg font-semibold text-white transition-all"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex-1 py-3 bg-gradient-to-r from-accent-cyan to-accent-cyan/80 hover:from-accent-cyan/90 hover:to-accent-cyan/70 rounded-lg font-semibold text-white transition-all glow-cyan"
|
||||
>
|
||||
Add Album
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
import { useAdmin } from '@/lib/AdminContext';
|
||||
import AdminSidebar from './AdminSidebar';
|
||||
|
||||
export default function AdminLayout({ children }: { children: React.ReactNode }) {
|
||||
const { isAuthenticated } = useAdmin();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated && pathname !== '/admin') {
|
||||
router.push('/admin');
|
||||
}
|
||||
}, [isAuthenticated, router, pathname]);
|
||||
|
||||
if (!isAuthenticated && pathname !== '/admin') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (pathname === '/admin') {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-primary-900 via-primary-800 to-primary-900 flex">
|
||||
<AdminSidebar />
|
||||
<main className="flex-1 overflow-auto">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
import { motion } from 'framer-motion';
|
||||
import { FaHome, FaMusic, FaShoppingBag, FaSignOutAlt, FaChartLine } from 'react-icons/fa';
|
||||
import { useAdmin } from '@/lib/AdminContext';
|
||||
|
||||
export default function AdminSidebar() {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const { logout } = useAdmin();
|
||||
|
||||
const handleLogout = () => {
|
||||
logout();
|
||||
router.push('/admin');
|
||||
};
|
||||
|
||||
const menuItems = [
|
||||
{ icon: FaChartLine, label: 'Dashboard', path: '/admin/dashboard' },
|
||||
{ icon: FaMusic, label: 'Albums', path: '/admin/albums' },
|
||||
{ icon: FaShoppingBag, label: 'Purchases', path: '/admin/purchases' },
|
||||
{ icon: FaHome, label: 'Back to Site', path: '/' },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="w-64 bg-primary-900/50 backdrop-blur-sm border-r border-white/10 flex flex-col">
|
||||
{/* Header */}
|
||||
<div className="p-6 border-b border-white/10">
|
||||
<h1 className="text-2xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-accent-cyan to-accent-orange">
|
||||
Admin Panel
|
||||
</h1>
|
||||
<p className="text-sm text-gray-400 mt-1">Parsa Music Store</p>
|
||||
</div>
|
||||
|
||||
{/* Menu */}
|
||||
<nav className="flex-1 p-4 space-y-2">
|
||||
{menuItems.map((item) => {
|
||||
const isActive = pathname === item.path;
|
||||
const Icon = item.icon;
|
||||
|
||||
return (
|
||||
<motion.button
|
||||
key={item.path}
|
||||
whileHover={{ x: 4 }}
|
||||
onClick={() => router.push(item.path)}
|
||||
className={`w-full flex items-center gap-3 px-4 py-3 rounded-lg transition-all ${
|
||||
isActive
|
||||
? 'bg-accent-cyan/20 text-accent-cyan'
|
||||
: 'text-gray-300 hover:bg-white/5'
|
||||
}`}
|
||||
>
|
||||
<Icon className="text-xl" />
|
||||
<span className="font-medium">{item.label}</span>
|
||||
</motion.button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Logout */}
|
||||
<div className="p-4 border-t border-white/10">
|
||||
<motion.button
|
||||
whileHover={{ x: 4 }}
|
||||
onClick={handleLogout}
|
||||
className="w-full flex items-center gap-3 px-4 py-3 rounded-lg text-red-400 hover:bg-red-500/10 transition-all"
|
||||
>
|
||||
<FaSignOutAlt className="text-xl" />
|
||||
<span className="font-medium">Logout</span>
|
||||
</motion.button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
import { motion } from 'framer-motion';
|
||||
import AlbumCard from './AlbumCard';
|
||||
import { Album } from '@/lib/types';
|
||||
import { albums } from '@/lib/data';
|
||||
import { useAlbums } from '@/lib/AlbumsContext';
|
||||
|
||||
interface AlbumShowcaseProps {
|
||||
purchasedAlbums: string[];
|
||||
@@ -12,6 +12,7 @@ interface AlbumShowcaseProps {
|
||||
}
|
||||
|
||||
export default function AlbumShowcase({ purchasedAlbums, onPlay, onPurchase }: AlbumShowcaseProps) {
|
||||
const { albums } = useAlbums();
|
||||
return (
|
||||
<section className="py-20 px-4 md:px-8" id="albums">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
'use client';
|
||||
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { FaExclamationTriangle, FaTimes } from 'react-icons/fa';
|
||||
import { Album } from '@/lib/types';
|
||||
|
||||
interface DeleteConfirmationModalProps {
|
||||
show: boolean;
|
||||
album: Album | null;
|
||||
onClose: () => void;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
|
||||
export default function DeleteConfirmationModal({
|
||||
show,
|
||||
album,
|
||||
onClose,
|
||||
onConfirm,
|
||||
}: DeleteConfirmationModalProps) {
|
||||
if (!album) return null;
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{show && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="fixed inset-0 bg-black/80 backdrop-blur-sm z-50 flex items-center justify-center p-4"
|
||||
onClick={onClose}
|
||||
>
|
||||
<motion.div
|
||||
initial={{ scale: 0.9, opacity: 0 }}
|
||||
animate={{ scale: 1, opacity: 1 }}
|
||||
exit={{ scale: 0.9, opacity: 0 }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="glass-effect rounded-2xl max-w-md w-full p-8 border-2 border-red-500/30"
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-3 bg-red-500/20 rounded-full">
|
||||
<FaExclamationTriangle className="text-3xl text-red-400" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold text-white">Delete Album</h2>
|
||||
<p className="text-sm text-gray-400">This action cannot be undone</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="p-2 hover:bg-white/10 rounded-full transition-colors"
|
||||
aria-label="Close"
|
||||
>
|
||||
<FaTimes className="text-xl text-gray-400" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="mb-6">
|
||||
<p className="text-gray-300 mb-4">
|
||||
Are you sure you want to delete the following album?
|
||||
</p>
|
||||
<div className="p-4 bg-white/5 rounded-lg">
|
||||
<p className="text-white font-semibold">{album.title}</p>
|
||||
<p className="text-sm text-gray-400">
|
||||
{album.year} • {album.genre} • {album.songs.length} tracks
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-red-400 text-sm mt-4">
|
||||
Warning: This will permanently delete this album and all associated data.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="flex-1 py-3 bg-white/10 hover:bg-white/20 rounded-lg font-semibold text-white transition-all"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={onConfirm}
|
||||
className="flex-1 py-3 bg-gradient-to-r from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 rounded-lg font-semibold text-white transition-all"
|
||||
>
|
||||
Delete Album
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { FaTimes, FaPlus, FaTrash, FaUpload, FaImage } from 'react-icons/fa';
|
||||
import { Album, Song } from '@/lib/types';
|
||||
|
||||
interface EditAlbumModalProps {
|
||||
show: boolean;
|
||||
album: Album | null;
|
||||
onClose: () => void;
|
||||
onUpdate: (albumId: string, album: Album) => void;
|
||||
}
|
||||
|
||||
export default function EditAlbumModal({ show, album, onClose, onUpdate }: EditAlbumModalProps) {
|
||||
const [title, setTitle] = useState('');
|
||||
const [year, setYear] = useState('');
|
||||
const [genre, setGenre] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
const [price, setPrice] = useState('');
|
||||
const [coverImage, setCoverImage] = useState('');
|
||||
const [coverImageFile, setCoverImageFile] = useState<File | null>(null);
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [songs, setSongs] = useState<Song[]>([{ id: '', title: '', duration: '', previewUrl: '', fullUrl: '' }]);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
// Populate form when album changes
|
||||
useEffect(() => {
|
||||
if (album) {
|
||||
setTitle(album.title);
|
||||
setYear(album.year.toString());
|
||||
setGenre(album.genre);
|
||||
setDescription(album.description);
|
||||
setPrice(album.price.toString());
|
||||
setCoverImage(album.coverImage || '');
|
||||
setSongs(album.songs.map((song) => ({ ...song })));
|
||||
}
|
||||
}, [album]);
|
||||
|
||||
const handleAddSong = () => {
|
||||
setSongs([...songs, { id: '', title: '', duration: '', previewUrl: '', fullUrl: '' }]);
|
||||
};
|
||||
|
||||
const handleRemoveSong = (index: number) => {
|
||||
if (songs.length > 1) {
|
||||
setSongs(songs.filter((_, i) => i !== index));
|
||||
}
|
||||
};
|
||||
|
||||
const handleSongChange = (index: number, field: 'title' | 'duration' | 'previewUrl' | 'fullUrl', value: string) => {
|
||||
const updatedSongs = [...songs];
|
||||
updatedSongs[index][field] = value;
|
||||
setSongs(updatedSongs);
|
||||
};
|
||||
|
||||
const handleCoverImageChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
setCoverImageFile(file);
|
||||
setIsUploading(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('folder', 'album-covers');
|
||||
|
||||
const response = await fetch('/api/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Upload failed');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
setCoverImage(data.url);
|
||||
} catch (err) {
|
||||
setError('Failed to upload cover image');
|
||||
setCoverImageFile(null);
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
|
||||
if (!album) return;
|
||||
|
||||
// Validation
|
||||
if (!title.trim()) {
|
||||
setError('Title is required');
|
||||
return;
|
||||
}
|
||||
|
||||
const yearNum = parseInt(year);
|
||||
if (!year || yearNum < 1900 || yearNum > new Date().getFullYear() + 1) {
|
||||
setError('Please enter a valid year');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!genre.trim()) {
|
||||
setError('Genre is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!description.trim()) {
|
||||
setError('Description is required');
|
||||
return;
|
||||
}
|
||||
|
||||
const priceNum = parseFloat(price);
|
||||
if (!price || priceNum <= 0) {
|
||||
setError('Please enter a valid price');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate songs
|
||||
for (let i = 0; i < songs.length; i++) {
|
||||
if (!songs[i].title.trim()) {
|
||||
setError(`Song ${i + 1} title is required`);
|
||||
return;
|
||||
}
|
||||
if (!songs[i].duration.trim()) {
|
||||
setError(`Song ${i + 1} duration is required`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Update album
|
||||
const albumSongs: Song[] = songs.map((song, index) => ({
|
||||
id: song.id || `${album.id}-${index + 1}`,
|
||||
title: song.title,
|
||||
duration: song.duration,
|
||||
previewUrl: song.previewUrl || '/audio/preview-1.mp3',
|
||||
fullUrl: song.fullUrl || '/audio/default-full.mp3',
|
||||
}));
|
||||
|
||||
const updatedAlbum: Album = {
|
||||
id: album.id,
|
||||
title,
|
||||
coverImage: coverImage || album.coverImage || '/albums/default-cover.jpg',
|
||||
year: yearNum,
|
||||
genre,
|
||||
description,
|
||||
price: priceNum,
|
||||
songs: albumSongs,
|
||||
};
|
||||
|
||||
onUpdate(album.id, updatedAlbum);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setError('');
|
||||
onClose();
|
||||
};
|
||||
|
||||
if (!album) return null;
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{show && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className="fixed inset-0 bg-black/80 backdrop-blur-sm z-50 flex items-center justify-center p-4"
|
||||
onClick={handleClose}
|
||||
>
|
||||
<motion.div
|
||||
initial={{ scale: 0.9, opacity: 0 }}
|
||||
animate={{ scale: 1, opacity: 1 }}
|
||||
exit={{ scale: 0.9, opacity: 0 }}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="glass-effect rounded-2xl max-w-2xl w-full max-h-[90vh] overflow-y-auto p-8 border-2 border-accent-orange/30"
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h2 className="text-2xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-accent-orange to-accent-cyan">
|
||||
Edit Album
|
||||
</h2>
|
||||
<button
|
||||
onClick={handleClose}
|
||||
className="p-2 hover:bg-white/10 rounded-full transition-colors"
|
||||
aria-label="Close"
|
||||
>
|
||||
<FaTimes className="text-xl text-gray-400" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Form */}
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{/* Title */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Album Title *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="Enter album title"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Cover Image Upload */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Album Cover Image
|
||||
</label>
|
||||
<div className="flex items-center gap-4">
|
||||
<label className="flex-1 cursor-pointer">
|
||||
<div className="flex items-center justify-center gap-2 px-4 py-3 bg-white/5 border border-white/10 rounded-lg hover:bg-white/10 transition-colors">
|
||||
{isUploading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-2 border-accent-orange border-t-transparent"></div>
|
||||
<span className="text-gray-400 text-sm">Uploading...</span>
|
||||
</>
|
||||
) : coverImage ? (
|
||||
<>
|
||||
<FaImage className="text-accent-orange" />
|
||||
<span className="text-accent-orange text-sm">Change Image</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<FaUpload className="text-gray-400" />
|
||||
<span className="text-gray-400 text-sm">Choose Image</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={handleCoverImageChange}
|
||||
className="hidden"
|
||||
disabled={isUploading}
|
||||
/>
|
||||
</label>
|
||||
{coverImage && (
|
||||
<div className="w-16 h-16 rounded-lg overflow-hidden border border-white/10">
|
||||
<img src={coverImage} alt="Cover preview" className="w-full h-full object-cover" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-2">
|
||||
Upload an album cover image (max 5MB, JPG/PNG/WEBP)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Year and Genre */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Year *
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
value={year}
|
||||
onChange={(e) => setYear(e.target.value)}
|
||||
placeholder="2024"
|
||||
min="1900"
|
||||
max={new Date().getFullYear() + 1}
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Genre *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={genre}
|
||||
onChange={(e) => setGenre(e.target.value)}
|
||||
placeholder="Progressive Rock"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Description *
|
||||
</label>
|
||||
<textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="Enter album description"
|
||||
rows={3}
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500 resize-none"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Price */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Price ($) *
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
value={price}
|
||||
onChange={(e) => setPrice(e.target.value)}
|
||||
placeholder="9.99"
|
||||
min="0.01"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Songs */}
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<label className="block text-sm font-medium text-gray-300">
|
||||
Songs *
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleAddSong}
|
||||
className="px-3 py-1 bg-accent-orange/20 hover:bg-accent-orange/30 text-accent-orange rounded-lg text-sm flex items-center gap-1 transition-colors"
|
||||
>
|
||||
<FaPlus className="text-xs" />
|
||||
Add Song
|
||||
</button>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
{songs.map((song, index) => (
|
||||
<div key={index} className="p-4 bg-white/5 rounded-lg border border-white/10 space-y-2">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-sm font-medium text-gray-300">Song {index + 1}</span>
|
||||
{songs.length > 1 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleRemoveSong(index)}
|
||||
className="p-1.5 bg-red-500/20 hover:bg-red-500/30 text-red-400 rounded-lg transition-colors"
|
||||
aria-label="Remove song"
|
||||
>
|
||||
<FaTrash className="text-xs" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={song.title}
|
||||
onChange={(e) => handleSongChange(index, 'title', e.target.value)}
|
||||
placeholder="Song title"
|
||||
className="px-3 py-2 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500 text-sm"
|
||||
required
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={song.duration}
|
||||
onChange={(e) => handleSongChange(index, 'duration', e.target.value)}
|
||||
placeholder="3:45"
|
||||
className="px-3 py-2 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500 text-sm"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<input
|
||||
type="url"
|
||||
value={song.fullUrl}
|
||||
onChange={(e) => handleSongChange(index, 'fullUrl', e.target.value)}
|
||||
placeholder="Song URL (e.g., https://example.com/song.mp3)"
|
||||
className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500 text-sm"
|
||||
/>
|
||||
<input
|
||||
type="url"
|
||||
value={song.previewUrl}
|
||||
onChange={(e) => handleSongChange(index, 'previewUrl', e.target.value)}
|
||||
placeholder="Preview URL (optional - 30s clip)"
|
||||
className="w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg focus:border-accent-orange focus:outline-none focus:ring-2 focus:ring-accent-orange/50 text-white placeholder-gray-500 text-sm"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Error Message */}
|
||||
{error && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: -10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
className="p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-red-300 text-sm"
|
||||
>
|
||||
{error}
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Submit Button */}
|
||||
<div className="flex gap-3 pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClose}
|
||||
className="flex-1 py-3 bg-white/10 hover:bg-white/20 rounded-lg font-semibold text-white transition-all"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex-1 py-3 bg-gradient-to-r from-accent-orange to-accent-orange/80 hover:from-accent-orange/90 hover:to-accent-orange/70 rounded-lg font-semibold text-white transition-all glow-orange"
|
||||
>
|
||||
Update Album
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
@@ -32,6 +32,7 @@ export default function MusicPlayer({ album, isPurchased, onClose, onPurchase }:
|
||||
|
||||
useEffect(() => {
|
||||
const audio = audioRef.current;
|
||||
console.log(audioRef.current)
|
||||
if (!audio) return;
|
||||
|
||||
const updateTime = () => setCurrentTime(audio.currentTime);
|
||||
@@ -123,9 +124,9 @@ export default function MusicPlayer({ album, isPurchased, onClose, onPurchase }:
|
||||
animate={{ opacity: 1, scale: 1, y: 0 }}
|
||||
exit={{ opacity: 0, scale: 0.9, y: 50 }}
|
||||
transition={{ type: 'spring', damping: 25, stiffness: 300 }}
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none"
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-6 md:p-12 pointer-events-none"
|
||||
>
|
||||
<div className="w-full max-w-md pointer-events-auto relative">
|
||||
<div className="w-full max-w-sm pointer-events-auto relative">
|
||||
{/* Close Button - Top Right */}
|
||||
<motion.button
|
||||
whileHover={{ scale: 1.1 }}
|
||||
|
||||
+97
-51
@@ -14,8 +14,9 @@ interface PaymentModalProps {
|
||||
export default function PaymentModal({ album, onClose, onSuccess }: PaymentModalProps) {
|
||||
const [cardNumber, setCardNumber] = useState('');
|
||||
const [cardName, setCardName] = useState('');
|
||||
const [expiry, setExpiry] = useState('');
|
||||
const [cvv, setCvv] = useState('');
|
||||
const [phoneNumber, setPhoneNumber] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [txReceipt, setTxReceipt] = useState('');
|
||||
const [processing, setProcessing] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
@@ -25,12 +26,11 @@ export default function PaymentModal({ album, onClose, onSuccess }: PaymentModal
|
||||
return groups ? groups.join(' ') : numbers;
|
||||
};
|
||||
|
||||
const formatExpiry = (value: string) => {
|
||||
const formatPhoneNumber = (value: string) => {
|
||||
const numbers = value.replace(/\D/g, '');
|
||||
if (numbers.length >= 2) {
|
||||
return numbers.slice(0, 2) + '/' + numbers.slice(2, 4);
|
||||
}
|
||||
return numbers;
|
||||
if (numbers.length <= 3) return numbers;
|
||||
if (numbers.length <= 6) return `(${numbers.slice(0, 3)}) ${numbers.slice(3)}`;
|
||||
return `(${numbers.slice(0, 3)}) ${numbers.slice(3, 6)}-${numbers.slice(6, 10)}`;
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
@@ -44,32 +44,60 @@ export default function PaymentModal({ album, onClose, onSuccess }: PaymentModal
|
||||
}
|
||||
|
||||
if (!cardName.trim()) {
|
||||
setError('Card name is required');
|
||||
setError('Name is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (expiry.length !== 5) {
|
||||
setError('Invalid expiry date');
|
||||
if (phoneNumber.replace(/\D/g, '').length < 10) {
|
||||
setError('Invalid phone number');
|
||||
return;
|
||||
}
|
||||
|
||||
if (cvv.length !== 3 && cvv.length !== 4) {
|
||||
setError('Invalid CVV');
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email)) {
|
||||
setError('Invalid email address');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!txReceipt.trim()) {
|
||||
setError('Transaction receipt is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!album) return;
|
||||
|
||||
setProcessing(true);
|
||||
|
||||
// Simulate payment processing
|
||||
setTimeout(() => {
|
||||
// Generate a mock transaction ID
|
||||
const transactionId = 'TXN-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9).toUpperCase();
|
||||
try {
|
||||
// Use the provided transaction receipt as the ID
|
||||
const transactionId = txReceipt.trim() || 'TXN-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9).toUpperCase();
|
||||
|
||||
// Create purchase via API
|
||||
const response = await fetch('/api/purchases', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
albumId: album.id,
|
||||
transactionId,
|
||||
customerName: cardName.trim(),
|
||||
email: email.trim(),
|
||||
phoneNumber: phoneNumber,
|
||||
txReceipt: txReceipt.trim(),
|
||||
purchaseDate: new Date().getTime(),
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json();
|
||||
throw new Error(data.error || 'Failed to process purchase');
|
||||
}
|
||||
|
||||
setProcessing(false);
|
||||
if (album) {
|
||||
onSuccess(album.id, transactionId);
|
||||
}
|
||||
}, 2000);
|
||||
onSuccess(album.id, transactionId);
|
||||
} catch (err: any) {
|
||||
setProcessing(false);
|
||||
setError(err.message || 'Failed to process payment');
|
||||
}
|
||||
};
|
||||
|
||||
if (!album) return null;
|
||||
@@ -136,46 +164,64 @@ export default function PaymentModal({ album, onClose, onSuccess }: PaymentModal
|
||||
{/* Card Name */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Name on Card
|
||||
Full Name
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={cardName}
|
||||
onChange={(e) => setCardName(e.target.value.toUpperCase())}
|
||||
placeholder="JOHN DOE"
|
||||
onChange={(e) => setCardName(e.target.value)}
|
||||
placeholder="John Doe"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Expiry and CVV */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Expiry Date
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={expiry}
|
||||
onChange={(e) => setExpiry(formatExpiry(e.target.value))}
|
||||
placeholder="MM/YY"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
CVV
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={cvv}
|
||||
onChange={(e) => setCvv(e.target.value.replace(/\D/g, '').slice(0, 4))}
|
||||
placeholder="123"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
{/* Phone Number */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Phone Number
|
||||
</label>
|
||||
<input
|
||||
type="tel"
|
||||
value={phoneNumber}
|
||||
onChange={(e) => {
|
||||
const formatted = formatPhoneNumber(e.target.value);
|
||||
setPhoneNumber(formatted);
|
||||
}}
|
||||
placeholder="(123) 456-7890"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Email */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Email Address
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="john@example.com"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Transaction Receipt */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Transaction Receipt / ID
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={txReceipt}
|
||||
onChange={(e) => setTxReceipt(e.target.value)}
|
||||
placeholder="TXN-123456789"
|
||||
className="w-full px-4 py-3 bg-white/5 border border-white/10 rounded-lg focus:border-accent-cyan focus:outline-none focus:ring-2 focus:ring-accent-cyan/50 text-white placeholder-gray-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Error Message */}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { FaCheckCircle, FaTimes, FaDownload } from 'react-icons/fa';
|
||||
import { FaClock, FaTimes, FaDownload } from 'react-icons/fa';
|
||||
import { Album, Purchase } from '@/lib/types';
|
||||
|
||||
interface PurchaseSuccessModalProps {
|
||||
@@ -20,9 +20,10 @@ export default function PurchaseSuccessModal({ show, album, purchase, onClose }:
|
||||
PURCHASE RECEIPT
|
||||
================
|
||||
|
||||
Status: PENDING APPROVAL
|
||||
Album: ${album.title}
|
||||
Artist: Parsa
|
||||
Price: $${album.price}
|
||||
Amount: $${album.price}
|
||||
Transaction ID: ${purchase.transactionId}
|
||||
Date: ${new Date(purchase.purchaseDate).toLocaleString()}
|
||||
|
||||
@@ -30,7 +31,8 @@ Tracks Included:
|
||||
${album.songs.map((song, idx) => `${idx + 1}. ${song.title} (${song.duration})`).join('\n')}
|
||||
|
||||
Thank you for your purchase!
|
||||
You now have full access to this album.
|
||||
Your order is pending admin approval.
|
||||
You will receive access to this album after confirmation.
|
||||
`;
|
||||
|
||||
const blob = new Blob([receipt], { type: 'text/plain' });
|
||||
@@ -64,14 +66,14 @@ You now have full access to this album.
|
||||
{/* Header */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-3 bg-green-500/20 rounded-full">
|
||||
<FaCheckCircle className="text-3xl text-green-400" />
|
||||
<div className="p-3 bg-accent-orange/20 rounded-full">
|
||||
<FaClock className="text-3xl text-accent-orange" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold text-white">
|
||||
Purchase Successful!
|
||||
Purchase Pending Approval
|
||||
</h2>
|
||||
<p className="text-sm text-gray-400">Thank you for your purchase</p>
|
||||
<p className="text-sm text-gray-400">Please wait for admin confirmation</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
@@ -99,7 +101,7 @@ You now have full access to this album.
|
||||
<span className="text-white font-semibold">{album.songs.length} songs</span>
|
||||
</div>
|
||||
<div className="border-t border-white/10 pt-3 flex justify-between">
|
||||
<span className="text-gray-400">Total Paid</span>
|
||||
<span className="text-gray-400">Amount</span>
|
||||
<span className="text-accent-orange font-bold text-xl">${album.price}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -129,13 +131,13 @@ You now have full access to this album.
|
||||
onClick={onClose}
|
||||
className="w-full py-3 bg-gradient-to-r from-accent-cyan to-accent-cyan/80 hover:from-accent-cyan/90 hover:to-accent-cyan/70 rounded-lg font-semibold text-white transition-all glow-cyan"
|
||||
>
|
||||
Start Listening
|
||||
OK, Got It
|
||||
</motion.button>
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<p className="text-xs text-gray-500 text-center mt-6">
|
||||
You now have unlimited access to all tracks in this album
|
||||
Your purchase will be reviewed by an admin. You will receive access after approval.
|
||||
</p>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
|
||||
Reference in New Issue
Block a user