Files
aperonight/app/views/promoter/events/show.html.erb
kbe e838e91162 ## Backend Implementation
Enhanced TicketType model with helper methods and better validations

So the full context is:

## Backend Implementation
- Enhanced TicketType model with helper methods and better validations
- New Promoter::TicketTypesController with full authorization
- Sales status tracking (draft, available, upcoming, expired, sold_out)
- New Promoter::TicketTypesController with full authorization
- Safe calculation methods preventing nil value errors
- Sales status tracking (draft, available, upcoming, expired, sold_out)

## Frontend Features
- Modern responsive UI with Tailwind CSS styling
- Interactive forms with Stimulus controller for dynamic calculations
- Revenue calculators showing potential, current, and remaining revenue
- Status indicators with appropriate colors and icons
- Buyer analytics and purchase history display

## JavaScript Enhancements
- New TicketTypeFormController for dynamic pricing calculations
- Real-time total updates as users type price/quantity
- Proper French currency formatting
- Form validation for minimum quantities based on existing sales

## Bug Fixes
 Fixed nil value errors in price_euros method when price_cents is nil
 Added defensive programming for all calculation methods
 Graceful handling of incomplete ticket types during creation
 Proper default values for new ticket type instances

## Files Added/Modified
- app/controllers/promoter/ticket_types_controller.rb (new)
- app/javascript/controllers/ticket_type_form_controller.js (new)
- app/views/promoter/ticket_types/*.html.erb (4 new view files)
- app/models/ticket_type.rb (enhanced with helper methods)
- config/routes.rb (added nested ticket_types routes)
- db/migrate/*_add_requires_id_to_ticket_types.rb (new migration)

## Integration
- Seamless integration with existing event management system
- Updated promoter event show page with ticket management link
- Proper scoping ensuring promoters only manage their own tickets
- Compatible with existing ticket purchasing and checkout flow
2025-09-01 00:03:35 +02:00

231 lines
10 KiB
Plaintext

<% content_for(:title, @event.name) %>
<div class="container py-8">
<!-- Header with actions -->
<div class="mb-8">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-4">
<%= link_to promoter_events_path, class: "text-gray-400 hover:text-gray-600 transition-colors" do %>
<i data-lucide="arrow-left" class="w-5 h-5"></i>
<% end %>
<div>
<h1 class="text-3xl font-bold text-gray-900 mb-2"><%= @event.name %></h1>
<div class="flex items-center space-x-4 text-sm text-gray-500">
<span class="flex items-center">
<i data-lucide="calendar" class="w-4 h-4 mr-1"></i>
<%= @event.start_time&.strftime("%d/%m/%Y à %H:%M") || "Date non définie" %>
</span>
<span class="flex items-center">
<i data-lucide="map-pin" class="w-4 h-4 mr-1"></i>
<%= @event.venue_name %>
</span>
</div>
</div>
</div>
<div class="flex items-center space-x-3">
<%= link_to edit_promoter_event_path(@event), class: "inline-flex items-center px-4 py-2 bg-white border border-gray-300 text-gray-700 font-medium rounded-lg hover:bg-gray-50 transition-colors duration-200" do %>
<i data-lucide="edit" class="w-4 h-4 mr-2"></i>
Modifier
<% end %>
<% if @event.draft? %>
<%= button_to publish_promoter_event_path(@event), method: :patch, class: "inline-flex items-center px-4 py-2 bg-green-600 text-white font-medium rounded-lg hover:bg-green-700 transition-colors duration-200" do %>
<i data-lucide="upload" class="w-4 h-4 mr-2"></i>
Publier
<% end %>
<% elsif @event.published? %>
<%= button_to unpublish_promoter_event_path(@event), method: :patch, class: "inline-flex items-center px-4 py-2 bg-yellow-600 text-white font-medium rounded-lg hover:bg-yellow-700 transition-colors duration-200" do %>
<i data-lucide="download" class="w-4 h-4 mr-2"></i>
Dépublier
<% end %>
<% end %>
<% if @event.published? %>
<%= button_to cancel_promoter_event_path(@event), method: :patch, class: "inline-flex items-center px-4 py-2 bg-red-600 text-white font-medium rounded-lg hover:bg-red-700 transition-colors duration-200", data: { confirm: "Êtes-vous sûr de vouloir annuler cet événement ?" } do %>
<i data-lucide="x-circle" class="w-4 h-4 mr-2"></i>
Annuler
<% end %>
<% end %>
</div>
</div>
</div>
<!-- Status banner -->
<div class="mb-8">
<% case @event.state %>
<% when "draft" %>
<div class="bg-gray-50 border border-gray-200 rounded-lg p-4">
<div class="flex items-center">
<i data-lucide="edit-3" class="w-5 h-5 text-gray-400 mr-3"></i>
<div>
<h3 class="text-sm font-medium text-gray-900">Événement en brouillon</h3>
<p class="text-sm text-gray-500">Cet événement n'est pas visible publiquement. Publiez-le pour le rendre accessible aux utilisateurs.</p>
</div>
</div>
</div>
<% when "published" %>
<div class="bg-green-50 border border-green-200 rounded-lg p-4">
<div class="flex items-center">
<i data-lucide="eye" class="w-5 h-5 text-green-400 mr-3"></i>
<div>
<h3 class="text-sm font-medium text-green-900">Événement publié</h3>
<p class="text-sm text-green-700">Cet événement est visible publiquement et les utilisateurs peuvent acheter des billets.</p>
</div>
<div class="ml-auto">
<%= link_to event_path(@event.slug, @event), target: "_blank", class: "text-green-600 hover:text-green-800 font-medium text-sm" do %>
Voir publiquement <i data-lucide="external-link" class="w-4 h-4 inline ml-1"></i>
<% end %>
</div>
</div>
</div>
<% when "canceled" %>
<div class="bg-red-50 border border-red-200 rounded-lg p-4">
<div class="flex items-center">
<i data-lucide="x-circle" class="w-5 h-5 text-red-400 mr-3"></i>
<div>
<h3 class="text-sm font-medium text-red-900">Événement annulé</h3>
<p class="text-sm text-red-700">Cet événement a été annulé et n'est plus accessible aux utilisateurs.</p>
</div>
</div>
</div>
<% when "sold_out" %>
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
<div class="flex items-center">
<i data-lucide="users" class="w-5 h-5 text-blue-400 mr-3"></i>
<div>
<h3 class="text-sm font-medium text-blue-900">Événement complet</h3>
<p class="text-sm text-blue-700">Tous les billets pour cet événement ont été vendus.</p>
</div>
</div>
</div>
<% end %>
<% if @event.featured? %>
<div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4 mt-4">
<div class="flex items-center">
<i data-lucide="star" class="w-5 h-5 text-yellow-400 mr-3"></i>
<div>
<h3 class="text-sm font-medium text-yellow-900">Événement à la une</h3>
<p class="text-sm text-yellow-700">Cet événement est mis en avant sur la page d'accueil.</p>
</div>
</div>
</div>
<% end %>
</div>
<!-- Event details -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Main content -->
<div class="lg:col-span-2 space-y-8">
<!-- Event image -->
<% if @event.image.present? %>
<div class="aspect-video bg-gray-100 rounded-lg overflow-hidden">
<img src="<%= @event.image %>" alt="<%= @event.name %>" class="w-full h-full object-cover">
</div>
<% end %>
<!-- Description -->
<div class="bg-white rounded-lg border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Description</h3>
<div class="prose prose-gray max-w-none">
<%= simple_format(@event.description) %>
</div>
</div>
<!-- Location details -->
<div class="bg-white rounded-lg border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Lieu</h3>
<div class="space-y-3">
<div class="flex items-start space-x-3">
<i data-lucide="building" class="w-5 h-5 text-gray-400 mt-0.5"></i>
<div>
<p class="font-medium text-gray-900"><%= @event.venue_name %></p>
<p class="text-gray-500"><%= @event.venue_address %></p>
</div>
</div>
<div class="flex items-center space-x-3 text-sm text-gray-500">
<i data-lucide="map-pin" class="w-4 h-4"></i>
<span><%= @event.latitude %>, <%= @event.longitude %></span>
</div>
</div>
</div>
</div>
<!-- Sidebar -->
<div class="space-y-6">
<!-- Event stats -->
<div class="bg-white rounded-lg border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Statistiques</h3>
<div class="space-y-4">
<div class="flex items-center justify-between">
<span class="text-gray-500">Types de billets</span>
<span class="font-medium"><%= @event.ticket_types.count %></span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-500">Billets vendus</span>
<span class="font-medium"><%= @event.tickets.count %></span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-500">Revenus</span>
<span class="font-medium">
<%= number_to_currency(@event.tickets.sum(:price_cents) / 100.0, unit: "€") %>
</span>
</div>
</div>
</div>
<!-- Event info -->
<div class="bg-white rounded-lg border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Informations</h3>
<div class="space-y-4">
<div>
<span class="text-sm text-gray-500">Slug</span>
<p class="font-mono text-sm"><%= @event.slug %></p>
</div>
<div>
<span class="text-sm text-gray-500">Créé le</span>
<p class="text-sm"><%= @event.created_at.strftime("%d/%m/%Y à %H:%M") %></p>
</div>
<div>
<span class="text-sm text-gray-500">Modifié le</span>
<p class="text-sm"><%= @event.updated_at.strftime("%d/%m/%Y à %H:%M") %></p>
</div>
<% if @event.start_time %>
<div>
<span class="text-sm text-gray-500">Début</span>
<p class="text-sm"><%= @event.start_time.strftime("%d/%m/%Y à %H:%M") %></p>
</div>
<% end %>
<% if @event.end_time %>
<div>
<span class="text-sm text-gray-500">Fin</span>
<p class="text-sm"><%= @event.end_time.strftime("%d/%m/%Y à %H:%M") %></p>
</div>
<% end %>
</div>
</div>
<!-- Quick actions -->
<div class="bg-white rounded-lg border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Actions rapides</h3>
<div class="space-y-3">
<%= link_to promoter_event_ticket_types_path(@event), class: "w-full inline-flex items-center px-4 py-2 bg-purple-600 text-white font-medium rounded-lg hover:bg-purple-700 transition-colors duration-200" do %>
<i data-lucide="ticket" class="w-4 h-4 mr-2"></i>
Gérer les types de billets
<% end %>
<%= button_to mark_sold_out_promoter_event_path(@event), method: :patch, class: "w-full inline-flex items-center px-4 py-2 bg-gray-50 text-gray-700 font-medium rounded-lg hover:bg-gray-100 transition-colors duration-200", disabled: !@event.published? do %>
<i data-lucide="users" class="w-4 h-4 mr-2"></i>
Marquer comme complet
<% end %>
<hr class="border-gray-200">
<%= button_to promoter_event_path(@event), method: :delete,
data: { confirm: "Êtes-vous sûr de vouloir supprimer cet événement ? Cette action est irréversible." },
class: "w-full inline-flex items-center px-4 py-2 text-red-600 font-medium rounded-lg hover:bg-red-50 transition-colors duration-200" do %>
<i data-lucide="trash-2" class="w-4 h-4 mr-2"></i>
Supprimer l'événement
<% end %>
</div>
</div>
</div>
</div>
</div>