feat: Implement comprehensive promoter system with dashboard and role-based access
This commit implements a complete promoter system that allows professional users (is_professionnal: true) to manage events with advanced analytics and controls. ## Key Features Added: ### Role-Based Access Control - Update User#can_manage_events? to use is_professionnal field - Add promoter? alias method for semantic clarity - Restrict event management to professional users only ### Enhanced Navigation - Add conditional "Créer un événement" and "Mes événements" links - Display promoter navigation only for professional users - Include responsive mobile navigation with appropriate icons - Maintain clean UI for regular users ### Comprehensive Promoter Dashboard - Revenue metrics with total earnings calculation - Tickets sold counter across all events - Published vs draft events statistics - Monthly revenue trend chart (6 months) - Recent events widget with quick management actions - Recent orders table with customer information ### Advanced Analytics - Real-time revenue calculations from order data - Monthly revenue trends with visual progress bars - Event performance metrics and status tracking - Customer order history and transaction details ### Event Management Workflow - Verified existing event CRUD operations are comprehensive - Maintains easy-to-use interface for event creation/editing - State management system (draft → published → cancelled) - Quick action buttons for common operations ### Documentation - Comprehensive implementation guide in docs/ - Technical details and architecture explanations - Future enhancement recommendations - Testing and deployment considerations ## Technical Implementation: - Optimized database queries to prevent N+1 problems - Proper eager loading for dashboard performance - Responsive design with Tailwind CSS components - Clean separation of promoter vs regular user features - Maintainable code structure following Rails conventions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,52 @@ class PagesController < ApplicationController
|
||||
.can_retry_payment
|
||||
.order(:expires_at)
|
||||
|
||||
# Promoter-specific data if user is a promoter
|
||||
if current_user.promoter?
|
||||
@promoter_events = current_user.events.includes(:orders, :tickets)
|
||||
.order(created_at: :desc)
|
||||
.limit(5)
|
||||
|
||||
# Revenue metrics for promoter
|
||||
@total_revenue = current_user.events
|
||||
.joins(:orders)
|
||||
.where(orders: { status: ['paid', 'completed'] })
|
||||
.sum('orders.total_amount_cents') / 100.0
|
||||
|
||||
@total_tickets_sold = current_user.events
|
||||
.joins(:tickets)
|
||||
.where(tickets: { status: 'active' })
|
||||
.count
|
||||
|
||||
@active_events_count = current_user.events.where(state: 'published').count
|
||||
@draft_events_count = current_user.events.where(state: 'draft').count
|
||||
|
||||
# Recent orders for promoter events
|
||||
@recent_orders = Order.joins(:event)
|
||||
.where(events: { user: current_user })
|
||||
.where(status: ['paid', 'completed'])
|
||||
.includes(:event, :user, tickets: :ticket_type)
|
||||
.order(created_at: :desc)
|
||||
.limit(10)
|
||||
|
||||
# Monthly revenue trend (last 6 months)
|
||||
@monthly_revenue = (0..5).map do |months_ago|
|
||||
start_date = months_ago.months.ago.beginning_of_month
|
||||
end_date = months_ago.months.ago.end_of_month
|
||||
|
||||
revenue = current_user.events
|
||||
.joins(:orders)
|
||||
.where(orders: { status: ['paid', 'completed'] })
|
||||
.where(orders: { created_at: start_date..end_date })
|
||||
.sum('orders.total_amount_cents') / 100.0
|
||||
|
||||
{
|
||||
month: start_date.strftime("%B %Y"),
|
||||
revenue: revenue
|
||||
}
|
||||
end.reverse
|
||||
end
|
||||
|
||||
# Simplified upcoming events preview - only show if user has orders
|
||||
if @user_orders.any?
|
||||
ordered_event_ids = @user_orders.map(&:event).map(&:id)
|
||||
|
||||
Reference in New Issue
Block a user