'use client' import { useState, useEffect } from 'react' import { LabelStats } from '@/components/LabelStats' import { ArtistRoster } from '@/components/ArtistRoster' import { InvitationCard } from '@/components/InvitationCard' import { InviteArtistModal } from '@/components/InviteArtistModal' export default function LabelDashboardPage() { const [label, setLabel] = useState(null) const [stats, setStats] = useState(null) const [invitations, setInvitations] = useState([]) const [loading, setLoading] = useState(true) const [isInviteModalOpen, setIsInviteModalOpen] = useState(false) useEffect(() => { fetchDashboardData() }, []) const fetchDashboardData = async () => { try { // Check authentication const userRes = await fetch('/api/users/me') if (!userRes.ok) { window.location.href = '/login' return } const userData = await userRes.json() // Fetch user's label const labelRes = await fetch(`/api/users/${userData.user.id}/label`) if (!labelRes.ok) { window.location.href = '/label/create' return } const labelData = await labelRes.json() setLabel(labelData.label) // Fetch stats const statsRes = await fetch(`/api/labels/${labelData.label.id}/stats`) if (statsRes.ok) { const statsData = await statsRes.json() setStats(statsData.stats) } // Fetch invitations const invitationsRes = await fetch(`/api/labels/${labelData.label.id}/invitations`) if (invitationsRes.ok) { const invitationsData = await invitationsRes.json() setInvitations(invitationsData.invitations || []) } } catch (error) { console.error('Failed to fetch dashboard data:', error) } finally { setLoading(false) } } const handleRemoveArtist = async (artistId: string) => { if (!confirm('Are you sure you want to remove this artist from your label?')) { return } try { const res = await fetch(`/api/labels/${label.id}/artists/${artistId}`, { method: 'DELETE' }) if (res.ok) { fetchDashboardData() } else { alert('Failed to remove artist') } } catch (error) { console.error('Failed to remove artist:', error) alert('Network error') } } const handleCancelInvitation = async (invitationId: string) => { try { const res = await fetch(`/api/invitations/${invitationId}`, { method: 'DELETE' }) if (res.ok) { setInvitations(invitations.filter(inv => inv.id !== invitationId)) } else { alert('Failed to cancel invitation') } } catch (error) { console.error('Failed to cancel invitation:', error) alert('Network error') } } if (loading) { return (

Loading dashboard...

) } if (!label) { return (

You don't have a label yet

Create Label
) } return (
{/* Header */}

{label.name}

Label Dashboard

Settings
{/* Stats */} {stats && (
)} {/* Artist Roster */}

Your Artists

{ window.location.href = `/artist/${artistId}` }} />
{/* Pending Invitations */} {invitations.length > 0 && (

Pending Invitations ({invitations.filter(inv => inv.status === 'PENDING').length})

{invitations .filter(inv => inv.status === 'PENDING') .map((invitation) => ( ))}
)}
{/* Invite Modal */} setIsInviteModalOpen(false)} onInviteSent={() => { setIsInviteModalOpen(false) fetchDashboardData() }} />
) }