import { API_BASE_URL } from '../../lib/config'; import React, { useState, useEffect } from 'react'; import { motion } from 'framer-motion'; import { Plus, Trash2, Building2, Edit, Save, CheckCircle2 } from 'lucide-react'; import { useDialog } from '../../context/DialogContext'; export const VenueManagement: React.FC = () => { const { showAlert, showConfirm } = useDialog(); const [venues, setVenues] = useState([]); const [newVenueName, setNewVenueName] = useState(''); const [newVenueCapacity, setNewVenueCapacity] = useState(''); const [editingVenueId, setEditingVenueId] = useState(null); const [editVenueName, setEditVenueName] = useState(''); const [editVenueCapacity, setEditVenueCapacity] = useState(''); useEffect(() => { fetchVenues(); }, []); const fetchVenues = async () => { try { const response = await fetch(API_BASE_URL + '/api/venues'); if (response.ok) { const data = await response.json(); setVenues(data); } } catch (error) { console.error('Failed to fetch venues:', error); } }; const handleCreateVenue = async (e: React.FormEvent) => { e.preventDefault(); if (!newVenueName.trim()) { showAlert('Required', 'Please enter a venue name', 'error'); return; } try { const capacityVal = newVenueCapacity.trim() ? Number(newVenueCapacity) : null; const response = await fetch(API_BASE_URL + '/api/venues', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: newVenueName.trim(), capacity: capacityVal }) }); if (response.ok) { fetchVenues(); setNewVenueName(''); setNewVenueCapacity(''); showAlert('Success', 'Venue added successfully.', 'success'); } } catch (error) { console.error('Failed to add venue:', error); showAlert('Error', 'Failed to add venue.', 'error'); } }; const handleStartEditVenue = (venue: any) => { setEditingVenueId(venue.id); setEditVenueName(venue.name); setEditVenueCapacity(venue.capacity !== null && venue.capacity !== undefined ? String(venue.capacity) : ''); }; const handleSaveVenueEdit = async (venueId: string) => { if (!editVenueName.trim()) { showAlert('Required', 'Venue name cannot be empty', 'error'); return; } try { const capacityVal = editVenueCapacity.trim() ? Number(editVenueCapacity) : null; const response = await fetch(API_BASE_URL + '/api/venues', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: venueId, name: editVenueName.trim(), capacity: capacityVal }) }); if (response.ok) { fetchVenues(); setEditingVenueId(null); showAlert('Success', 'Venue updated successfully.', 'success'); } } catch (error) { console.error('Failed to update venue:', error); showAlert('Error', 'Failed to update venue.', 'error'); } }; const handleDeleteVenue = async (venueId: string) => { showConfirm( 'Delete Venue', 'Are you sure you want to delete this venue? This cannot be undone.', async () => { try { const response = await fetch(`${API_BASE_URL}/api/venues/${venueId}`, { method: 'DELETE' }); if (response.ok) { fetchVenues(); showAlert('Success', 'Venue deleted successfully.', 'success'); } } catch (error) { console.error('Failed to delete venue:', error); showAlert('Error', 'Failed to delete venue.', 'error'); } } ); }; return (
{/* Header */}

Venue Management

Configure college venues, halls, and seating capacities

{/* Manage Venues Section */}

Registered Venues

Configure college venues, halls, and seating capacities.

setNewVenueName(e.target.value)} className="bg-slate-50 border border-slate-200 rounded-xl py-2 px-4 text-xs font-bold focus:bg-white focus:border-brand-indigo outline-none transition-all text-slate-800" required /> setNewVenueCapacity(e.target.value)} className="bg-slate-50 border border-slate-200 rounded-xl py-2 px-4 text-xs font-bold focus:bg-white focus:border-brand-indigo outline-none transition-all text-slate-800 w-32" />
{venues.map(venue => (
{editingVenueId === venue.id ? (
setEditVenueName(e.target.value)} className="w-full bg-white border border-slate-200 rounded-xl py-1.5 px-3 text-xs font-bold focus:border-brand-indigo outline-none transition-all" required />
setEditVenueCapacity(e.target.value)} className="w-full bg-white border border-slate-200 rounded-xl py-1.5 px-3 text-xs font-bold focus:border-brand-indigo outline-none transition-all" placeholder="Unlimited / Custom" />
) : ( <>

{venue.name}

{venue.capacity ? `Capacity: ${venue.capacity} seats` : 'No Limit / Custom'}
)}
))} {venues.length === 0 && (
No venues registered. Use the form above to add a new venue.
)}
); };