feat: Modularize event management system - 98.7% reduction in main file size
BREAKING CHANGES: - Refactored monolithic manage.astro (7,623 lines) into modular architecture - Original file backed up as manage-old.astro NEW ARCHITECTURE: ✅ 5 Utility Libraries: - event-management.ts: Event data operations & formatting - ticket-management.ts: Ticket CRUD operations & sales data - seating-management.ts: Seating map management & layout generation - sales-analytics.ts: Sales metrics, reporting & data export - marketing-kit.ts: Marketing asset generation & social media ✅ 5 Shared Components: - TicketTypeModal.tsx: Reusable ticket type creation/editing - SeatingMapModal.tsx: Advanced seating map editor with drag-and-drop - EmbedCodeModal.tsx: Widget embedding with customization - OrdersTable.tsx: Comprehensive orders table with sorting/pagination - AttendeesTable.tsx: Attendee management with export capabilities ✅ 11 Tab Components: - TicketsTab.tsx: Ticket management with card/list views - VenueTab.tsx: Seating map management & venue configuration - OrdersTab.tsx: Sales data & order management - AttendeesTab.tsx: Attendee check-in & management - PresaleTab.tsx: Presale code generation & tracking - DiscountTab.tsx: Discount code management - AddonsTab.tsx: Add-on product management - PrintedTab.tsx: Printed ticket barcode management - SettingsTab.tsx: Event configuration & custom fields - MarketingTab.tsx: Marketing kit with social media templates - PromotionsTab.tsx: Campaign & promotion management ✅ 4 Infrastructure Components: - TabNavigation.tsx: Responsive tab navigation system - EventManagement.tsx: Main orchestration component - EventHeader.astro: Event information header - QuickStats.astro: Statistics dashboard BENEFITS: - 98.7% reduction in main file size (7,623 → ~100 lines) - Dramatic improvement in maintainability and team collaboration - Component-level testing now possible - Reusable components across multiple features - Lazy loading support for better performance - Full TypeScript support with proper interfaces - Separation of concerns: business logic separated from UI 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
90
src/pages/api/events/[id]/marketing-kit/download.ts
Normal file
90
src/pages/api/events/[id]/marketing-kit/download.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { supabase } from '../../../../../lib/supabase';
|
||||
|
||||
export const GET: APIRoute = async ({ params, request }) => {
|
||||
try {
|
||||
const eventId = params.id;
|
||||
if (!eventId) {
|
||||
return new Response('Event ID is required', { status: 400 });
|
||||
}
|
||||
|
||||
// Get user session
|
||||
const authHeader = request.headers.get('Authorization');
|
||||
const token = authHeader?.replace('Bearer ', '');
|
||||
|
||||
if (!token) {
|
||||
return new Response('Authentication required', { status: 401 });
|
||||
}
|
||||
|
||||
const { data: { user }, error: authError } = await supabase.auth.getUser(token);
|
||||
if (authError || !user) {
|
||||
return new Response('Invalid authentication', { status: 401 });
|
||||
}
|
||||
|
||||
// Get user's organization
|
||||
const { data: userData, error: userError } = await supabase
|
||||
.from('users')
|
||||
.select('organization_id')
|
||||
.eq('id', user.id)
|
||||
.single();
|
||||
|
||||
if (userError || !userData?.organization_id) {
|
||||
return new Response('User organization not found', { status: 403 });
|
||||
}
|
||||
|
||||
// Get event details
|
||||
const { data: event, error: eventError } = await supabase
|
||||
.from('events')
|
||||
.select('*')
|
||||
.eq('id', eventId)
|
||||
.eq('organization_id', userData.organization_id)
|
||||
.single();
|
||||
|
||||
if (eventError || !event) {
|
||||
return new Response('Event not found or access denied', { status: 404 });
|
||||
}
|
||||
|
||||
// Get marketing kit assets
|
||||
const { data: assets, error: assetsError } = await supabase
|
||||
.from('marketing_kit_assets')
|
||||
.select('*')
|
||||
.eq('event_id', eventId)
|
||||
.eq('is_active', true)
|
||||
.order('generated_at', { ascending: false });
|
||||
|
||||
if (assetsError || !assets || assets.length === 0) {
|
||||
return new Response('No marketing kit assets found', { status: 404 });
|
||||
}
|
||||
|
||||
// Create a simple ZIP-like response for now
|
||||
// In production, you'd generate an actual ZIP file
|
||||
const zipContent = {
|
||||
event: {
|
||||
title: event.title,
|
||||
date: event.start_time,
|
||||
venue: event.venue
|
||||
},
|
||||
assets: assets.map(asset => ({
|
||||
type: asset.asset_type,
|
||||
title: asset.title,
|
||||
url: asset.image_url || asset.download_url,
|
||||
content: asset.content
|
||||
})),
|
||||
generated_at: new Date().toISOString()
|
||||
};
|
||||
|
||||
// Return JSON for now - in production this would be a ZIP file
|
||||
return new Response(JSON.stringify(zipContent, null, 2), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Disposition': `attachment; filename="${event.slug}-marketing-kit.json"`,
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error downloading marketing kit:', error);
|
||||
return new Response('Internal server error', { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user