"use client" import { useState, useEffect } from 'react' import { useParams } from 'next/navigation' import { ArtistForm } from '@/components/admin/artist-form' import { useToast } from '@/hooks/use-toast' import type { Artist } from '@/types/database' export default function EditArtistPage() { const params = useParams() const { toast } = useToast() const [artist, setArtist] = useState(null) const [loading, setLoading] = useState(true) const fetchArtist = async () => { try { const response = await fetch(`/api/artists/${params.id}`) if (!response.ok) throw new Error('Failed to fetch artist') const data = await response.json() setArtist(data.artist) } catch (error) { console.error('Error fetching artist:', error) toast({ title: 'Error', description: 'Failed to load artist', variant: 'destructive', }) } finally { setLoading(false) } } useEffect(() => { if (params.id) { fetchArtist() } }, [params.id]) if (loading) { return (
Loading artist...
) } if (!artist) { return (
Artist not found
) } return (

Edit Artist

Update {artist.name}'s information and portfolio

{ toast({ title: 'Success', description: 'Artist updated successfully', }) fetchArtist() // Refresh the data }} />
) }