Skip to content

Commit

Permalink
Adding donation to the ticket request form
Browse files Browse the repository at this point in the history
  • Loading branch information
kigster committed May 20, 2024
1 parent 56b08a4 commit d7fad94
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Metrics/ClassLength:
Metrics/ModuleLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Layout/HashAlignment:
Enabled: true
EnforcedColonStyle: table
Expand Down
13 changes: 4 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-05-20 17:20:36 UTC using RuboCop version 1.63.5.
# on 2024-05-20 21:02:26 UTC using RuboCop version 1.63.5.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -16,11 +16,6 @@ Lint/UnmodifiedReduceAccumulator:
Exclude:
- 'app/helpers/shifts_helper.rb'

# Offense count: 36
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 65

# Offense count: 6
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
# AllowedMethods: refine
Expand All @@ -35,7 +30,7 @@ Metrics/CyclomaticComplexity:
# Offense count: 50
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 58
Max: 60

# Offense count: 10
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down Expand Up @@ -217,9 +212,9 @@ Style/GuardClause:
- 'app/controllers/ticket_requests_controller.rb'
- 'app/models/event.rb'

# Offense count: 25
# Offense count: 27
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 154
Max: 252
6 changes: 5 additions & 1 deletion app/assets/stylesheets/site/global.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ legend {
}

label.strong {
font-weight: 800;
font-weight: 500;
}

strong {
font-weight: 600;
}

.event-row {
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/ticket_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create
end

tr_params = permitted_params[:ticket_request].to_h || {}

tr_params[:donation] = 0 unless tr_params[:donation].present? && tr_params[:donation] =~ /^[\d.]+$/
if tr_params.empty?
flash.now[:error] = 'Please fill out the form below to request tickets.'
return render_flash(flash)
Expand Down Expand Up @@ -158,6 +158,8 @@ def update
.flatten.map(&:presence)
.compact

ticket_request_params[:donation] = 0 unless ticket_request_params[:donation].present? && ticket_request_params[:donation] =~ /^[\d.]+$/

ticket_request_params.delete(:guest_list)
ticket_request_params[:guests] = guests

Expand Down
1 change: 1 addition & 0 deletions app/views/ticket_requests/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
%br
= f.label :donation, 'Your Donation'
= f.number_field :donation, class: 'input-mini', min: 0, required: false
= tooltip_box "Your donation is optional, but would be greatly appreciated!"

.control-group

Expand Down
14 changes: 10 additions & 4 deletions app/views/ticket_requests/_ticket_request_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
%span.p-2.rounded{ class: text_class_for_status(ticket_request) }
= ticket_request.status_name

- if ticket_request.can_purchase?
%tr
%td.text-end.small.p-2.px-4.text-nowrap= "Total Tickets Price:"
%td
%strong
%span{ class: ('label label-info' if ticket_request.special_price) }
= number_to_currency(ticket_request.price, precision: 0)

- if ticket_request.donation&.positive?
%tr
%td.text-end.small.p-2.px-4.text-nowrap= "Total Tickets Price:"
%td.text-end.small.p-2.px-4.text-nowrap= "Extra Donation:"
%td
%strong
%span{ class: ('label label-info' if ticket_request.special_price) }
= number_to_currency(ticket_request.price, precision: 0)
= number_to_currency(ticket_request.donation, precision: 0)

%tr
%td.text-end.small.p-2.px-4.text-nowrap= "Payment:"
Expand Down
4 changes: 2 additions & 2 deletions app/views/ticket_requests/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
= succeed '!' do
= 'ticket'.pluralize(@ticket_request.total_tickets)

- if @ticket_request.user == current_user || @event.admin?(current_user)
%hr

= render partial: 'ticket_request_show', locals: { event: @event, ticket_request: @ticket_request, payment: @payment }
= render partial: 'ticket_request_show', locals: { event: @event, ticket_request: @ticket_request, payment: @payment, current_user: }

.card-footer.bg-body-secondary.border-dark-subtle
.row
Expand Down

0 comments on commit d7fad94

Please sign in to comment.