Add warnings when a user needs to register or complete a purchase

This commit is contained in:
Michael Ball 2020-07-11 01:50:17 -07:00
parent 5bef4b7004
commit 1964522f49
4 changed files with 41 additions and 1 deletions

View file

@ -27,6 +27,10 @@ class ConferencesController < ApplicationController
redirect_to admin_conference_splashpage_path(@conference.short_title) && return
end
# User messages at the top of the page.
@unpaid_tickets = current_user_has_unpaid_tickets?
@user_needs_to_register = current_user_needs_to_register?
@image_url = "#{request.protocol}#{request.host}#{@conference.picture}"
if splashpage.include_cfp
@ -79,4 +83,17 @@ class ConferencesController < ApplicationController
format.html { head :ok }
end if request.options?
end
def current_user_tickets
@current_user_tickets ||= current_user.ticket_purchases.by_conference(@conference)
end
def current_user_needs_to_register?
current_user && !@conference.user_registered?(current_user) &&
current_user_tickets.where(ticket: @conference.registration_tickets).paid.any?
end
def current_user_has_unpaid_tickets?
current_user && current_user_tickets.unpaid.any?
end
end

View file

@ -116,7 +116,7 @@ class Conference < ApplicationRecord
# True when there is at least one ticket marked as "registration"
# A user must get a registration ticket before registering.
def registration_ticket_required?
tickets.for_registration.any?
registration_tickets.any?
end
##

View file

@ -16,6 +16,28 @@
= content_for :title do
= @conference.title
= content_for :additional_messages do
- if @unpaid_tickets
.row
.col-md-12
.alert.alert-dismissable.alert-info.text-center#unpaid-tickets{role: 'alert'}
%button.button.close{"data-dismiss" => "alert", "aria-label"=>"close"}
&times;
%p
You have unpaid tickets. Please complete your purchase.
= link_to('Purchase Tickets', new_conference_payment_path(@conference), class: 'btn btn-success btn-lg')
- if @user_needs_to_register
.row
.col-md-12
.alert.alert-dismissable.alert-warning.text-center#flash{role: 'alert'}
%button.button.close{"data-dismiss" => "alert", 'aria-label': 'close'}
&times;
%p
You still need to complete your registration for #{@conference.title}.
= link_to('Complete Registration', new_conference_conference_registration_path(@conference), class: 'btn btn-success btn-lg')
#splash
- if @conference.code_of_conduct.present?

View file

@ -30,6 +30,7 @@
#messages
.container
= render 'layouts/messages'
= yield :additional_messages
#content
= yield